
    Ki                     6   d Z ddlZddlZ ej        e          ZddlZddlZddlm	Z	m
Z
 ddlmZmZmZmZ  eg d          ZdZdZdZg d	Zd
efdZd=dedee         d
efdZdee         d
ee         fdZd>deded
ee         fdZ	 	 	 	 d?dededee         deee                  dee         dedee         dee         dee         dee         fdZ	 	 d@deded
eeef         fdZ	 	 	 	 	 	 dAdee         dee         deee                  deeeeef                           dee         d
efdZ de!d
e!fd Z"d
e!fd!Z#d"d#d$d%d&d'd%d(d'd)d*d%id+d,d)d$d%d-d'd%d.d'd)d*d%id/d,d0dgd1dd2d3d4d5d'd6g d1d7Z$dd8l%m&Z&  e&j'        d"d9e$d: ed;<           dS )Ba  
Delegate Tool -- Subagent Architecture

Spawns child AIAgent instances with isolated context, restricted toolsets,
and their own terminal sessions. Supports single-task and batch (parallel)
modes. The parent blocks until all children complete.

Each child gets:
  - A fresh conversation (no parent history)
  - Its own task_id (own terminal session, file ops cache)
  - A restricted toolset (configurable, with blocked tools always stripped)
  - A focused system prompt built from the delegated goal + context

The parent's context only sees the delegation call and the summary result,
never the child's intermediate tool calls or reasoning.
    N)ThreadPoolExecutoras_completed)AnyDictListOptional)delegate_taskclarifymemorysend_messageexecute_code      2   )terminalfilewebreturnc                      dS )z<Delegation has no external requirements -- always available.T r       0/home/ubuntu/hermes-agent/tools/delegate_tool.pycheck_delegate_requirementsr   +   s    4r   goalcontextc                     ddd|  g}|r,|                                 r|                    d|            |                    d           d                    |          S )z0Build a focused system prompt for a child agent.z@You are a focused subagent working on a specific delegated task. zYOUR TASK:
z

CONTEXT:
a.  
Complete this task using the tools available to you. When finished, provide a clear, concise summary of:
- What you did
- What you found or accomplished
- Any files you created or modified
- Any issues encountered

Be thorough but concise -- your response is returned to the parent agent as a summary.
)stripappendjoin)r   r   partss      r   _build_child_system_promptr#   0   s     	K
tE
  /7==?? /-G--...	LL	%	 	 	 99Ur   toolsetsc                 (    h dfd| D             S )z0Remove toolsets that contain only blocked tools.>   r   r
   
delegationcode_executionc                     g | ]}|v|	S r   r   ).0tblocked_toolset_namess     r   
<listcomp>z(_strip_blocked_tools.<locals>.<listcomp>K   s$    BBB!1,A#A#AA#A#A#Ar   r   )r$   r+   s    @r   _strip_blocked_toolsr-   F   s2       CBBBxBBBBr      
task_index
task_countc                    	 t          |dd          	t          |dd          	ssdS |dk    r	d| dz    dnddg dd	t          d
t          f	fd}fd}||_        |S )a  Build a callback that relays child agent tool calls to the parent display.

    Two display paths:
      CLI:     prints tree-view lines above the parent's delegation spinner
      Gateway: batches tool names and relays to parent's progress callback

    Returns None if no display mechanism is available, in which case the
    child agent runs with no progress callback (identical to current behavior).
    _delegate_spinnerNtool_progress_callbackr.   [] r      	tool_namepreviewc                 p   | dk    rzrv|r t          |          dk    r|d d         dz   n|pd}	                     d d| d           n2# t          $ r%}t                              d|           Y d }~nd }~ww xY wd S r|r t          |          d	k    r|d d	         dz   n|pd}d
