feat(hooks): add agent and tool lifecycle boundaries#12583
feat(hooks): add agent and tool lifecycle boundaries#12583vincentkoc wants to merge 14 commits intoopenclaw:mainfrom
Conversation
Additional Comments (1)
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run.ts
Line: 846:852
Comment:
**Client toolCallId dropped**
`runEmbeddedAttempt` now returns `clientToolCall.toolCallId`, but this code ignores it and generates a new pending tool id via ``id: `call_${Date.now()}```. For client-delegated tools, this breaks correlation between the returned `pendingToolCalls[].id` and the tool lifecycle hooks (`before_tool_call`/`after_tool_call` + internal `agent:tool:*`) that use the real `toolCallId`. Consider using `attempt.clientToolCall.toolCallId` for `pendingToolCalls[].id` so downstream consumers can correlate consistently.
How can I resolve this? If you propose a fix, please make it concise. |
@greptileai used |
|
Perfect! The fix looks correct. Using Before (broken correlation): After (consistent correlation): This maintains the correlation chain established in src/agents/pi-tool-definition-adapter.ts:151 where the ID is first generated/captured, through the hook system, and now to the consumer-facing The change is minimal, safe, and directly addresses the observability gap you identified. |
|
@greptileai Tool hook ID fallback generation updated as per your ask to use |
8da2dd3 to
f91ed2a
Compare
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
27 similar comments
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated commits). Please recreate the PR from a clean branch. |
|
Moved to #18889 |
Why
Agent execution lacked complete lifecycle boundaries around thinking, response generation, and tool execution, reducing traceability for observability and policy systems. This PR adds those boundaries and ensures tool lifecycle hooks carry
toolCallIdcontext when available. lobster-biscuitSplit Context
This PR was split from closed umbrella PR #9761: #9761.
Detailed Changes
agent:thinking:start/agent:thinking:endagent:response:start/agent:response:endagent:tool:start/agent:tool:endrunAfterToolCallHookwiring for tool execution lifecycle completiontoolCallIdthrough before/after tool hook contexts where availabletoolCallIdand run after-tool hook flowRelated Links, Issues and Resolution
Greptile Overview
Greptile Summary
This PR adds explicit lifecycle boundaries around embedded agent execution and tool calls.
agent:thinking:*,agent:response:*) inside the embedded attempt runner, with a run-scoped fallback session key whensessionKeyis missing.agent:tool:start/agent:tool:endaround tool execution, and wiringafter_tool_callvia a newrunAfterToolCallHook.toolCallIdthrough tool hook contexts. When upstream toolCallIds are missing/blank, wrappers generate a canonicalhook-<uuid>ID and use it consistently.after_tool_callin afinallyblock and includetoolCallIdin the pending tool result.Overall, the changes fit into the existing hooks architecture by expanding internal hook events for observability and enhancing plugin hook context for tool lifecycle correlation.
Confidence Score: 5/5