@@ -1067,6 +1067,8 @@ def parse_args(self):
10671067 # External Agent - use external AI CLI tools
10681068 parser .add_argument ("--external-agent" , type = str , choices = ["claude" , "gemini" , "codex" , "cursor" ],
10691069 help = "Use external AI CLI tool (claude, gemini, codex, cursor)" )
1070+ parser .add_argument ("--external-agent-direct" , action = "store_true" ,
1071+ help = "Use external agent as direct proxy (skip manager Agent delegation)" )
10701072
10711073 # Compare - compare different CLI modes
10721074 parser .add_argument ("--compare" , type = str , help = "Compare CLI modes (comma-separated: basic,tools,research,planning)" )
@@ -4365,11 +4367,13 @@ def level_based_approve(function_name, arguments, risk_level):
43654367 existing_tools = list (mcp_tools )
43664368 agent_config ['tools' ] = existing_tools
43674369
4368- # External Agent - Use external AI CLI tools directly
4370+ # External Agent - Use external AI CLI tools with manager delegation
43694371 if getattr (self .args , 'external_agent' , None ):
43704372 from rich .console import Console
43714373 ext_console = Console ()
43724374 external_agent_name = self .args .external_agent
4375+ direct = getattr (self .args , 'external_agent_direct' , False )
4376+
43734377 try :
43744378 from .features .external_agents import ExternalAgentsHandler
43754379 handler = ExternalAgentsHandler (verbose = getattr (self .args , 'verbose' , False ))
@@ -4379,23 +4383,43 @@ def level_based_approve(function_name, arguments, risk_level):
43794383
43804384 integration = handler .get_integration (external_agent_name , workspace = workspace )
43814385
4382- if integration .is_available :
4383- ext_console .print (f"[bold cyan]🔌 Using external agent: { external_agent_name } [/bold cyan]" )
4384-
4385- # Run the external agent directly instead of PraisonAI agent
4386+ if not integration .is_available :
4387+ ext_console .print (f"[yellow]⚠️ External agent '{ external_agent_name } ' is not installed[/yellow]" )
4388+ ext_console .print (f"[dim]Install with: { handler ._get_install_instructions (external_agent_name )} [/dim]" )
4389+ return None
4390+
4391+ if direct :
4392+ # Pass-through proxy (original behavior, preserved as escape hatch)
4393+ ext_console .print (f"[bold cyan]🔌 Using external agent (direct): { external_agent_name } [/bold cyan]" )
43864394 import asyncio
43874395 try :
43884396 result = asyncio .run (integration .execute (prompt ))
43894397 ext_console .print (f"\n [bold green]Result from { external_agent_name } :[/bold green]" )
43904398 ext_console .print (result )
4391- # Return empty string to avoid duplicate printing by caller
43924399 return ""
43934400 except Exception as e :
4394- ext_console .print (f"[red]Error executing { external_agent_name } : { e } [/red]" )
4401+ ext_console .print (f"[red]Error executing { external_agent_name } : { e . __class__ . __name__ } : { e } [/red]" )
43954402 return None
4396- else :
4397- ext_console .print (f"[yellow]⚠️ External agent '{ external_agent_name } ' is not installed[/yellow]" )
4398- ext_console .print (f"[dim]Install with: { handler ._get_install_instructions (external_agent_name )} [/dim]" )
4403+
4404+ # NEW default: manager Agent uses external CLI as subagent tool
4405+ ext_console .print (f"[bold cyan]🔌 Using external agent via manager delegation: { external_agent_name } [/bold cyan]" )
4406+ try :
4407+ from praisonaiagents import Agent
4408+ manager = Agent (
4409+ name = "Manager" ,
4410+ instructions = (
4411+ f"You are a manager that delegates tasks to the { external_agent_name } subagent "
4412+ f"via the { integration .cli_command } _tool. Call the tool for coding/analysis tasks."
4413+ ),
4414+ tools = [integration .as_tool ()],
4415+ llm = agent_config .get ('llm' ) or os .environ .get ("MODEL_NAME" , "gpt-4o-mini" ),
4416+ )
4417+ result = manager .start (prompt )
4418+ ext_console .print (f"\n [bold green]Manager delegation result:[/bold green]" )
4419+ ext_console .print (result )
4420+ return ""
4421+ except Exception as e :
4422+ ext_console .print (f"[red]Error with manager delegation: { e .__class__ .__name__ } : { e } [/red]" )
43994423 return None
44004424 except Exception as e :
44014425 ext_console .print (f"[red]Error setting up external agent: { e } [/red]" )
0 commit comments