Opt-in tool_call_id injection into tool execution - #366
Open
ypicard wants to merge 1 commit into
Open
Conversation
ypicard
force-pushed
the
add-optional-tool_call_id-injection-to
branch
from
August 28, 2026 16:59
8aa8216 to
86018ab
Compare
ypicard
marked this pull request as ready for review
August 28, 2026 18:10
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in mechanism for tool functions to receive the current ToolCall.id via a tool_call_id: str parameter, enabling tools (e.g., indexing/search tools) to key work/results to the specific tool call that produced them while keeping the parameter hidden from the LLM-facing schema.
Changes:
- Add
tool_call_idinjection inEnvironment.exec_tool_calls()when the tool function declares it. - Hide
tool_call_idfromTool.from_functionJSON schema generation and skip it inargref_by_namereference handling. - Add tests and documentation describing the new injected parameter behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_tools.py | Adds coverage for schema hiding, injection into async/sync/state/method tools, concurrency behavior, and spoofing override. |
| src/aviary/tools/base.py | Updates Tool.from_function to exclude tool_call_id from the LLM-facing schema (like state). |
| src/aviary/tools/argref.py | Ensures tool_call_id is not treated as an argref key when using argref_by_name. |
| src/aviary/env.py | Injects the tool call ID into tool execution when the signature declares tool_call_id. |
| README.md | Documents the new optional tool_call_id: str injected parameter for tools. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
A tool function may now declare a tool_call_id: str parameter, and exec_tool_calls passes the ID of the call it is executing, mirroring how state is injected. Environments that attribute per-call work, such as recording which documents a search call indexed, can write it while the tool runs instead of reconstructing the mapping from the ToolRequestMessage afterwards. from_function omits the parameter from the JSON schema, so the model never sees it and cannot emit it. Injection happens per call inside _exec_tool_call, so concurrent calls each receive their own ID.
ypicard
force-pushed
the
add-optional-tool_call_id-injection-to
branch
from
August 28, 2026 20:57
86018ab to
dc45734
Compare
sidnarayanan
approved these changes
Sep 11, 2026
Comment on lines
+242
to
+243
| # optional in the function signature: state is dropped when undeclared, | ||
| # tool_call_id is injected when declared. Tool.from_function keeps both |
Collaborator
There was a problem hiding this comment.
Not sure I appreciate the difference: state is dropped but tool call id is injected? Do they not behave the same?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A tool that indexes documents needs to know which tool call it is serving, so a UI can show which search found which papers. Aviary knows that ID but never hands it to the tool. Environments work around this by scanning the whole corpus after every step and diffing it against the previous one.
A tool function can now declare
tool_call_id: strand get the ID of the call it is running:This works like
state. Declare the parameter to opt in. Leave it out and nothing changes.Tool.from_functionskips it when building the JSON schema, right next to thestateskip, so the model never sees it and cannot send it. If a model sends one anyway, the injected ID wins._exec_tool_callalready runs once per call, so concurrent calls each get their own ID. No globals.argref_by_namepasses the value through instead of treating it as a reference key.Pairs with #349, which made the ID settable on
ToolCall.from_name.