fix(subagent): pass tool definitions to LLM API in sub-agent loop#1492
Merged
fix(subagent): pass tool definitions to LLM API in sub-agent loop#1492
Conversation
Sub-agents with `tools.allow` configuration were calling `provider.chat()` which returns a plain string with no tool support. The `FilteredToolExecutor` was constructed correctly but its definitions never reached the LLM, causing it to generate XML-style fake tool calls instead of native tool_use blocks. - Rewrite `run_agent_loop` in `subagent/manager.rs` to use `chat_with_tools` with tool definitions collected from `FilteredToolExecutor` - Add `handle_tool_step` to handle `ChatResponse::ToolUse` / `Text` branching and execute tool calls via `execute_tool_call_erased`, building proper ToolUse/ToolResult message parts for the next turn - Add `chat_with_named_provider_and_tools` to `AnyProvider` and `chat_for_named_with_tools` to `Orchestrator` for named provider routing - Expose `tool_execution` module and `tool_def_to_definition` as `pub(crate)` so subagent module can reuse the conversion helper - Add 2 regression tests: tools passed to provider, native tool call executed Fixes #1467
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.
Summary
tools.allowconfig were callingprovider.chat()(plain string, no tools), causing the LLM to generate XML-style fake tool calls instead of nativetool_useblocksrun_agent_loopinsubagent/manager.rsto usechat_with_toolswithFilteredToolExecutordefinitionshandle_tool_stepforChatResponse::ToolUse/Textbranching with proper multi-part message constructionchat_with_named_provider_and_tools/chat_for_named_with_toolsfor named provider routingtool_executionmodule andtool_def_to_definitionaspub(crate)for reuseTest plan
cargo nextest run --config-file .github/nextest.toml --workspace --features full --lib --bins— 4933 passedcargo clippy --workspace --features full -- -D warnings— cleancargo +nightly fmt --check— cleanrun_agent_loop_passes_tools_to_providerverifieschat_with_toolsis calledrun_agent_loop_executes_native_tool_callverifiesexecute_tool_call_erasedinvokedCloses #1467