agent-zero icon indicating copy to clipboard operation
agent-zero copied to clipboard

Improving the nudge

Open TerminallyLazy opened this issue 2 months ago • 0 comments

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

  1. 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 from agent0. This caused the subordinate agent's context and the hierarchical chain to be lost.
  2. Broken Auto-Nudge Tracking: The extensions responsible for updating last_activity_time were implemented as standalone functions (async def run), but the framework requires extensions to be classes inheriting from Extension. 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 calling kill_process(), ensuring the reference isn't lost when streaming_agent is 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_time against the configured auto_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_time is updated, allowing the monitor to accurately detect and act on timeouts.

TerminallyLazy avatar Nov 19 '25 09:11 TerminallyLazy