@@ -245,6 +245,7 @@ def _get_default_server_registry() -> ServerRegistry:
245245 from ..context .models import ContextConfig
246246 from ..context .manager import ContextManager
247247 from ..knowledge .knowledge import Knowledge
248+ from .interrupt import InterruptController
248249 from ..agent .autonomy import AutonomyConfig
249250 from ..task .task import Task
250251 from .handoff import Handoff , HandoffConfig , HandoffResult
@@ -531,7 +532,7 @@ def __init__(
531532 # CONSOLIDATED FEATURE PARAMS (agent-centric API)
532533 # Each follows: False=disabled, True=defaults, Config=custom
533534 # ============================================================
534- memory : Optional [Union [bool , str , 'MemoryConfig' , 'MemoryManager' ]] = None ,
535+ memory : Optional [Union [bool , str , 'MemoryConfig' , Any ]] = None ,
535536 knowledge : Optional [Union [bool , str , List [str ], 'KnowledgeConfig' , 'Knowledge' ]] = None ,
536537 planning : Optional [Union [bool , str , 'PlanningConfig' ]] = False ,
537538 reflection : Optional [Union [bool , str , 'ReflectionConfig' ]] = None ,
@@ -551,6 +552,7 @@ def __init__(
551552 parallel_tool_calls : bool = False , # Gap 2: Enable parallel execution of batched LLM tool calls
552553 learn : Optional [Union [bool , str , Dict [str , Any ], 'LearnConfig' ]] = None , # Continuous learning (peer to memory)
553554 backend : Optional [Any ] = None , # External managed agent backend (e.g., ManagedAgentIntegration)
555+ interrupt_controller : Optional ['InterruptController' ] = None , # G2: Cooperative cancellation
554556 ):
555557 """Initialize an Agent instance.
556558
@@ -575,7 +577,7 @@ def __init__(
575577 memory: Memory system configuration. Accepts:
576578 - bool: True enables defaults, False disables
577579 - MemoryConfig: Custom configuration
578- - MemoryManager : Pre-configured instance
580+ - Any : Pre-configured memory instance
579581 knowledge: Knowledge sources. Accepts:
580582 - bool: True enables defaults
581583 - List[str]: File paths, URLs, or text content
@@ -1458,6 +1460,8 @@ def __init__(
14581460 self .instructions = instructions
14591461 # Gap 2: Store parallel tool calls setting for ToolCallExecutor selection
14601462 self .parallel_tool_calls = parallel_tool_calls
1463+ # G2: Store interrupt controller for cooperative cancellation
1464+ self .interrupt_controller = interrupt_controller
14611465 # Check for model name in environment variable if not provided
14621466 self ._using_custom_llm = False
14631467 # Flag to track if final result has been displayed to prevent duplicates
@@ -2851,6 +2855,19 @@ def run_autonomous(
28512855 started_at = started_at ,
28522856 )
28532857
2858+ # G2: Check for interrupt request (cooperative cancellation) - sync version
2859+ if self .interrupt_controller and self .interrupt_controller .is_set ():
2860+ reason = self .interrupt_controller .reason or "unknown"
2861+ return AutonomyResult (
2862+ success = False ,
2863+ output = f"Task interrupted: { reason } " ,
2864+ completion_reason = "interrupted" ,
2865+ iterations = iterations ,
2866+ stage = stage ,
2867+ actions = actions_taken ,
2868+ duration_seconds = time_module .time () - start_time ,
2869+ started_at = started_at ,
2870+ )
28542871
28552872 # Execute one turn using the agent's chat method
28562873 # Always use the original prompt (prompt re-injection)
@@ -3248,6 +3265,20 @@ async def main():
32483265 started_at = started_at ,
32493266 )
32503267
3268+ # G2: Check for interrupt request (cooperative cancellation)
3269+ if self .interrupt_controller and self .interrupt_controller .is_set ():
3270+ reason = self .interrupt_controller .reason or "unknown"
3271+ return AutonomyResult (
3272+ success = False ,
3273+ output = f"Task interrupted: { reason } " ,
3274+ completion_reason = "interrupted" ,
3275+ iterations = iterations ,
3276+ stage = stage ,
3277+ actions = actions_taken ,
3278+ duration_seconds = time_module .time () - start_time ,
3279+ started_at = started_at ,
3280+ )
3281+
32513282
32523283 # Execute one turn using the agent's async chat method
32533284 # Always use the original prompt (prompt re-injection)
0 commit comments