Skip to content

feat(tools): add opt-in flag to auto-attach load_artifacts to AgentTool sub-agents#6197

Open
nuthalapativarun wants to merge 1 commit into
google:mainfrom
nuthalapativarun:fix/3232-auto-include-load-artifacts-tool
Open

feat(tools): add opt-in flag to auto-attach load_artifacts to AgentTool sub-agents#6197
nuthalapativarun wants to merge 1 commit into
google:mainfrom
nuthalapativarun:fix/3232-auto-include-load-artifacts-tool

Conversation

@nuthalapativarun

Copy link
Copy Markdown

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 using ParallelAgent wrapped in AgentTool (see issue comment). The actual gap is that the artifact bytes are only injected into an LLM agent's request when it explicitly calls the load_artifacts tool. This is by design (avoids sending large payloads on every turn), but it's easy to miss — especially when AgentTool wraps a composite agent like ParallelAgent with several sub-agents, none of which have load_artifacts added by default.

Solution

Adds an opt-in include_load_artifacts_tool parameter (default False, preserving existing behavior) to AgentTool. When set to True, AgentTool.run_async() recursively attaches load_artifacts_tool to the wrapped agent and all of its sub-agents (skipping non-LLM agents like ParallelAgent/SequentialAgent themselves, since only LlmAgent can 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:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.
tests/unittests/tools/test_agent_tool.py::test_include_load_artifacts_tool_default_false PASSED
tests/unittests/tools/test_agent_tool.py::test_include_load_artifacts_tool_true_adds_to_wrapped_agent PASSED
tests/unittests/tools/test_agent_tool.py::test_include_load_artifacts_tool_true_adds_to_sub_agents_recursively PASSED
tests/unittests/tools/test_agent_tool.py::test_include_load_artifacts_tool_does_not_duplicate_existing_tool PASSED

4 passed in 2.40s

Full tests/unittests/tools/test_agent_tool.py suite: 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-wrapped ParallelAgent with two sub-agents. Without the flag, sub-agents can read/write artifacts via callback_context but the model never sees the bytes unless load_artifacts is added manually. With include_load_artifacts_tool=True, both sub-agents automatically have load_artifacts available.

Checklist

  • Read CONTRIBUTING.md
  • Self-review performed
  • Comments added for hard-to-understand areas
  • Tests added proving fix/feature works
  • New and existing unit tests pass locally
  • Manually tested end-to-end
  • Dependent changes merged/published downstream

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_artifacts for sub-agents) per the direction discussed by maintainers in that thread.

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with passing message from root agent to AgentTool

1 participant