Skip to content

Fix/add id to toolcall - #712

Open
SaiDevaHarshaR wants to merge 5 commits into
ollama:mainfrom
SaiDevaHarshaR:fix/add-id-to-toolcall
Open

SaiDevaHarshaR wants to merge 5 commits into
ollama:mainfrom
SaiDevaHarshaR:fix/add-id-to-toolcall

Conversation

@SaiDevaHarshaR

Copy link
Copy Markdown

What this fixes

Fixes #667 — ToolCall is missing id field required by OpenAI API spec.
When using ollama-python responses with OpenAI-compatible tools,
tool_call_id is missing causing errors.

Change

Added id: Optional[str] = None to Message.ToolCall:

class ToolCall(SubscriptableBaseModel):
    id: Optional[str] = None  # added
    function: Function

Why Optional

Making it optional preserves backward compatibility — existing code
that creates ToolCall without id continues to work.

Testing

# With id
tc = Message.ToolCall(id="call_abc123", function=...)
print(tc.id)  # "call_abc123"

# Without id (backward compatible)
tc = Message.ToolCall(function=...)
print(tc.id)  # None

Closes #667

@ducanhnguyen223 ducanhnguyen223 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cross-checked this against the Client.chat path for a reported tool-correlation bug. This patch adds id to Message.ToolCall, which covers the assistant-call side, but the corresponding tool-result field still appears absent: Message has no tool_call_id, and _copy_messages() validates each incoming mapping through Message.model_validate(...), so a role=tool message carrying tool_call_id is dropped before request serialization. Could you confirm whether the Ollama API accepts/preserves that field? If it does, a transport-level regression for a tool result would cover the other half of the round trip. Related concrete reproduction: langchain-ai/langchain#41085. I did not execute this fork or run its tests.

This branch has not been deployed

No deployments
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.

id in ToolCall missing

2 participants