dlm}  ||           }d d| d|  }|r	|d| dz  }	                     |           n2# t          $ r%}t                              d|           Y d }~nd }~ww xY w
r	                    |            t          	          k    rrd                    	          }	  
dd |            n2# t          $ r%}t                              d|           Y d }~nd }~ww xY w		                                 d S d S d S )N	_thinking7   z...r    u   ├─ 💭 ""zSpinner print_above failed: %s#   r   )get_tool_emojiu   ├─ z  ", subagent_progress   🔀 zParent callback failed: %s)
lenprint_above	Exceptionloggerdebugagent.displayr?   r    r!   clear)r7   r8   shorter?   emojilinesummary_BATCH_SIZE_batch	parent_cbprefixspinners           r   	_callbackz1_build_child_progress_callback.<locals>._callbacke   s   ## F29dc'llR>O>O"--V]VcacF''(KF(K(K%(K(K(KLLLL  F F FLL!A1EEEEEEEEF F  
	B.5`#g,,:K:KWSbS\E))RYR_]_E444444"N9--E9v99e99i99D )(u((((B##D)))) B B B=qAAAAAAAAB  	MM)$$$6{{k))))F++BI13L63L73L3LMMMM  B B BLL!=qAAAAAAAAB	 	))sG   A 
A=A88A=C( (
D2DDE, ,
F6FFc                      rrrrd                               } 	  dd |             n2# t          $ r%}t                              d|           Y d}~nd}~ww xY w                                 dS dS dS )z<Flush remaining batched tool names to gateway on completion.r@   rA   rB   z Parent callback flush failed: %sN)r!   rE   rF   rG   rI   )rN   rK   rP   rQ   rR   s     r   _flushz._build_child_progress_callback.<locals>._flush   s     	 	ii''GD	-/Hv/Hw/H/HIIII D D D?CCCCCCCCDLLNNNNN	 	 	 	s   . 
AAAN)getattrstrrV   )
r/   parent_agentr0   rT   rV   rO   rP   rQ   rR   rS   s
        @@@@@r   _build_child_progress_callbackr[   N   s     l$7>>G&>EEI 9 t (2A~~#a####2F KF! !S !3 ! ! ! ! ! ! ! ! ! !F       Ir   modelmax_iterationsoverride_provideroverride_base_urloverride_api_keyoverride_api_modec           
         ddl m} t          t          |dd          pt                    |rt          fd|D                       }n<|r&t          |dd          rt          |j                  }nt          t                    }t          ||          }t          |dd          }|s*t          |d          r|j	        
                    d          }t          | |          }|p|j        }|pt          |dd          }|p|j        }|	p|}|
pt          |d	d          }t          |d
d          }t          t          |dg           pg           } |d(i d|d|d|d|d	|d
|d|d|dt          |dd          dt          |dd          dt          |dd          d|ddd|dd|  dd|j        dddddddt          |dd          d|j        d|j        d |j        d!|j        d"|d#d}t          |d$d          d%z   |_        t          |d&          rbt          |d'd          }|r5|5  |j                            |           ddd           n# 1 swxY w Y   n|j                            |           |S ))a  
    Build a child AIAgent on the main thread (thread-safe construction).
    Returns the constructed child agent without running it.

    When override_* params are set (from delegation config), the child uses
    those credentials instead of inheriting from the parent.  This enables
    routing subagents to a different provider:model pair (e.g. cheap/fast
    model on OpenRouter while the parent runs on Nous Portal).
    r   )AIAgentenabled_toolsetsNc                     g | ]}|v |	S r   r   )r)   r*   parent_toolsetss     r   r,   z&_build_child_agent.<locals>.<listcomp>   s#    .[.[.[Qa?FZFZqFZFZFZr   api_key_client_kwargsproviderapi_modeacp_commandacp_argsbase_urlr\   r]   
max_tokensreasoning_configprefill_messages
quiet_modeTephemeral_system_prompt
log_prefix
[subagent-]platformskip_context_filesskip_memoryclarify_callback
session_db_session_dbproviders_allowedproviders_ignoredproviders_orderprovider_sortr3   iteration_budget_delegate_depthr.   _active_children_active_children_lockr   )	run_agentrc   setrX   DEFAULT_TOOLSETSr-   rd   r#   hasattrrh   getr[   r\   rm   listrv   r|   r}   r~   r   r   r   r    )r/   r   r   r$   r\   r]   rZ   r^   r_   r`   ra   rc   child_toolsetschild_promptparent_api_keychild_progress_cbeffective_modeleffective_providereffective_base_urleffective_api_keyeffective_api_modeeffective_acp_commandeffective_acp_argschildlockrf   s                            @r   _build_child_agentr      s   . "!!!!! ',0BDII]M]^^O @-.[.[.[.[(.[.[.[\\	 @',0BDII @-l.KLL-.>??-dG<<L\9d;;N D6F G G D%488CC 7z<PP 1|1O*UglJPT.U.U*Cl.C(:N*UglJPT.U.U#L-FFglJCCIrJJG   ##!! o $#	
 $# *) $# &~ <t<<< !/A4HHH !/A4HHH ( 4 !- .
----  &&!"  4#$ D%& '( <===)* '88+, '88-. %44/0 #0012  1034 5E: $L2CQGG!KE |/00 8|%<dCC 	8 < <-44U;;;< < < < < < < < < < < < < < < )00777Ls   <I##I'*I'c                 "   t          j                    }t          |dd          }ddl}t          |dt	          |j                            }	 |                    |          }	|rXt          |d          rH	 |                                 n2# t          $ r%}
t                              d|
           Y d}
~
nd}
~
ww xY wt          t          j                    |z
  d          }|	                    d	          pd
}|	                    dd          }|	                    dd          }|	                    dd          }|rd}n|rd}nd}g }i }|	                    d          pg }t          |t                    r|D ]}t          |t                    s|                    d          dk    r|                    d          pg D ]}|                    di           }|                    dd          t!          |                    dd
                    d}|                    |           |                    d          }|r|||<   |                    d          dk    r|                    dd
          }t%          |od|dd                                         v           }t!          |          |rdndd}|                    d           }|r|                    |          nd}||                    |           |r|d!                             |           |rd}n|rd}nd"}t          |d#d          }t          |d$d          }t          |d%d          } | ||||t          | t*                    r| nd|t          |t,          t.          f          r|ndt          |t,          t.          f          r|ndd&|d'	}!|dk    r|	                    dd(          |!d<   |!ddl}t          |dd          }"t          |"t                    rt	          |"          |_        t          |d)          r	 t          |d*d          }#|#r5|#5  |j                            |           ddd           S # 1 swxY w Y   S |j                            |           S # t4          t6          f$ r%}
t                              d+|
           Y d}
~
S d}
~
ww xY wS # t          $ rG}$t          t          j                    |z
  d          }t9          j        d,|  d-           | ddt+          |$          d|d.cY d}$~$ddl}t          |dd          }"t          |"t                    rt	          |"          |_        t          |d)          r	 t          |d*d          }#|#r5|#5  |j                            |           ddd           S # 1 swxY w Y   S |j                            |           S # t4          t6          f$ r%}
t                              d+|
           Y d}
~
S d}
~
ww xY wS d}$~$ww xY w# ddl}t          |dd          }"t          |"t                    rt	          |"          |_        t          |d)          r	 t          |d*d          }#|#r5|#5  |j                            |           ddd           w # 1 swxY w Y   w |j                            |           w # t4          t6          f$ r%}
t                              d+|
           Y d}
~
w d}
~
ww xY ww xY w)/zi
    Run a pre-built child agent. Called from within a thread.
    Returns a structured result dict.
    r3   Nr   _delegate_saved_tool_names)user_messagerV   z"Progress callback flush failed: %sr   final_responser   	completedFinterrupted	api_callsfailedmessagesrole	assistant
tool_callsfunctionnameunknown	arguments)tool
args_bytesidr   contenterrorP   ok)result_bytesstatustool_call_idr]   session_prompt_tokenssession_completion_tokensr\   )inputoutput)	r/   r   rN   r   duration_secondsr\   exit_reasontokens
tool_tracez$Subagent did not produce a response.r   r   z/Could not remove child from active_children: %srt   z] failedr/   r   rN   r   r   r   )time	monotonicrX   model_toolsr   _last_resolved_tool_namesrun_conversationr   rV   rE   rF   rG   roundr   
isinstancedictrC   r    boollowerupdaterY   intfloatr   remove
ValueErrorUnboundLocalErrorlogging	exception)%r/   r   r   rZ   _kwargschild_startr   r   _saved_tool_namesresultrK   durationrN   r   r   r   r   r   trace_by_idr   msgtcfnentry_ttc_idr   is_errorresult_metatargetr   _input_tokens_output_tokens_modelentrysaved_tool_namesr   excs%                                        r   _run_single_childr      s}	    .""K  '?FF 'C $[%J K KM M@S''T'::  	F):H!E!E 	FF!((**** F F FA1EEEEEEEEF ))K7;;**-..4"JJ{E22	jj66JJ{A..	 	"FF 	 !FFF ,.
13::j))/Rh%% 	; ; ;!#t,, 776??k11"ww|44: 	9 	9VVJ33$&FF69$=$=*-bff[".E.E*F*F# # #))'222 "t  918K.	9 WWV__..!ggi44G#CGwss|/A/A/C/C$C   H ),G-5"?''4# #K
  GGN33E7<F[__U333$F)k2222# ;"2--k:::  	+'KK 	+%KK*K  '>BB (CQGG.. %" ()&#66@VVD&*4]S%L*Q*QXWX,6~U|,T,T[..Z[  %!
 !
 X#ZZ1WXXE'N" 	"5*FMM&-- 	K489I4J4JK1 <!344 		SS|-DdKK @ D D$5<<UCCCD D D D D D D D D D D D D D D D !188???? 12 S S SNPQRRRRRRRRS		S-  

 

 

))K7;;;z;;;<<<$XX (
 
 	
 	
 	
 	
 	
 	"5*FMM&-- 	K489I4J4JK1 <!344 		SS|-DdKK @ D D$5<<UCCCD D D D D D D D D D D D D D D D !188???? 12 S S SNPQRRRRRRRRS		S-

 	"5*FMM&-- 	K489I4J4JK1 <!344 		SS|-DdKK @ D D$5<<UCCCD D D D D D D D D D D D D D D D !188???? 12 S S SNPQRRRRRRRRS		SsA  (S 6B 
S 
B:B50S 5B::L&S /RQ+R+Q/	/R2Q/	3R7RS#SSXAX(X)X! <WV8,W8V<	<W?V<	 WWX0XXXX! !A\1[Z-![,\-Z11[4Z15[8\9[\\
%\ \\

\tasksc                 >   |t          j        ddi          S t          |dd          }|t          k    rt          j        ddt           di          S t	                      }|                    dt                    }|p|}		 t          ||          }
n:# t          $ r-}t          j        dt          |          i          cY d}~S d}~ww xY w|r%t          |t                    r|dt                   }nI| r1t          | t                    r|                                 r| ||d	g}nt          j        dd
i          S |st          j        ddi          S t          |          D ]I\  }}|                    dd                                          st          j        dd| di          c S Jt          j                    }g }t#          |          }d |D             }ddl}t          |j                  }g }	 t          |          D ]\  }}t)          ||d         |                    d          |                    d          p||
d         |	||
d         |
d         |
d         |
d                   }||_        |                    |||f           	 ||_        n# ||_        w xY w|dk    r;|d         \  }}}t/          d|d         ||          }|                    |           n,d}t          |dd          }t1          t                    5 }i }|D ]0\  }}}|                    t.          ||d         ||          }|||<   1t5          |          D ]}	 |                                } n5# t8          $ r(}||         }!|!ddt          |          ddd} Y d}~nd}~ww xY w|                    |            |dz  }| d         }!|!t#          |          k     r||!         nd|! }"|                     dd          }#|                     d d!          }$|$d"k    rd#nd$}%||z
  }&|% d%|!dz    d&| d'|" d(|# d)
}'|r9	 |                    |'           n4# t8          $ r t=          d*|'            Y nw xY wt=          d*|'            |r`|&dk    rZ	 |                    d+|& d,|&dk    rd-nd d.           [# t8          $ r&}(t@          !                    d/|(           Y d}(~(d}(~(ww xY w	 ddd           n# 1 swxY w Y   |"                    d0 1           |rtG          |d2          r|j$        r|D ]} 	 | d         t#          |          k     r|| d                  d         nd})|j$        %                    |)|                     d3d          pd| d         t#          |          k     r#t          || d                  d4         d5d          nd6           # t8          $ r Y w xY wtM          t          j                    |z
  d4          }*t          j        ||*d7d89          S ):a  
    Spawn one or more child agents to handle delegated tasks.

    Supports two modes:
      - Single: provide goal (+ optional context, toolsets)
      - Batch:  provide tasks array [{goal, context, toolsets}, ...]

    Returns JSON with results array, one entry per task.
    Nr   z.delegate_task requires a parent agent context.r   r   z Delegation depth limit reached (z,). Subagents cannot spawn further subagents.r]   r   r   r$   z7Provide either 'goal' (single task) or 'tasks' (batch).zNo tasks provided.r   r   zTask z is missing a 'goal'.c                 .    g | ]}|d          dd         S )r   N(   r   )r)   r*   s     r   r,   z!delegate_task.<locals>.<listcomp>  s$    555a1V9SbS>555r   r   r$   r\   ri   rm   rg   rj   )r/   r   r   r$   r\   r]   rZ   r^   r_   r`   ra   r.   r2   )max_workers)r/   r   r   rZ   r   r/   r   r   ?r   u   ✓u   ✗z [/r5   z  (zs)z  rB   z tasksz
 remainingzSpinner update_text failed: %sc                     | d         S )Nr/   r   )rs    r   <lambda>zdelegate_task.<locals>.<lambda>0  s
    1\? r   )key_memory_managerrN   r   
session_id)taskr   child_session_id)resultstotal_duration_secondsF)ensure_ascii)'jsondumpsrX   	MAX_DEPTH_load_configr   DEFAULT_MAX_ITERATIONS_resolve_delegation_credentialsr   rY   r   r   MAX_CONCURRENT_CHILDRENr   	enumerater   r   rC   r   r   r   r   r    r   r   submitr   r   rE   rD   printupdate_textrF   rG   sortr   r   on_delegationr   )+r   r   r$   r   r]   rZ   depthcfgdefault_max_itereffective_max_itercredsr   	task_listir   overall_startr   n_taskstask_labels_model_tools_parent_tool_nameschildrenr*   r   _i_tr   completed_countspinner_refexecutorfuturesfuturer   idxlabeldurr   icon	remainingcompletion_linerK   
_task_goaltotal_durations+                                              r   r	   r	     sN   " z7$TUVVV L"3Q77E	z<9 < < <
   	 ..Cww/1GHH';+;//\BB / / /z7CHH-......../  `E4(( `2223			 `*T3'' `DJJLL `"wHMMN		z7$]^___ ;z7$89::: Y'' K K4xx##))++ 	K:w(H(H(H(HIJJJJJ	K N$$MG)nnG559555K
 '&&&lDEE
 HDi(( 	+ 	+DAq&1V9aeeI6F6Fz**6heGn1"'
"3uZGX!&y!1"'
"3  E 0BE,OOQ5M****	+ 2D..1C.CCCC!|| B"1bj%FFv l,?FF,CDDD 1	JG' $ $1e!% 6!- )   #$&w// %J %J"MMOOEE  	 	 	!&/C&)")#'!$S%&,- EEEEEE	 u%%%1$ L),/#k2B2B,B,BC((PSii 2A668S11 &+ 5 5uu5#o5	%)"Q"QSU"Q"QW"Q"Q"Q"Q#"Q"Q"Q 26#//@@@@$ 6 6 64?44555556 000111  J9q==J#//0q	0q0qy\]~~ce0q0q0qrrrr$ J J J%EqIIIIIIIIJI%J1	J 1	J 1	J 1	J 1	J 1	J 1	J 1	J 1	J 1	J 1	J 1	J 1	J 1	J 1	Jh 	22333  
.?@@ 
\Ea 
 		 		ECHCVY\]bYcYcCcCcU5#67??ik
,::# 99Y339rdijvdwz}  G  {H  {H  eH  eHWXeL6I-J1-M|]_%`%`%`  NP ;    
     4>++m;Q??N:"0     s   B 
C
"C?C
C
9BJ 	J%AS3M/.S3/
N!9NS3N!!BS38QS3Q-*S3,Q--S3$R1/S31
S!;SS3S!!S33S7:S73BW
WWr  c                 p   t          |                     d          pd                                          pd}t          |                     d          pd                                          pd}t          |                     d          pd                                          pd}t          |                     d          pd                                          pd}|rk|p&t          j        dd                                          }|st          d          |                                }d	}d
}	d|v rd}d}	nd|v rd}d}	|||||	dS |s|dddddS 	 ddlm}
  |
|          }n)# t          $ r}t          d| d| d          |d}~ww xY w|                    dd          }|st          d| d          ||                    d          |                    d          ||                    d          |                    d          t          |                    d          pg           dS )u  Resolve credentials for subagent delegation.

    If ``delegation.base_url`` is configured, subagents use that direct
    OpenAI-compatible endpoint. Otherwise, if ``delegation.provider`` is
    configured, the full credential bundle (base_url, api_key, api_mode,
    provider) is resolved via the runtime provider system — the same path used
    by CLI/gateway startup. This lets subagents run on a completely different
    provider:model pair.

    If neither base_url nor provider is configured, returns None values so the
    child inherits everything from the parent agent.

    Raises ValueError with a user-friendly message on credential failure.
    r\   r   Nri   rm   rg   OPENAI_API_KEYzeDelegation base_url is configured but no API key was found. Set delegation.api_key or OPENAI_API_KEY.customchat_completionszchatgpt.com/backend-api/codexzopenai-codexcodex_responseszapi.anthropic.com	anthropicanthropic_messages)r\   ri   rm   rg   rj   r   )resolve_runtime_provider)	requestedz$Cannot resolve delegation provider 'z': z. Check that the provider is configured (API key set, valid provider name), or set delegation.base_url/delegation.api_key for a direct endpoint. Available providers: openrouter, nous, zai, kimi-coding, minimax.zDelegation provider 'z^' resolved but has no API key. Set the appropriate environment variable or run 'hermes login'.rj   commandargs)r\   ri   rm   rg   rj   r)  r*  )rY   r   r   osgetenvr   r   hermes_cli.runtime_providerr'  rE   r   )r  rZ   configured_modelconfigured_providerconfigured_base_urlconfigured_api_keyrg   
base_lowerri   rj   r'  runtimer   s                r   r   r   G  s    3777++1r2288::Bdcggj117R88>>@@HDcggj117R88>>@@HDSWWY//5266<<>>F$ 
 7y)2..4466 	  	<  
 )..00
%*j88%H(HH J.."H+H & + 
 
 	
  
 &
 
 	
	HHHHHH**5HIII   Q3F Q Q3 Q Q Q
 

 	 kk)R((G 
O$7 O O O
 
 	
 "KK
++KK
++KK
++;;y))W[[((.B//  s   E, ,
F6FFc                      	 ddl m}  |                     di           }|r|S n# t          $ r Y nw xY w	 ddlm}  |            }|                    di           S # t          $ r i cY S w xY w)aN  Load delegation config from CLI_CONFIG or persistent config.

    Checks the runtime config (cli.py CLI_CONFIG) first, then falls back
    to the persistent config (hermes_cli/config.py load_config()) so that
    ``delegation.model`` / ``delegation.provider`` are picked up regardless
    of the entry point (CLI, gateway, cron).
    r   )
CLI_CONFIGr&   )load_config)clir5  r   rE   hermes_cli.configr6  )r5  r  r6  fulls       r   r   r     s    """"""nn\2.. 	J	   111111{}}xxb)))   			s   # 
00%A A)(A)r	   a  Spawn one or more subagents to work on tasks in isolated contexts. Each subagent gets its own conversation, terminal session, and toolset. Only the final summary is returned -- intermediate tool results never enter your context window.

