Skip to content

Conversation

@shentongmartin
Copy link
Contributor

@shentongmartin shentongmartin commented Dec 9, 2025

ADK: Emit Internal Events from Agent Tools

Summary

  • Adds an opt-in mechanism for agent tools to emit internal AgentEvents to their parent agent.
  • Provides a concrete tool option for binding an event generator and a config flag to auto-inject it in nested runs.
  • Improves tracing, debugging, and orchestration of multi-agent workflows without breaking existing APIs.

Problem

  • When an agent is wrapped as a tool and used inside another agent, its internal events are not visible to the parent.
  • This limits live telemetry and provenance tracking across tool boundaries.

Solution

  • Introduce a tool option to pass an event generator into agent tools and forward events upstream.
  • Add a ToolsConfig flag on ChatModelAgent to automatically inject this option when running nested tools.

Implementation

  • adk/agent_tool.go:80 adds WithAgentToolEventGenerator(gen *AsyncGenerator[*AgentEvent]).
  • adk/agent_tool.go:99 forwards events in invokableAgentTool.InvokableRun.
  • adk/chatmodel.go:87–89 adds ToolsConfig.EmitInternalEvents.
  • adk/chatmodel.go:744–746 auto-injects the tool option during ChatModelAgent runs when enabled.

Configuration

  • Enable event emission for nested tools in ChatModelAgent:
agent, _ := adk.NewChatModelAgent(ctx, &adk.ChatModelAgentConfig{
  Model: mdl,
  ToolsConfig: adk.ToolsConfig{
    ToolsNodeConfig: compose.ToolsNodeConfig{
      Tools: []tool.BaseTool{adk.NewAgentTool(ctx, subAgent)},
    },
    EmitInternalEvents: true,
  },
})

Compatibility

  • Default is unchanged; event emission is off unless explicitly enabled.
  • APIs are additive; existing code continues to work.

@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

❌ Patch coverage is 84.37500% with 10 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@d293091). Learn more about missing BASE report.

Files with missing lines Patch % Lines
adk/agent_tool.go 82.75% 3 Missing and 2 partials ⚠️
adk/chatmodel.go 75.00% 2 Missing and 1 partial ⚠️
adk/flow.go 88.23% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #620   +/-   ##
=======================================
  Coverage        ?   79.15%           
=======================================
  Files           ?      123           
  Lines           ?    11562           
  Branches        ?        0           
=======================================
  Hits            ?     9152           
  Misses          ?     1691           
  Partials        ?      719           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shentongmartin shentongmartin force-pushed the feat/agent_tool_event branch 9 times, most recently from e306abf to 75d26ef Compare December 10, 2025 02:49
Change-Id: I8c4a79c2bd2ccfbda88983f068b4db4aefd2fc32
@shentongmartin shentongmartin merged commit f094b51 into main Dec 16, 2025
19 checks passed
@shentongmartin shentongmartin deleted the feat/agent_tool_event branch December 16, 2025 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants