Skip to content

Plugin callbacks not propagated to sub-agent runners in agenttool #669

@dmora

Description

@dmora

Bug

When a Plugin is registered on a Runner via PluginConfig, its callbacks (BeforeToolCallback, AfterToolCallback, etc.) do not fire for tools executed inside a sub-agent invoked via agenttool.

Root Cause

agenttool.Run() creates a new runner.Runner at agent_tool.go:170-177 without forwarding PluginConfig:

r, err := runner.New(runner.Config{
    AppName:         t.agent.Name(),
    Agent:           t.agent,
    SessionService:  sessionService,
    ArtifactService: artifact.InMemoryService(),
    MemoryService:   memory.InMemoryService(),
    // PluginConfig not set — sub-runner has no plugins
})

The parent runner stores its plugin manager in context at runner.go:160:

ctx = plugininternal.ToContext(ctx, r.pluginManager)

The sub-runner's Run() then overwrites the parent's plugin manager with its own empty one at the same line. The parent's plugins are lost.

Impact

  • Observability plugins (logging, tracing, metrics) are blind to tool calls inside sub-agents
  • BeforeToolCallback / AfterToolCallback only fire for the agenttool wrapper itself, not for function tools inside the sub-agent
  • Same issue affects RunLive() (line 337)

Reproduction

  1. Create a parent agent with a sub-agent wrapped via agenttool.New()
  2. Sub-agent has a function tool (e.g., functiontool.New(...))
  3. Register a plugin with BeforeToolCallback on the parent runner
  4. Run the parent agent with input that triggers delegation to the sub-agent
  5. Observe: plugin callback fires for tool=sub_agent_name but NOT for the inner function tool

Suggested Fix

Add a HasPlugins() method to PluginManager and make runner.Run() / runner.RunLive() conditional:

// runner.go:160 (and :337 for RunLive)
// Only overwrite if this runner has its own plugins — otherwise inherit parent's
if r.pluginManager.HasPlugins() {
    ctx = plugininternal.ToContext(ctx, r.pluginManager)
}

This preserves backwards compatibility: sub-runners with explicit plugins override; sub-runners without plugins (agenttool case) inherit the parent's.

Related

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions