Skip to content

docs: document streaming tool calls and the Jinja requirement - #28261

Closed
apollo-2006 wants to merge 1 commit into
ggml-org:masterfrom
apollo-2006:docs/streaming-tool-calls
Closed

apollo-2006 wants to merge 1 commit into
ggml-org:masterfrom
apollo-2006:docs/streaming-tool-calls

Conversation

@apollo-2006

@apollo-2006 apollo-2006 commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

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, 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. 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-jinja or with a template that is not tool-aware.

Additional information

Claims were checked against the source rather than inferred:

  • the first chunk for an index carries id, type and function.name; later chunks carry only index and function.arguments (tools/server/server-chat.cpp:617-621, tools/server/server-task.cpp:203-205)
  • arguments arrive as incremental diffs keyed by tool_call_index (common/chat.cpp), which is why they need concatenating per index
  • use_jinja = true by default (common/common.h), disabled with --no-jinja
  • finish_reason is "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

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - Claude (Opus 5) used assistively, for wording and structure of the prose in the docs and in this description, and as a review pass over the finished diff. The technical claims were verified by me against the source files cited above, and I am responsible for the submitted changes.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Sep 2, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

Hi @apollo-2006, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@apollo-2006
apollo-2006 force-pushed the docs/streaming-tool-calls branch 2 times, most recently from 618c937 to 00fcc67 Compare September 2, 2026 21:18
@apollo-2006
apollo-2006 marked this pull request as ready for review September 2, 2026 21:33
Copilot AI lite review requested due to automatic review settings September 2, 2026 21:33
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.
@apollo-2006
apollo-2006 force-pushed the docs/streaming-tool-calls branch from 00fcc67 to edb465a Compare September 2, 2026 21:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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_calls as 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.

Comment thread docs/function-calling.md Outdated

# 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.
Comment thread docs/function-calling.md Outdated
```

> [!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.
@apollo-2006

apollo-2006 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed, my oversight. The Requirements section now matches .github/pull_request_template.md; the AI usage disclosure was sitting in a paragraph below its bullet rather than on it, so the field rendered empty.

@apollo-2006

Copy link
Copy Markdown
Contributor Author

@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 --no-jinja, or a template that is not tool-aware, tool calls come back as plain assistant text with nothing reporting an error, which is easy to mistake for the model ignoring the tools. Is that still accurate after the new engine landed, or does it now surface something a client can detect? I would rather document the current behaviour than the one I inferred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants