Skip to content

Tool-use hook events omit agent_name that other event types populate #3109

Closed

Description

@t-mizumoto1203

Overview

pre_tool_use and post_tool_use hook events do not include agent_name
in their hooks.Input, even though the field exists (hooks.Input.AgentName,
documented as "identifies the agent dispatching the event") and every other
event type populates it. As a result a pre_tool_use hook cannot tell which
agent issued a given tool call.

Motivation

  • Session / turn / before|after_llm_call / on_agent_switch events set
    AgentName: a.Name() when building their Input.
  • Tool events instead build their Input via toolexec.NewHooksInput, which
    receives no agent reference, so AgentName ships empty — even though the
    shared dispatchHook path already receives the agent.
  • Observed in practice: when actually running an agent, the pre_tool_use
    hook input contains no agent_name key (only
    cwd / hook_event_name / session_id / tool_input / tool_name / tool_use_id).
  • There is no usable workaround for a consumer that needs the agent identity
    at tool-call time.

Use Cases

  1. Auditing: decision logs that record which agent invoked each tool.
  2. Per-agent state in builtin hooks: rate limits / tool budgets scoped
    to a specific agent.
  3. Per-agent policy when integrating an external agent-governance tool
    (e.g. a policy engine): a hook consuming pre_tool_use can allow/deny a
    tool based on the calling agent (e.g. only spec-analyst may use fetch).

Proposed Solution

Auto-fill AgentName in the shared dispatchHook path (which already
receives the agent), mirroring how Executor.Dispatch auto-fills Cwd.
Set it only when empty so explicit caller values win; the field is
omitempty, so the change is backward compatible. This covers both
pre_tool_use and post_tool_use (both flow through the same path).

Semantics: agent_name = the agent that directly issues the tool call
(a.Name()); on transfer/handoff it follows the active sub-agent.

Alternatives

  • Pass the agent into toolexec.NewHooksInput and set AgentName there
    (more call-site churn for the same effect).
  • No usable runtime workaround exists today.

Additional Context

The field already exists and is set on every event except tool events, so
this is an asymmetry / oversight rather than a brand-new capability.

Activity

  1. added
    area/agent
    on Jun 14, 2026
  2. added theissue type on Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/agent

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions