feat(tools): add opt-in flag to auto-attach load_artifacts to AgentTool sub-agents#6197
Open
nuthalapativarun wants to merge 1 commit into
Open
Conversation
…ol sub-agents Artifacts saved by a parent agent are forwarded to sub-agents via ForwardingArtifactService, but the bytes are only injected into an LLM agent's request when it explicitly calls the load_artifacts tool. This is easy to miss, especially when AgentTool wraps a composite agent like ParallelAgent with several sub-agents. Adds include_load_artifacts_tool (default False) to AgentTool that recursively attaches load_artifacts_tool to the wrapped agent and all of its sub-agents. Closes google#3232
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem
Artifacts saved by a parent agent are correctly forwarded to sub-agents via
ForwardingArtifactService— I verified this end-to-end with a repro usingParallelAgentwrapped inAgentTool(see issue comment). The actual gap is that the artifact bytes are only injected into an LLM agent's request when it explicitly calls theload_artifactstool. This is by design (avoids sending large payloads on every turn), but it's easy to miss — especially whenAgentToolwraps a composite agent likeParallelAgentwith several sub-agents, none of which haveload_artifactsadded by default.Solution
Adds an opt-in
include_load_artifacts_toolparameter (defaultFalse, preserving existing behavior) toAgentTool. When set toTrue,AgentTool.run_async()recursively attachesload_artifacts_toolto the wrapped agent and all of its sub-agents (skipping non-LLM agents likeParallelAgent/SequentialAgentthemselves, since onlyLlmAgentcan hold tools, but still descending into their sub-agents). It's a no-op if the tool is already present, so it's safe to call on every invocation.Testing Plan
Unit Tests:
Full
tests/unittests/tools/test_agent_tool.pysuite: 41 passed (no regressions).Manual End-to-End (E2E) Tests:
Reproduced the original issue scenario locally: a root agent saves an artifact, calls an
AgentTool-wrappedParallelAgentwith two sub-agents. Without the flag, sub-agents can read/write artifacts viacallback_contextbut the model never sees the bytes unlessload_artifactsis added manually. Withinclude_load_artifacts_tool=True, both sub-agents automatically haveload_artifactsavailable.Checklist
Additional context
See discussion on #3232 — the artifact-forwarding plumbing itself was already confirmed working via repro; this PR addresses the actual reported gap (auto-injecting
load_artifactsfor sub-agents) per the direction discussed by maintainers in that thread.