Repository navigation
docs: document streaming tool calls and the Jinja requirement - #28261
apollo-2006 wants to merge 1 commit into
Conversation
|
Hi @apollo-2006, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
618c937 to
00fcc67
Compare
Adds two sections to docs/function-calling.md. Streaming tool calls arrive as deltas keyed by index rather than as one object. id, type and function.name are sent once, on the first chunk for an index; later chunks carry only index and function.arguments, and those arguments are raw JSON fragments that have to be concatenated, so a client that parses a single fragment gets invalid JSON. Adds a short accumulation loop and notes the finish_reason values. Tool calling also depends on the Jinja template path. It is on by default, so with --no-jinja, or with a template that is not tool-aware, tool calls come back as plain assistant text with no error reported, which is easy to mistake for the model ignoring the tools.
00fcc67 to
edb465a
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The new Jinja section incorrectly claims --no-jinja can silently return tool calls as plain text for OpenAI-compatible requests with tools, but the server rejects such requests with an error, and the streaming finish_reason wording is ambiguous when include_usage is enabled.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR adds documentation to docs/function-calling.md covering (1) how OpenAI-compatible streaming tool calls are delivered as interleaved deltas that must be accumulated by index, and (2) how tool calling depends on the Jinja template path and what symptoms appear when that path/template is not set up for tools.
Changes:
- Document streaming
tool_callsas indexed deltas and provide a short Python accumulation loop. - Add guidance on diagnosing “no tool calls” when Jinja is disabled or the template is not tool-aware.
File summaries
| File | Description |
|---|---|
| docs/function-calling.md | Adds new sections on streaming tool-call deltas and Jinja/template requirements for tool calling. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| # Tool calls and Jinja | ||
|
|
||
| Tool calling goes through the Jinja template path, which is enabled by default; `--no-jinja` turns it off. The explicit `--jinja` in the examples above predates that default and is now redundant. With Jinja disabled, or with a template that is not tool-aware, tool calls come back as plain assistant text instead of in `tool_calls`, and nothing reports an error. |
| ``` | ||
|
|
||
| > [!TIP] | ||
| > The final chunk carries `finish_reason: "tool_calls"`, or `"stop"` when the turn produced none. That is the point at which each accumulated `arguments` string is complete and can be parsed. |
|
Fixed, my oversight. The |
|
@ngxson you implemented the current Jinja engine in #18462, so you are the right person for the one claim I could not fully settle from the source. The section I added says that with |
Overview
Adds two sections to
docs/function-calling.md: how tool calls arrive when"stream": true, and what happens when the Jinja template path is off or the template is not tool-aware.Streaming tool calls do not arrive as one object. They arrive as deltas keyed by
index, so two calls in the same turn interleave.id,typeandfunction.nameare sent once, on the first chunk for an index; later chunks carry onlyindexandfunction.arguments, and those arguments are raw JSON fragments that have to be concatenated, so a client that parses a single fragment gets invalid JSON. The section documents that and includes a short accumulation loop.The Jinja section covers the case where tool calls come back as plain assistant text with nothing reporting an error, which is easy to mistake for the model ignoring the tools. Jinja is on by default, so this shows up either with an explicit
--no-jinjaor with a template that is not tool-aware.Additional information
Claims were checked against the source rather than inferred:
id,typeandfunction.name; later chunks carry onlyindexandfunction.arguments(tools/server/server-chat.cpp:617-621,tools/server/server-task.cpp:203-205)tool_call_index(common/chat.cpp), which is why they need concatenating per indexuse_jinja = trueby default (common/common.h), disabled with--no-jinjafinish_reasonis"tool_calls", or"stop"when the turn produced none (tools/server/server-task.cpp)The Python example was executed against a simulated interleaved stream before being added, to confirm it keeps two concurrent calls separate and that the concatenated fragments parse as JSON.
This is additive: 33 lines appended, nothing existing modified. The Jinja section cross-references the existing "Usage - need tool-aware Jinja template" section rather than restating it.
Requirements