feat(plugin): expose agent identity and parentAgent in plugin hooks for governance#14806
feat(plugin): expose agent identity and parentAgent in plugin hooks for governance#14806ArmirKS wants to merge 4 commits intoanomalyco:devfrom
Conversation
Add agent to tool.execute.before, tool.execute.after, and shell.env plugin hooks. This is a local-only patch for ContractOps governance.
5 tests covering: - shell.env hook receives agent string - tool.execute.before hook receives agent string - tool.execute.after hook receives agent string - shell.env handles undefined agent (PTY case) - bash tool end-to-end agent threading Validates patch f7aa1dacf exposes agent identity correctly.
…cking Adds parentAgent? to tool.execute.before, tool.execute.after, and shell.env hooks. When agent A spawns agent B via the task tool, hooks now receive: agent='B', parentAgent='A' Top-level agents have parentAgent=undefined. Threaded through: PromptInput, MessageV2.User, Tool.Context, ShellInput, Pty.CreateInput, task.ts, and all 10 Plugin.trigger call sites. 10 tests pass (18 expect() calls) covering agent + parentAgent.
Removes ~50 lines of duplicated Plugin.trigger calls from 3 sites in prompt.ts by extracting Tool.invoke() in tool.ts. Fixes a bug where batch.ts sub-tools never fired plugin hooks. Adds status field to tool.execute.after hook type for distinguishing success from error.
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: Found a potentially related PR: centralize tool plugin hooks + add agent to hook input (PR #13521) This PR appears to be directly related - it mentions centralizing tool plugin hooks and adding agent information to hook inputs, which aligns with your PR's goal of exposing agent identity in plugin hooks and centralizing duplicated The other matches (PR #8315 and #10043) are about analytics metrics and general plugin hook tests but don't appear to be duplicates of the specific governance-focused changes in PR #14806. |
Summary
agentandparentAgentfields intool.execute.before,tool.execute.after, andshell.envplugin hooks, enabling governance plugins (e.g. ContractOps) to enforce per-agent policiesPlugin.triggercalls into a newTool.invoke()helper, fixing a bug wherebatch.tssub-tools never fired plugin hooksstatusfield totool.execute.afterhook for distinguishing success from errorTest plan