feat(hooks): add agent_name field to BeforeAgent/AfterAgent hook inputs#25033
feat(hooks): add agent_name field to BeforeAgent/AfterAgent hook inputs#25033Weaxs wants to merge 2 commits intogoogle-gemini:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the agent hook system by introducing an "agent_name" field to "BeforeAgent" and "AfterAgent" hook inputs. This addition provides crucial context to hook scripts, allowing them to determine if they are being executed by the main agent or a subagent. This enables developers to write more precise and targeted hook logic, preventing hooks intended for the main agent from running unnecessarily during subagent operations and improving overall system control and flexibility. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
BeforeAgent and AfterAgent hooks currently fire for both main agent and subagents with no way to distinguish them. This adds an optional agent_name field to the hook input — undefined for the main agent, set to the subagent name (e.g. "browser_agent") for subagents. Hook scripts can use this to skip execution for subagents: agent_name=$(echo "$input" | jq -r '.agent_name // empty') if [ -n "$agent_name" ]; then exit 0; fi Fixes google-gemini#15269
There was a problem hiding this comment.
Code Review
This pull request introduces an agentName property to the AgentLoopContext and hook event inputs (BeforeAgentInput, AfterAgentInput). This enhancement allows hooks to distinguish between events originating from the main agent and those from subagents, providing more precise control over hook execution. The LocalAgentExecutor is updated to correctly propagate the subagent's name to its context. Corresponding documentation in docs/hooks/reference.md has been updated, and new unit tests in hookEventHandler.test.ts confirm that the agent_name is accurately included (or undefined for the main agent) in both BeforeAgent and AfterAgent events. I have no feedback to provide.
Summary
Add an optional
agent_namefield toBeforeAgentandAfterAgenthook inputs, allowing hook scripts to distinguish between the main agent and subagents (e.g.browser_agent,codebase_investigator).Currently,
BeforeAgent/AfterAgenthooks fire for both the main agent and subagents with no way to tell them apart. This causes hooks intended only for the main agent (e.g. auto-commit, post-task notifications) to also fire during subagent execution.Details
agentNamefield toAgentLoopContextinterfaceagentName = definition.namewhen creating subagent execution context inLocalAgentExecutoragent_namefield toBeforeAgentInputandAfterAgentInputinterfacesagent_namefromcontext.agentNameinHookEventHandler.fireBeforeAgentEvent()andfireAfterAgentEvent()agent_nameisundefinedfor the main agent, and set to the subagent name (e.g."browser_agent") for subagentsHook scripts can use this to skip subagent execution:
Related Issues
Fixes #15269
How to Validate
fireBeforeAgentEvent→agent_nameisundefinedfor main agent contextfireBeforeAgentEvent→agent_nameis"browser_agent"for subagent contextfireAfterAgentEvent→ same assertions for both main and subagentagent_namefield and verify:agent_nameis absent/nullcodebase_investigator) →agent_nameis"codebase_investigator"Pre-Merge Checklist