TWO MODES (one of 'goal' or 'tasks' is required):
1. Single task: provide 'goal' (+ optional context, toolsets)
2. Batch (parallel): provide 'tasks' array with up to 3 items. All run concurrently and results are returned together.

WHEN TO USE delegate_task:
- Reasoning-heavy subtasks (debugging, code review, research synthesis)
- Tasks that would flood your context with intermediate data
- Parallel independent workstreams (research A and B simultaneously)

WHEN NOT TO USE (use these instead):
- Mechanical multi-step work with no reasoning needed -> use execute_code
- Single tool call -> just call the tool directly
- Tasks needing user interaction -> subagents cannot use clarify

IMPORTANT:
- Subagents have NO memory of your conversation. Pass all relevant info (file paths, error messages, constraints) via the 'context' field.
- Subagents CANNOT call: delegate_task, clarify, memory, send_message, execute_code.
- Each subagent gets its own terminal session (separate working directory and state).
- Results are always returned as an array, one entry per task.objectstringzWhat the subagent should accomplish. Be specific and self-contained -- the subagent knows nothing about your conversation history.)typedescriptionzBackground information the subagent needs: file paths, error messages, project structure, constraints. The more specific you are, the better the subagent performs.arrayr<  zToolsets to enable for this subagent. Default: inherits your enabled toolsets. Common patterns: ['terminal', 'file'] for code work, ['web'] for research, ['terminal', 'file', 'web'] for full-stack tasks.)r<  itemsr=  z	Task goalzTask-specific contextzToolsets for this specific taskr   )r<  
propertiesrequiredzBatch mode: up to 3 tasks to run in parallel. Each gets its own subagent with isolated context and terminal session. When provided, top-level goal/context/toolsets are ignored.)r<  r?  maxItemsr=  integerzSMax tool-calling turns per subagent (default: 50). Only set lower for simple tasks.)r   r   r$   r   r]   )r   r=  
parameters)registryr&   c           
         t          |                     d          |                     d          |                     d          |                     d          |                     d          |                    d                    S )Nr   r   r$   r   r]   rZ   )r   r   r$   r   r]   rZ   )r	   r   )r*  kws     r   r   r     sp    }XXf##*%%hhwxx 011VVN++ -  -  - r   u   🔀)r   toolsetschemahandlercheck_fnrL   rW   )r.   )NNNN)NN)NNNNNN)(__doc__r   r   	getLogger__name__rF   r+  r   concurrent.futuresr   r   typingr   r   r   r   	frozensetDELEGATE_BLOCKED_TOOLSr   r   r   r   r   r   rY   r#   r-   r   callabler[   r   r   r	   r   r   r   DELEGATE_TASK_SCHEMAtools.registryrE  registerr   r   r   <module>rW     s   "  		8	$	$ 				  ? ? ? ? ? ? ? ? , , , , , , , , , , , , # $ $ $     	 ... T    
 S 8C= C    ,C49 Cc C C C CE Es Ec EZbckZl E E E Eb (,'+&*'+c cc
c c]c tCy!	c
 C=c c  }c  }c smc  }c c c cP 	VS VSVS
VS 
#s(^VS VS VS VSr !$(,0$(q q
3-qc]q tCy!q Dc3h()	q
 SMq 	q q q qhV V V V V Vrd    8 	I2  !,  !J    (+(	
 
  $)1+ N N,4E\#]#]$+&,h%7+L% %# # "(  R# . "7 e9
 9
t y= =7Y Y z $ # # # # #  	- - )
     r   