Skip to content

fix: Add optional tool_calls arg to ChatMessage.assistant#143

Merged
restlessronin merged 1 commit intocyberchitta:mainfrom
biraj21:biraj/chat-message-tool-calls
Mar 15, 2026
Merged

fix: Add optional tool_calls arg to ChatMessage.assistant#143
restlessronin merged 1 commit intocyberchitta:mainfrom
biraj21:biraj/chat-message-tool-calls

Conversation

@biraj21
Copy link
Contributor

@biraj21 biraj21 commented Mar 10, 2026

Add optional tool_calls arg to ChatMessage.assistant

When using function calling in the userguide.livemd, the assistant message from the API response was added directly to context. The problem is API responses use string keys (e.g. "role", "content") while ChatMessage creates maps with atom keys. This meant iterating over context required handling both Map.get(msg, :role) and Map.get(msg, "role").

Also, ChatMessage.assistant only accepted content - there was no way to include tool_calls in an assistant message.
Changes:

  • Added :tool_calls to ChatMessage.map_fields
  • Updated assistant/1 to assistant/2 to accept optional tool_calls
  • Updated userguide to use ChatMessage.assistant instead of inserting raw message

Discovered while building a coding agent that printed context and had to handle both key types.

…nsistency

- add :tool_calls to ChatMessage map_fields
- Update assistant/1 to assistant/2 to accept optional tool_calls
- Update userguide to use ChatMessage.assistant explicitly
@restlessronin restlessronin merged commit 8c2a059 into cyberchitta:main Mar 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants