agent-zero
agent-zero copied to clipboard
Improving the nudge
Fix subordinate agent nudge reset and enable auto-nudge monitoring
Summary
This PR fixes a critical issue where manually nudging a subordinate agent would reset the entire agent chain back to Agent 0, losing the subordinate's context. It also finalizes the Auto-Nudge feature by fixing the activity tracking extensions and refining the monitoring logic.
Problem
-
Manual Nudge Reset: When a subordinate agent (e.g., Agent 1) was running and the "Nudge" button was pressed, the
nudge()method would kill the process and default back to resuming execution fromagent0. This caused the subordinate agent's context and the hierarchical chain to be lost. -
Broken Auto-Nudge Tracking: The extensions responsible for updating
last_activity_timewere implemented as standalone functions (async def run), but the framework requires extensions to be classes inheriting fromExtension. As a result, activity was never tracked, rendering the auto-nudge monitor ineffective.
Solution
1. Fix Manual Nudge (agent.py)
Updated AgentContext.nudge() to:
- Capture the
current_agent(the subordinate) before callingkill_process(), ensuring the reference isn't lost whenstreaming_agentis cleared. - Resume execution using
self._process_chain(current_agent, ...)instead of directly running the monologue. This preserves the superior/subordinate relationship and callback chain.
2. Fix Auto-Nudge Extensions
Refactored the following extensions to use the correct class-based Extension pattern:
-
python/extensions/monologue_start/_50_auto_nudge_tracker.py -
python/extensions/response_stream_chunk/_50_auto_nudge_activity.py -
python/extensions/tool_execute_before/_50_auto_nudge_activity.py -
python/extensions/tool_execute_after/_50_auto_nudge_activity.py
This ensures last_activity_time is correctly updated in the context data during agent activity.
3. Refine Auto-Nudge Monitor (auto_nudge_monitor.py)
- Removed excessive debug logging.
- Standardized the stuck detection logic to compare
last_activity_timeagainst the configuredauto_nudge_timeout. - Ensures
context.nudge()is triggered safely when a timeout occurs.
Verification
- Manual Nudge: Verified that nudging a subordinate agent now correctly resumes execution within that same subordinate agent, preserving the call stack to its superior.
-
Auto-Nudge: Confirmed that activity extensions are now loaded by the system and
last_activity_timeis updated, allowing the monitor to accurately detect and act on timeouts.