Skip to content

feat(crew): add on_event hook so overrides can't silence the agent - #71

Open
abhishekmishragithub wants to merge 1 commit into
mainfrom
chore/crew-safe-event-hook
Open

feat(crew): add on_event hook so overrides can't silence the agent#71
abhishekmishragithub wants to merge 1 commit into
mainfrom
chore/crew-safe-event-hook

Conversation

@abhishekmishragithub

Copy link
Copy Markdown
Collaborator

Problem

OutputCrewNode.process_event carries the framework routing — SDKSystemLLMRequestEvent -> _handle_llm_request (the LLM turn), transcript -> context, settings updates. A subclass that overrides process_event without super() silently drops all of it and the agent stops responding (the "0 turns, silent" symptom we hit).

Fix (per review)

Extract the routing into a private _route_framework_event() and add an on_event() hook as the documented, super()-free extension point:

async def process_event(self, event):
    await super().process_event(event)      # interrupt handling
    await self._route_framework_event(event) # framework-owned, always runs
    await self.on_event(event)               # user hook — override THIS, no super() needed
    await self.send_event(event)

Overriding on_event can't silence the agent; overriding process_event is discouraged in the docstring.

Scope + backward compat

Contained to OutputCrewNode. RootNode/SinkNode/BackgroundCrewNode legitimately override process_event without super() (no framework routing, and Background deliberately skips interrupts) — untouched, so interrupt semantics don't change anywhere. Legacy process_event-with-super() overrides keep working.

Tests

tests/custom/test_output_node_on_event_hook.py: (1) overriding on_event without super keeps the LLM routing; (2) legacy process_event+super still routes. Both green.

Pairs with #70 (Ready-before-nodes). Both are the SDK-side lifecycle footguns behind why node-level greeting attempts silenced the agent. No version bump — bundle into 5.4.0.

🤖 Generated with Claude Code

OutputCrewNode.process_event carried the framework routing (LLM request ->
generate_response, transcript -> context, settings), so a subclass that
overrode process_event without super() silently dropped it — the agent stopped
responding (0 turns).

Extract that routing into a private _route_framework_event() and add an
on_event() hook as the documented, super()-free extension point. process_event
now runs: interrupt -> framework routing -> on_event -> forward. Overriding
on_event can't drop framework routing; overriding process_event is discouraged
in the docstring. Legacy process_event-with-super() overrides still work.

Backward-compatible, scoped to OutputCrewNode (RootNode/SinkNode/Background
legitimately override process_event without super and are untouched). Tests
cover the on_event path and the legacy super() path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant