Repository navigation
Description
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_switchevents set
AgentName: a.Name()when building their Input. - Tool events instead build their Input via
toolexec.NewHooksInput, which
receives no agent reference, soAgentNameships empty — even though the
shareddispatchHookpath already receives the agent. - Observed in practice: when actually running an agent, the
pre_tool_use
hook input contains noagent_namekey (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
- Auditing: decision logs that record which agent invoked each tool.
- Per-agent state in builtin hooks: rate limits / tool budgets scoped
to a specific agent. - Per-agent policy when integrating an external agent-governance tool
(e.g. a policy engine): a hook consumingpre_tool_usecan allow/deny a
tool based on the calling agent (e.g. onlyspec-analystmay usefetch).
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.NewHooksInputand setAgentNamethere
(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