fix(agents): merge config and per-call onStepStart hooks for sub-agent forwarding#59
Conversation
…t forwarding The base agent was only forwarding `params.onStepStart` to sub-agents via parentCtx, ignoring `config.onStepStart`. This meant config-level onStepStart hooks were silently dropped when forwarding to sub-agents, unlike onStepFinish which correctly merged both hooks via buildMergedHook. Also adds onStepStart to AgentConfig type for parity with onStepFinish. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 33042e2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds an optional Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant ParentAgent as Parent Agent
participant Merger as Hook Merger
participant SubAgent as Sub-agent
participant ConfigHook as Config onStepStart
participant PerCallHook as Per-call onStepStart
Caller->>ParentAgent: generate(params { onStepStart: PerCallHook })
ParentAgent->>Merger: buildMergedHook(config.onStepStart, params.onStepStart)
Merger-->>ParentAgent: mergedHook
ParentAgent->>SubAgent: invoke with mergedHook
SubAgent->>ParentAgent: step "work" start
ParentAgent->>mergedHook: call StepStartEvent
mergedHook->>ConfigHook: invoke (if present)
mergedHook->>PerCallHook: invoke (if present)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/agents/src/integration/lifecycle.test.ts`:
- Around line 1623-1626: The current assertion only checks for at least one
"work" event but the test intends to verify both the config-level and per-call
onStepStart hooks fired; update the assertion on the filtered stepEvents
(variable subSteps) to require two or more events (e.g., use
toBeGreaterThanOrEqual(2) or toBeGreaterThan(1)) so the test confirms both hooks
executed for the sub-flow.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: fee277c4-c8ca-485a-bd62-371bd27fa66b
📒 Files selected for processing (4)
.changeset/fix-merge-onstepstart.mdpackages/agents/src/core/agents/base/agent.tspackages/agents/src/core/agents/types.tspackages/agents/src/integration/lifecycle.test.ts
FlowAgent doesn't structurally satisfy Agent at the type level (missing model property), but works correctly at runtime. Added oxlint-disable comment explaining the cast. Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Assert >= 2 events instead of > 0 to explicitly verify both config and per-call onStepStart hooks fired for the sub-flow step. Co-Authored-By: Claude <noreply@anthropic.com>
Summary
params.onStepStartto sub-agents viaparentCtx, droppingconfig.onStepStart. This was inconsistent withonStepFinish, which correctly merged both config and per-call hooks viabuildMergedHook.buildMergedHook(log, config.onStepStart, params.onStepStart)in theparentCtxconstruction, matching theonStepFinishpattern.onStepStarttoAgentConfigso config-level step-start hooks can be defined (previously it only existed onGenerateParams).Test plan
parent config and per-call onStepStart both fire for flow sub-agent steps