§
    ØŽ’j0 ã                   ó^  — d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlmZ ddl	m	Z	 ddl
mZmZmZmZmZmZ ddlZddlmZ d	d
lmZmZmZmZ ddlmZ ddlmZ d	dlmZmZm Z m!Z!m"Z" ddl#m$Z$ ddl%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF ddlGmHZH ddlImJZJmKZKmLZLmMZM ddlNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z] ddl^m_Z_m`Z`maZambZbmcZc ddldmeZemfZfmgZgmhZh d	dlimjZj ddlkmlZlmmZm erddlnmoZo neZo G d„ d¦  «        ZpdS )z.The unified agent class in AgentScope library.é    N)ÚQueue©Údeepcopy)Úfnmatch)Údatetime)ÚAnyÚAsyncGeneratorÚSequenceÚListÚTYPE_CHECKINGÚType)Ú	BaseModelé   )ÚContextConfigÚReActConfigÚModelConfigÚInjectionConfigé   )Ú
AgentState)ÚReplyContext)Ú_ToolCallBatchÚActingÚExitÚ	ReasoningÚ_resolve_timezone)Úlogger)Ú_generate_idÚ_json_loads_with_repairÚ_execute_async_or_sync_func)Ú
AgentEventÚModelCallEndEventÚModelCallStartEventÚReplyEndEventÚReplyStartEventÚTextBlockDeltaEventÚTextBlockEndEventÚTextBlockStartEventÚThinkingBlockDeltaEventÚThinkingBlockEndEventÚThinkingBlockStartEventÚToolCallDeltaEventÚToolCallEndEventÚToolCallStartEventÚToolResultDataDeltaEventÚToolResultEndEventÚToolResultStartEventÚToolResultTextDeltaEventÚRequireUserConfirmEventÚRequireExternalExecutionEventÚExternalExecutionResultEventÚUserConfirmResultEventÚDataBlockStartEventÚDataBlockDeltaEventÚDataBlockEndEventÚExceedMaxItersEventÚReplyFinishedReasonÚUserInterruptEventÚHintBlockEvent)ÚAgentOrientedException)ÚChatResponseÚ	ChatUsageÚChatModelBaseÚFinishedReason)ÚMsgÚAssistantMsgÚ	SystemMsgÚUserMsgÚ	TextBlockÚThinkingBlockÚToolCallBlockÚToolResultBlockÚ	DataBlockÚBase64SourceÚ	URLSourceÚToolCallStateÚToolResultStateÚUsageÚ	HintBlock)ÚToolkitÚToolBaseÚ	ToolChunkÚ
ToolChoiceÚToolResponse)ÚPermissionBehaviorÚPermissionEngineÚPermissionDecisionÚPermissionRule)Ú_GenerateStructuredOutput)Ú	OffloaderÚWorkspaceBase)ÚMiddlewareBasec                   óL  — e Zd ZdZ	 	 	 	 	 	 	 	 dQdededededz  dee         dz  de	dz  d	e
dz  d
edz  dedz  dedz  dedz  ddfd„ZdRd„Z	 	 	 dSdeee         z  ez  ez  ez  dz  dee         dz  dedeeez  df         fd„Z	 	 dTdeee         z  ez  ez  ez  dz  dee         dz  defd„ZdUdeee         z  dz  ddfd„Z	 	 dTdedz  dedz  ddfd„Z	 	 dTdedz  dedz  ddfd„Z	 	 dTdeee         z  ez  ez  ez  dz  dee         dz  deeez  df         fd„Z dee!e"z  e#z  df         fd„Z$	 	 dTdeee         z  ez  ez  ez  dz  dee         dz  deeez  df         fd„Z%dee&df         fd„Z'	 dUd e(dz  dee)e*z  e+z  e,z  e-z  e.z  e/z  e0z  e1z  e2z  e3z  e4z  e5z  e6z  ez  df         fd!„Z7	 dUd e(dz  dee)e*z  e+z  e,z  e-z  e.z  e/z  e0z  e1z  e2z  e3z  e4z  e5z  e6z  ez  df         fd"„Z8d#eez  dz  defd$„Z9d#eez  dz  dee!e"z  e:z  e#z  df         fd%„Z;deee         z  dz  ddfd&„Z<d'ee-         dee=         fd(„Z>d'ee-         dee?e@z  e!z  e"z  e:z  e#z  df         fd)„ZAd'ee-         dee?e@z  e!z  e"z  e:z  e#z  df         fd*„ZB	 dUd+e-d,eCd-eeD         dz  ddfd.„ZEd+e-d/eFd0eGeeHf         deIfd1„ZJd+e-d/eFd0eGeeHf         deIfd2„ZK	 dUd+e-d-eeD         dz  dee?e@z  e!z  e"z  e:z  e#z  df         fd3„ZLd+e-ded4         fd5„ZMd+e-ded4         fd6„ZNd+e-d7edeOdee!e"z  e:z  e#z  df         fd8„ZPd9eQd:eeG         deRee         ee         f         fd;„ZSd<ee         ddfd=„ZTd>eUdeReUeUdz  f         fd?„ZVdefd@„ZWdeGeeHf         fdA„ZX	 dUdBee         d:eeG         d e(dz  deYeeYdf         z  fdC„ZZdDede[ddfdE„Z\	 dUdFe]e^e_z  e-z  eUz  e`z           dGeadz  ddfdH„Zbdedz  fdI„Zc	 dUdJedz  dedeez  efz  fdK„ZgdLeGdMeYdefdN„ZhdDedOeeie^e`z           z  defdP„ZjdS )VÚAgentzThe agent class.NÚnameÚsystem_promptÚmodelÚtoolkitÚmiddlewaresÚstateÚ	offloaderÚmodel_configÚcontext_configÚreact_configÚinjection_configÚreturnc                 ó”  — || _         || _        || _        |pt          ¦   «         | _        |pt          ¦   «         | _        |	pt          ¦   «         | _        |
pt          ¦   «         | _
        |pt          ¦   «         | _        |                      ¦   «          t          | j        j        ¦  «        | _        || _        |pt%          ¦   «         | _        |pg }d„ |D ¦   «         | _        d„ |D ¦   «         | _        d„ |D ¦   «         | _        d„ |D ¦   «         | _        d„ |D ¦   «         | _        d„ |D ¦   «         | _        d„ |D ¦   «         | _        dS )	a£  Initialize the agent class in AgentScope.

        Args:
            name (`str`):
                The agent identifier.
            system_prompt (`str`):
                The agent's system prompt. Additional instructions may be
                appended to it dynamically during operation.
            model (`ChatModelBase`):
                The chat model/llm used for this agent.
            toolkit (`Toolkit | None`, optional):
                The toolkit used for registering tools, MCPs and skills as the
                sole source.
            middlewares (`list[MiddlewareBase] | None`, optional):
                Middlewares applied to the agent to modify its behavior
                without altering its source code. Supported hook points
                include: reply, reasoning, permission checking, acting, model
                call, context compression, and system prompt retrieval.
            state (`AgentState | None`, optional):
                The agent state. A new state will be created if not provided.
            offloader (`Offloader | None`, optional):
                The context offloader. If provided, the compressed context and
                tool result will be offloaded.
            model_config (`ModelConfig | None`, optional):
                The additional chat model configuration including fallback
                model and retries.
            context_config (`ContextConfig | None`, optional):
                The context config for context compression and tool result
                compression.
            react_config (`ReActConfig | None`, optional):
                The config for the reasoning-acting loop.
            injection_config (`InjectionConfig | None`, optional):
                The runtime state injection config, which controls how the
                time, (plan) tasks and context usage are injected into the
                context to help the agent better reason and act.
        c                 ó<   — g | ]}|                      d ¦  «        ¯|‘ŒS )Úon_reply©Úis_implemented©Ú.0Ú_s     úEC:\Projects\DSCons\.venv\Lib\site-packages\agentscope\agent\_agent.pyú
<listcomp>z"Agent.__init__.<locals>.<listcomp>À   s;   € ð #
ð #
ð #
Ø a×&6Ò&6°zÑ&BÔ&Bð#
Øð#
ð #
ð #
ó    c                 ó<   — g | ]}|                      d ¦  «        ¯|‘ŒS )Úon_reasoningro   rq   s     rt   ru   z"Agent.__init__.<locals>.<listcomp>Ã   s;   € ð '
ð '
ð '
Ø a×&6Ò&6°~Ñ&FÔ&Fð'
Øð'
ð '
ð '
rv   c                 ó<   — g | ]}|                      d ¦  «        ¯|‘ŒS )Úon_check_permissionro   rq   s     rt   ru   z"Agent.__init__.<locals>.<listcomp>Æ   ó<   € ð .
ð .
ð .
Ø a×&6Ò&6Ð7LÑ&MÔ&Mð.
Øð.
ð .
ð .
rv   c                 ó<   — g | ]}|                      d ¦  «        ¯|‘ŒS )Ú	on_actingro   rq   s     rt   ru   z"Agent.__init__.<locals>.<listcomp>É   s;   € ð $
ð $
ð $
Ø a×&6Ò&6°{Ñ&CÔ&Cð$
Øð$
ð $
ð $
rv   c                 ó<   — g | ]}|                      d ¦  «        ¯|‘ŒS )Úon_model_callro   rq   s     rt   ru   z"Agent.__init__.<locals>.<listcomp>Ì   s;   € ð (
ð (
ð (
Ø a×&6Ò&6°Ñ&GÔ&Gð(
Øð(
ð (
ð (
rv   c                 ó<   — g | ]}|                      d ¦  «        ¯|‘ŒS )Úon_system_promptro   rq   s     rt   ru   z"Agent.__init__.<locals>.<listcomp>Ï   s<   € ð +
ð +
ð +
Ø a×&6Ò&6Ð7IÑ&JÔ&Jð+
Øð+
ð +
ð +
rv   c                 ó<   — g | ]}|                      d ¦  «        ¯|‘ŒS )Úon_compress_contextro   rq   s     rt   ru   z"Agent.__init__.<locals>.<listcomp>Ò   r{   rv   N)r`   Ú_system_promptrb   r   re   r   rg   r   rh   r   ri   r   rj   Ú_validate_configsrW   Úpermission_contextÚ_enginerf   rQ   rc   Ú_reply_middlewaresÚ_reasoning_middlewaresÚ_check_permission_middlewaresÚ_acting_middlewaresÚ_model_call_middlewaresÚ_system_prompt_middlewaresÚ_compress_context_middlewares)Úselfr`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   s               rt   Ú__init__zAgent.__init__r   s­  € ðf ˆŒ	Ø+ˆÔØˆŒ
ØÐ*�j™lœlˆŒ
à(Ð9­K©M¬MˆÔØ,Ð?µ±´ˆÔØ(Ð9­K©M¬MˆÔØ 0Ð EµOÑ4EÔ4EˆÔØ×ÒÑ Ô Ð õ (¨¬
Ô(EÑFÔFˆŒð #ˆŒð
 Ð+¥'¡)¤)ˆŒð "Ð' Rˆð#
ð #
Ø"ð#
ñ #
ô #
ˆÔð'
ð '
Ø"ð'
ñ '
ô '
ˆÔ#ð.
ð .
Ø"ð.
ñ .
ô .
ˆÔ*ð$
ð $
Ø"ð$
ñ $
ô $
ˆÔ ð(
ð (
Ø"ð(
ñ (
ô (
ˆÔ$ð+
ð +
Ø"ð+
ñ +
ô +
ˆÔ'ð.
ð .
Ø"ð.
ñ .
ô .
ˆÔ*Ð*Ð*rv   c                 ó2  — | j         j        | j         j        k    r*t          d| j         j        › d| j         j        › d�¦  «        ‚| j        j        rD| j        j        | j         j        k    r,t          d| j        j        › d| j         j        › d�¦  «        ‚dS dS )a
  Validate the config combinations that a single config class cannot
        check by itself.

        Raises:
            `ValueError`:
                If the reserved/buffer ratios don't leave room ahead of the
                context compression threshold.
        zXThe 'reserve_ratio' of the context config must be smaller than its 'trigger_ratio', got z and ú.z¶The 'context_buffer_ratio' of the injection config must be smaller than the 'trigger_ratio' of the context config, so that the context length is injected before the compression, got N)rh   Úreserve_ratioÚtrigger_ratioÚ
ValueErrorrj   Úinject_runtime_stateÚcontext_buffer_ratio)r�   s    rt   r…   zAgent._validate_configsÖ   sî   € ð ÔÔ-ØÔ"Ô0ò1ð 1õ ð8àÔ&Ô4ð8ð 8ð Ô&Ô4ð8ð 8ð 8ñô ð ð Ô!Ô6ð	àÔ%Ô:ØÔ"Ô0ò1ð 1õ ð8ð Ô,ÔAð8ð 8ð Ô&Ô4ð	8ð 8ð 8ñô ð ð	ð 	ð1ð 1rv   FÚinputsÚstructured_schemaÚyield_final_msgc                ó„   K  — |                       ||¬¦  «        2 3 d{V —†}t          |t          ¦  «        r|sŒ|W V — Œ%6 dS )a·  Reply to the given inputs and stream agent events.

        Args:
            inputs (`Msg | list[Msg] | UserConfirmResultEvent |             UserInterruptEvent | ExternalExecutionResultEvent | None`,             optional):
                The inputs that trigger this reply. See :meth:`reply` for
                the full list of accepted variants.
            structured_schema (`Type[BaseModel] | None`, optional):
                The Pydantic model class that the reply's structured output
                must conform to. See :meth:`reply` for details.
            yield_final_msg (`bool`, defaults to `False`):
                If yield the final reply message. When requiring structured
                output, use this option to get the final message, and access
                it via the `structured_output` attribute.

        Yields:
            `AgentEvent | Msg`:
                Streamed events produced during the reply.

        .. note:: If requiring outside interaction for multiple tool calls
            and only receive partial confirmation or execution results, the
            agent won't re-send the requiring events for the unconfirmed
            or unexecuted tool calls.
        ©r˜   r™   N)Ú_replyÚ
isinstancerB   )r�   r˜   r™   rš   Úchunks        rt   Úreply_streamzAgent.reply_streamû   s„   è è € ðH  Ÿ;š;ØØ/ð 'ñ 
ô 
ð 	ð 	ð 	ð 	ð 	ð 	ð 	�%õ ˜%¥Ñ%Ô%ð ¨oð ØØˆKˆKˆKˆKˆKð
ð 
ð 
s   š?c              ƒ   óž   K  — d}|                       ||¬¦  «        2 3 d{V —†}t          |t          ¦  «        r|}Œ6 |€t          d¦  «        ‚|S )u=  Reply to the given inputs, consuming all streamed events.

        Args:
            inputs (`Msg | list[Msg] | UserConfirmResultEvent |             UserInterruptEvent | ExternalExecutionResultEvent | None`,             optional):
                The inputs that trigger this reply. It can be:

                - a single `Msg` or a list of `Msg` objects to start a new
                  reply,
                - a `UserConfirmResultEvent` or
                  `ExternalExecutionResultEvent` to continue from the
                  outside interaction required by the previous reply,
                - a `UserInterruptEvent` to abort a parked reply â€” the
                  agent closes all pending tool calls with an interrupted
                  tool result and ends the reply without entering the
                  reasoning-acting loop,
                - `None` if there is nothing new to feed in (e.g. just
                  continue from the current state).
            structured_schema (`Type[BaseModel] | None`, optional):
                The Pydantic model class that the reply's structured output
                must conform to, with the validated result carried on the
                final message's ``structured_output`` attribute as a dict.

        Returns:
            `Msg`:
                A final reply message.
        Nrœ   z&Agent did not produce a final message.)r�   rž   rB   ÚRuntimeError)r�   r˜   r™   Ú	final_msgÚ
evt_or_msgs        rt   ÚreplyzAgent.reply'  s‹   è è € ðL !%ˆ	Ø $§¢ØØ/ð !,ñ !
ô !
ð 	'ð 	'ð 	'ð 	'ð 	'ð 	'ð 	'�*õ ˜*¥cÑ*Ô*ð 'Ø&�	øð!
ð ÐÝÐGÑHÔHÐHØÐs   œ;Úmsgsc              ƒ   ó@   K  — |                       |¦  «        ƒ d{V —† dS )zKReceive external observation message(s) and save them into
        context.N)Ú_handle_incoming_messages)r�   r¦   s     rt   ÚobservezAgent.observeX  s4   è è € ð ×,Ò,¨TÑ2Ô2Ð2Ð2Ð2Ð2Ð2Ð2Ð2Ð2Ð2rv   Úinstructionsc           	   ƒ   óÊ   ‡ ‡K  — ‰ j         s‰                      ||¬¦  «        ƒ d{V —† dS d||fdt          dt          dz  dt          dz  ddfˆˆ fd„Š ‰¦   «         ƒ d{V —† dS )	á  Compress the agent's context if the token count exceeds the
        threshold.

        Args:
            context_config (`ContextConfig | None`, optional):
                If provided, compress the context with the given context
                config. Otherwise, use the default context config in the
                agent.
            instructions (`HintBlock | None`, optional):
                Optional hints or instructions injected into the compression
                context to guide the summarization behavior.
        ©rh   rª   Nr   Úindexrh   rª   rk   c              “   ó   •‡ ‡K  — ‰ t          ‰j        ¦  «        k    r‰                     ||¬¦  «        ƒ d{V —† dS ‰j        ‰          }||dœŠdt          ddfˆˆ ˆfd„}|                     ‰‰|¬¦  «        ƒ d{V —† dS )z.Execute the compress_context middleware chain.r­   NÚkwargsrk   c               ›   ó8   •K  —  ‰‰dz   fi i ‰¥| ¥¤Žƒ d {V —† d S ©Nr   © ©r°   Úexecute_chainr®   Úinput_kwargss    €€€rt   Únext_handlerzCAgent.compress_context.<locals>.execute_chain.<locals>.next_handler‡  sa   øè è € Ø+˜mØ! A™Iðð à8 Ð8°Ð8ðð ð ð ð ð ð ð ð ð ð rv   ©Úagentr¶   r·   )ÚlenrŽ   Ú_compress_context_implr   rƒ   )r®   rh   rª   Úmwr·   r¶   rµ   r�   s   `    @€€rt   rµ   z-Agent.compress_context.<locals>.execute_chainu  s  øøøè è € ð �C Ô BÑCÔCÒCÐCØ×5Ò5Ø'5Ø%1ð 6ñ ô ð ð ð ð ð ð ð ð ð ð
 Ô;¸EÔB�Bà*8Ø(4ð$ð $�Lð
µSð ¸Tð ð ð ð ð ð ð ð ð ×0Ò0Ø"Ø%1Ø%1ð 1ñ ô ð ð ð ð ð ð ð ð ð rv   )rŽ   r»   Úintr   rP   )r�   rh   rª   rµ   s   `  @rt   Úcompress_contextzAgent.compress_context]  sç   øøè è € ð" Ô1ð %	"Ø×-Ò-Ø-Ø)ð .ñ ô ð ð ð ð ð ð ð ð ð ð Ø7EØ1=ðð Ýðå -°Ñ 4ðõ (¨$Ñ.ðð ð	ð ð ð ð ð ð ð<  �-‘/”/Ð!Ð!Ð!Ð!Ð!Ð!Ð!Ð!Ð!rv   c              ƒ   ó\  ‡ ‡‡‡‡K  — |p‰ j         Š‰                      ¦   «         ƒ d{V —†} ‰ j        j        di |¤Žƒ d{V —†}‰j        ‰ j        j        z  }||k     rdS t          j        d‰ j        t          |¦  «        t          |¦  «        ¦  «         t          ‰ j        j        ¦  «        dk    r&d}‰ j        j        rd}t          d|› d|› d�¦  «        ‚|                     d	g ¦  «        }‰                      ‰j        ‰ j        j        z  |¦  «        ƒ d{V —†\  ŠŠt          ‰¦  «        dk    rFt          j        d
‰j        ¦  «         ‰                      d‰ j        j        z  |¦  «        ƒ d{V —†\  ŠŠt'          d‰                      ¦   «         ƒ d{V —†¬¦  «        g}‰ j        j        r-|                     t-          d‰ j        j        ¦  «        ¦  «         g }	|�*|	                     t/          ‰ j        |g¬¦  «        ¦  «         |‰z   |	z   t-          d‰j        ¬¦  «        gz   }
ddd‰j        dœdœg}d}‰ j                             |
|¦  «        ƒ d{V —†}|‰ j        j        k    r!t          j        d‰ j        j        ¦  «         d}	 ‰ j                             |
‰j        ¬¦  «        ƒ d{V —†ŠnÞ# t6          $ rÑ}|rÂt          j        d¦  «         t9          dt          ‰¦  «        dz   ¦  «        D ]e}|‰|d…         z   |	z   t-          d‰j        ¬¦  «        gz   }
‰ j                             |
|¦  «        ƒ d{V —†}|‰ j        j        ‰j        z  k     r nŒf‰ j                             |
‰j        ¬¦  «        ƒ d{V —†Šn|d‚Y d}~nd}~ww xY w‰j        t<          j        k    r't          j        d¦  «         tA          j!        ¦   «         ‚dˆˆˆˆˆ fd„}tA          j"         |¦   «         ¦  «        }	 tA          j#        |¦  «        ƒ d{V —† dS # t@          j!        $ r
 |ƒ d{V —† ‚ w xY w)r¬   NzT[AGENT %s]: Current token count %d exceeds the threshold %d, activating compression.r   Ú zand the compression summary zThe system prompt z%exceed(s) the compression threshold (z tokens), cannot be compressed.ÚtoolszgThe reserve ratio %.2f is too large to compress any context.Lower the reserve ratio to 0 as a fallback.Úsystem©r`   ÚcontentÚuserÚfunctionÚgenerate_structured_outputzFCall this function to generate structured output required by the user.)r`   ÚdescriptionÚ
parameters)ÚtyperÆ   Fz�The current context length exceeds the model's context length (%d tokens), the compression maybe failed due to insufficient reserved context for compression.T)ÚmessagesÚstructured_modelz”Failed to compress context, which may be caused by insufficient reserved context for compression. Trying to compress by removing the oldest context.r   z5The context compression was interrupted and skipped. rk   c               “   óL  •K  —  ‰j         j        di ‰j        ¤Ž} ‰j        r5‰j                             ‰j        j        ‰¬¦  «        ƒ d{V —†}| d|› d�z  } ‰                     ‰¦  «        ƒ d{V —† | ‰j        _        ‰‰j        _	        t          j        d‰j        ¦  «         dS )z6Apply the context change with interruption protection.)r¦   Nz:
<system-reminder>The compressed context is offloaded to 'z5', you can refer to it when needed.</system-reminder>z-[AGENT %s]: The context compression finished.r³   )Úsummary_templateÚformatrÄ   rf   Úoffload_contextre   Ú
session_idÚ_clear_unreserved_read_cacheÚsummaryÚcontextr   Úinfor`   )Únew_summaryÚpathÚcfgÚmsgs_to_compressÚmsgs_to_reserveÚresr�   s     €€€€€rt   Ú_apply_changez3Agent._compress_context_impl.<locals>._apply_changeT  sú   øè è € à5˜#Ô.Ô5ÐDÐD¸¼ÐDÐDˆKØŒ~ð 	Ø!œ^×;Ò;Ø”JÔ)Ø)ð <ñ ô ð ð ð ð ð ð �ð ð*Øð*ð *ð *ñ�ð ×3Ò3°OÑDÔDÐDÐDÐDÐDÐDÐDÐDð "-ˆDŒJÔØ!0ˆDŒJÔåŒKØ?Ø”	ñô ð ð ð rv   r³   ©rk   N)$rh   Ú_prepare_model_inputrb   Úcount_tokensr”   Úcontext_sizer   rÕ   r`   r½   rº   re   rÔ   rÓ   r¢   ÚgetÚ_split_context_for_compressionr“   ÚwarningrD   Ú_get_system_promptÚappendrE   rC   Úcompression_promptÚsummary_schemarÇ   Ú	ExceptionÚrangeÚfinished_reasonrA   ÚINTERRUPTEDÚasyncioÚCancelledErrorÚcreate_taskÚshield)r�   rh   rª   r°   Úestimated_tokensÚ	thresholdÚsuffixrÁ   Úmsgs_systemÚinstruction_msgsrË   Úcompression_tool_schemaÚcontext_overflowÚestimated_compression_tokensÚeÚirÜ   Ú
apply_taskrØ   rÙ   rÚ   rÛ   s   `                 @@@@rt   r»   zAgent._compress_context_impl•  sr  øøøøøè è € ð" ,ÐB¨tÔ/Bˆð ×0Ò0Ñ2Ô2Ð2Ð2Ð2Ð2Ð2Ð2ˆØ!8 ¤Ô!8Ð!BÐ!B¸6Ð!BÐ!BÐBÐBÐBÐBÐBÐBÐð Ô%¨¬
Ô(?Ñ?ˆ	Ø˜iÒ'Ð'ØˆFåŒð&àŒIÝÐ Ñ!Ô!Ý�	‰NŒNñ	
ô 	
ð 	
õ ˆtŒzÔ!Ñ"Ô" aÒ'Ð'ð ˆFØŒzÔ!ð 8Ø7�ÝðI Vð Ið IØ'ðIð Ið Iñô ð ð —
’
˜7 BÑ'Ô'ˆð ×5Ò5ØÔ ¤
Ô 7Ñ7Øñ
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ñ	
ØØõ ÐÑ Ô  AÒ%Ð%õ ŒNð>àÔ!ñô ð ð ×9Ò9Ø�D”JÔ+Ñ+Øñô ð ð ð ð ð ð ñØ Øõ ØØ"×5Ò5Ñ7Ô7Ð7Ð7Ð7Ð7Ð7Ð7ðñ ô ð
ˆð Œ:Ôð 	DØ×Ò�w v¨t¬zÔ/AÑBÔBÑCÔCÐCà&(ÐØÐ#Ø×#Ò#ÝØœØ)˜Nðñ ô ñô ð ð Øñàñõ ˜V¨SÔ-CÐDÑDÔDðñð 	ð #à8ð$ ð #&Ô"4ðð ð	ð 	ð#
Ðð !ÐØ-1¬Z×-DÒ-DØØ#ñ.
ô .
ð (
ð (
ð (
ð (
ð (
ð (
Ð$ð (¨$¬*Ô*AÒAÐAÝŒNðAð ”
Ô'ñ	ô ð ð  $Ðð-	"Øœ
×=Ò=Ø!Ø!$Ô!3ð >ñ ô ð ð ð ð ð ð ˆCˆCøõ
 ð '	"ð '	"ð '	"Øð &"Ý”ðIñô ð õ
 ˜q¥#Ð&6Ñ"7Ô"7¸!Ñ";Ñ<Ô<ð ð �Aà#Ø*¨1¨2¨2Ô.ñ/à*ñ+õ $Ø%+Ø(+Ô(>ðñ ô ðñð ð #œj×5Ò5Ø$Ø3ñô ð ð ð ð ð ð ð 1ð 5Øœ*Ô1°CÔ4EÑEòFð Fð ˜ðFð
 !œJ×AÒAØ%Ø%(Ô%7ð Bñ ô ð ð ð ð ð ð ��ð ˜TÐ!ð ����øøøøðC'	"øøøðR Ô¥.Ô"<Ò<Ð<ÝŒNØGñô ð õ Ô(Ñ*Ô*Ð*ð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	õ4 Ô(¨¨©¬Ñ9Ô9ˆ
ð	Ý”. Ñ,Ô,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,øÝÔ%ð 	ð 	ð 	ØÐÐÐÐÐÐÐØð	øøøs%   Ê'J5 Ê5
NÊ?CNÎNÏ6P ÐP+c                óŠ  ‡ ‡K  — ‰ j         s'‰                      ||¬¦  «        2 3 d{V —†}|W V — Œ6 dS d||fdt          dt          t          t                   z  t
          z  t          z  t          z  dz  dt          t                   dz  dt          t          t          z  df         fˆˆ fd„Š ‰¦   «         2 3 d{V —†}|W V — Œ6 dS )	z0Reply entry point (maybe wrapped by middleware).rœ   Nr   r®   r˜   r™   rk   c                óT  •‡ ‡K  — ‰ t          ‰j        ¦  «        k    r'‰                     ||¬¦  «        2 3 d {V —†}|W V — Œ6 d S ‰j        ‰          }||dœŠdt          dt          t
          t          z  d f         fˆˆ ˆfd„}|                     ‰‰|¬¦  «        2 3 d {V —†}|W V — Œ6 d S )Nrœ   r°   rk   c                 óH   •K  —  ‰‰dz   fi i ‰¥| ¥¤Ž2 3 d {V —†}|W V — Œ6 d S r²   r³   ©r°   Úitemrµ   r®   r¶   s     €€€rt   r·   z9Agent._reply.<locals>.execute_chain.<locals>.next_handler£  sy   øè è € ð +8¨-Ø! A™Ið+ð +à8 Ð8°Ð8ð+ð +ð 'ð 'ð 'ð 'ð 'ð 'ð ' $ð #'˜J˜J˜J˜J˜Jð	+ð +ð +ó   ”!r¸   )rº   rˆ   Ú_reply_implr   r	   r    rB   rn   )	r®   r˜   r™   rÿ   r¼   r·   r¶   rµ   r�   s	   `     @€€rt   rµ   z#Agent._reply.<locals>.execute_chainŒ  sN  øøøè è € ð �C Ô 7Ñ8Ô8Ò8Ð8Ø&*×&6Ò&6Ø%Ø*;ð '7ñ 'ô 'ð #ð #ð #ð #ð #ð #ð #˜dð #˜
˜
˜
˜
˜
ð	'ð 'ð 'ð Ô0°Ô7�Bà"(Ø->ð$ð $�Lð
'Ý"%ð'å'­
µSÑ(8¸$Ð(>Ô?ð'ð 'ð 'ð 'ð 'ð 'ð 'ð 'ð ')§k¢kØ"Ø%1Ø%1ð '2ñ 'ô 'ð #ð #ð #ð #ð #ð #ð #˜dð
 #˜
˜
˜
˜
˜
ð'ð 'ð 's   µAÂB')rˆ   r  r½   rB   Úlistr5   r;   r4   r   r   r	   r    )r�   r˜   r™   rÿ   rµ   s   `   @rt   r�   zAgent._replyy  s`  øøè è € ð Ô&ð 0	Ø"×.Ò.ØØ"3ð /ñ ô ð ð ð ð ð ð ð �dð �
�
�
�
�
ð	ð ð ð ð  Ø<Mð%#ð %#Ýð%#åÝ•s”)ñå(ñ)õ %ñ%õ /ñ	/ð
 ñð%#õ $(­	¤?°TÑ#9ð%#õ  ¥
­SÑ 0°$Ð 6Ô7ð%#ð %#ð %#ð %#ð %#ð %#ð %#ðN ,˜m™oœoð ð ð ð ð ð ð �dØ�
�
�
�
�
ð .˜o˜os
   £0Â5Cc           	     ó2  K  — | j         j        sdS | j         j        d         }|j        dk    s|j        | j        k    rdS i }t	          |j        ¦  «        D ]U\  }}t          |t          ¦  «        r|||j        <   Œ%t          |t          ¦  «        r| 
                    |j        d¦  «         ŒVd}|                     ¦   «         D �]S}|j        |         }t          |t          ¦  «        sJ ‚|j         t          j        t          j        fvr?t          | j         j        |j        |         j        |j        |         j        ¬¦  «        W V — t          j        |_         t%          | j         j        |j        |         j        |¬¦  «        W V — t'          | j         j        |j        |         j        t(          j        ¬¦  «        W V — |j                             t          |j        |         j        |j        |         j        |t(          j        ¬¦  «        ¦  «         �ŒUdS )	zdClose the unfinished tool calls on interruption, so the next
        input will be handled normally.NéÿÿÿÿÚ	assistantzR<system-reminder>The tool call has been interrupted by the user.</system-reminder>©Úreply_idÚtool_call_idÚtool_call_name©r  r  Údelta©r  r  re   ©Úidr`   Úoutputre   )re   rÔ   Úroler`   Ú	enumeraterÄ   rž   rH   r  rI   ÚpopÚvaluesrM   ÚALLOWEDÚ	SUBMITTEDr0   r  ÚFINISHEDr1   r/   rN   rë   rå   )r�   Úlast_msgÚawaiting_tool_callsr®   ÚblockÚinterruption_messageÚ
call_blocks          rt   Ú_close_unfinished_tool_callsz"Agent._close_unfinished_tool_calls¶  sh  è è € ð ŒzÔ!ð 	ØˆFà”:Ô% bÔ)ˆØŒ=˜KÒ'Ð'¨8¬=¸D¼IÒ+EÐ+EØˆFð %'ÐÝ% hÔ&6Ñ7Ô7ð 	8ð 	8‰LˆE�5Ý˜%¥Ñ/Ô/ð 8Ø05Ð# E¤HÑ-Ð-Ý˜E¥?Ñ3Ô3ð 8Ø#×'Ò'¨¬°$Ñ7Ô7Ð7øð*ð 	ð
 )×/Ò/Ñ1Ô1ð "	ñ "	ˆEØ!Ô)¨%Ô0ˆJÝ˜j­-Ñ8Ô8Ð8Ð8Ð8ð ÔÝÔ%ÝÔ'ð(ð ð õ +Ø!œZÔ0Ø!)Ô!1°%Ô!8Ô!;Ø#+Ô#3°EÔ#:Ô#?ðñ ô ð ð ð ð õ  -Ô5ˆJÔÝ*ØœÔ,Ø%Ô-¨eÔ4Ô7Ø*ðñ ô ð ð ð ð õ
 %ØœÔ,Ø%Ô-¨eÔ4Ô7Ý%Ô1ðñ ô ð ð ð ð ð
 Ô×#Ò#ÝØÔ'¨Ô.Ô1Ø!Ô)¨%Ô0Ô5Ø/Ý)Ô5ð	ñ ô ñô ð ñ ð7"	ð "	rv   c                óÀ  K  — d}	 t          |t          t          t          f¦  «        r|}d}nd}|}|r|rt	          j        d¦  «         t          |t          ¦  «        rÑ| j                             | j        ¦  «        r0t          | j        j
        | j        j        t          j        ¬¦  «        }	 |�{|j        t          j        k    }|r"|                      ¦   «         2 3 d{V —†}|W V — Œ6 |W V — |r=t!          | j        j        | j        | j        j        t          j        ¬¦  «        W V — dS dS dS |                      |¦  «        ƒ d{V —†}|r$|                      |¦  «        2 3 d{V —†}	|	W V — Œ6 nr|                      |¦  «        ƒ d{V —† t-          t/          ¦   «         d|d¬¦  «        | j        _        t3          | j        j
        | j        j        | j        ¬¦  «        W V — | j                             t8          j        ¦  «        ƒ d{V —† | j        j        j        r=| j                             t9          | j        j        j        ¬¦  «        ¦  «        ƒ d{V —† d}
	 |                      |
¦  «        }|xt@          d
˜ x�š\  }} |pg D ]}|W V — Œ|r|W V — 	 |�{|j        t          j        k    }|r"|                      ¦   «         2 3 d{V —†}|W V — Œ6 |W V — |r=t!          | j        j        | j        | j        j        t          j        ¬¦  «        W V — dS dS dS  xtB          d˜ x��„\  }} d}
|r!| j         "                    | j        |g¦  «         |  #                    ¦   «         ƒ d{V —† |  $                    ¦   «         2 3 d{V —†}	|	W V — Œ6 d}|  %                    |¬¦  «        2 3 d{V —†}	t          |	tL          ¦  «        r|	}
Œt          |	tN          ¦  «        r|	j        tP          j        k    }|	W V — ŒO6 |r²t          | j        j
        | j        j        t          j        ¬¦  «        }	 |�{|j        t          j        k    }|r"|                      ¦   «         2 3 d{V —†}|W V — Œ6 |W V — |r=t!          | j        j        | j        | j        j        t          j        ¬¦  «        W V — dS dS dS �n« tR          d˜ x��ž\  }|  *                    |¦  «        ƒ d{V —†D �]}}|j+        dk    r|  ,                    |j-        ¦  «        }n=|j+        dk    r|  .                    |j-        ¦  «        }nt_          d|j+        › �¦  «        ‚d}d}|2 3 d{V —†}	|	W V — t          |	t`          tb          f¦  «        rd	}Œ+t          |	td          ¦  «        r|	j        tf          j        k    rd	}ŒX6 |r²t          | j        j
        | j        j        t          j        ¬¦  «        } |�{|j        t          j        k    }|r"|                      ¦   «         2 3 d{V —†}|W V — Œ6 |W V — |r=t!          | j        j        | j        | j        j        t          j        ¬¦  «        W V — dS dS dS |r n�Œn | j         4                    | j        ¦  «        s| j        xj5        dz  c_5        �Œ-# tl          j7        $ r@ t          | j        j
        | j        j        t          j        ¬¦  «        }| j        j8        r‚ Y nw xY w	 |�{|j        t          j        k    }|r"|                      ¦   «         2 3 d{V —†}|W V — Œ6 |W V — |r=t!          | j        j        | j        | j        j        t          j        ¬¦  «        W V — dS dS dS # |�z|j        t          j        k    }|r"|                      ¦   «         2 3 d{V —†}|W V — Œ6 |W V — |r;t!          | j        j        | j        | j        j        t          j        ¬¦  «        W V — w w w xY w)zCore reply logic.NzrThe given structured_schema is ignored when resuming with a HITL event; the parked reply's schema is used instead.©rÑ   r  rê   ©r  r`   rÄ   rê   r   )r  Úcur_iterr™   Ústructured_output)rÑ   r  r`   )ÚschemaT)Úexit_msgÚexit_events©ÚhintÚtool_choiceF©r'  ©Ú
tool_callsÚ
sequentialÚ
concurrentzInvalid batch type: r   )9rž   r5   r;   r4   r   rã   re   Úhas_awaiting_tool_callsr`   r#   rÑ   r  r:   rë   rê   r  rC   ri   r  Ú_check_incoming_eventÚ_handle_incoming_eventr¨   r   r   Úreply_contextr$   rc   Úremove_toolrZ   r™   Úadd_toolÚ_next_actionr   r   Úappend_contextr¾   Ú_inject_runtime_stateÚ
_reasoningrB   r!   rA   r   Ú_batch_tool_callsrÊ   Ú_execute_sequential_tool_callsr*  Ú_execute_concurrent_tool_callsr•   r2   r3   r/   rN   Úget_unfinished_tool_callsr   rì   rí   Ú"interruption_raise_cancelled_error)r�   r˜   r™   Ú	end_eventÚeventr¦   Úinterrupted_endrs   Úis_awaitingÚevtr£   Únext_actionr#  r$  Ú
exit_eventr&  r'  Úinterruptedr*  ÚbatchÚevt_generatorÚbreak_execution_for_hitlÚ break_execution_for_interruptions                          rt   r  zAgent._reply_impl÷  sO  è è € ð +/ˆ	ðp	õ Øå*Ý&Ý0ðñô ð ð �Ø��à�Ø�àð Ð*ð Ý”ð.ñô ð õ ˜&Õ"4Ñ5Ô5ð Ø”:×5Ò5°d´iÑ@Ô@ð Ý -Ø#'¤:Ô#8Ø!%¤Ô!4Ý(;Ô(Gð!ñ !ô !�Ið
 ðd Ð$àÔ-Ý*Ô6ò7ð  ð #ð  à#'×#DÒ#DÑ#FÔ#Fð  ð  ð  ð  ð  ð  ð  ˜aØ˜˜˜˜˜ð $Gð  ����à"ð å&Øœ:Ô.Ø!œYØ $Ô 1Ô FÝ(;Ô(Gð	ñ ô ð ð ð ð ð ð ð %Ð$ðð ðo !%× :Ò :¸5Ñ AÔ AÐAÐAÐAÐAÐAÐAˆKð ð Ø!%×!<Ò!<¸UÑ!CÔ!Cð ð ð ð ð ð ð ˜#Ø�I�I�I�I�Ið "DÐ!Cð ×4Ò4°TÑ:Ô:Ð:Ð:Ð:Ð:Ð:Ð:Ð:å+7Ý)™^œ^ØØ&7Ø&*ð	,ñ ,ô ,�”
Ô(õ &Ø#œzÔ4Ø!œZÔ0Øœðñ ô ð ð ð ð ð ”,×*Ò*Õ+DÔ+IÑJÔJÐJÐJÐJÐJÐJÐJÐJØŒzÔ'Ô9ð Ø”l×+Ò+Ý-Ø#œzÔ7ÔIðñ ô ñô ð ð ð ð ð ð ð ð %)ˆIðs-ð #×/Ò/°	Ñ:Ô:�à!ØI�ÐIÐIÐIÐIÑI¸[¸[¸[Ø*5Ð*;¸ð -ð -˜JØ",Ð,Ð,Ð,Ð,Ð,Ø#ð +Ø"*˜N˜N˜N˜NØðl Ð$àÔ-Ý*Ô6ò7ð  ð #ð  à#'×#DÒ#DÑ#FÔ#Fð  ð  ð  ð  ð  ð  ð  ˜aØ˜˜˜˜˜ð $Gð  ����à"ð å&Øœ:Ô.Ø!œYØ $Ô 1Ô FÝ(;Ô(Gð	ñ ô ð ð ð ð ð ð ð %Ð$ðð ðO Jð G�ÐFÐFÐFÑFÑF¸+¸+¸+Ø$(˜	Øð IØ œJ×5Ò5°d´iÀ$ÀÑHÔHÐHð #×3Ò3Ñ5Ô5Ð5Ð5Ð5Ð5Ð5Ð5Ð5ð *.×)CÒ)CÑ)EÔ)Eð &ð &ð &ð &ð &ð &ð & #Ø"%˜I˜I˜I˜I˜Ið *Fð ',˜Ø)-¯ªØ(3ð *9ñ *ô *ð &ð &ð &ð &ð &ð &ð & #õ  *¨#­sÑ3Ô3ð )ð -0 	Ø (å)¨#Õ/@ÑAÔAð "à$'Ô$7Ý'5Ô'Aò%Bð !,ð
 #&˜I˜I˜I˜I˜Ið*ð" 'ð #Ý(5Ø+/¬:Ô+@Ø)-¬Ô)<å$7Ô$Cð	)ñ )ô )˜Ið #ðZ Ð$àÔ-Ý*Ô6ò7ð  ð #ð  à#'×#DÒ#DÑ#FÔ#Fð  ð  ð  ð  ð  ð  ð  ˜aØ˜˜˜˜˜ð $Gð  ����à"ð å&Øœ:Ô.Ø!œYØ $Ô 1Ô FÝ(;Ô(Gð	ñ ô ð ð ð ð ð ð ð %Ð$ðð ñC#ð? GõR  Ð6Ð6Ð6Ñ6Ñ6¨:Ø+/×+AÒ+AÀ*Ñ+MÔ+MÐ%MÐ%MÐ%MÐ%MÐ%MÐ%Mð 4&ñ 4&˜EØ$œz¨\Ò9Ð9à$(×$GÒ$GØ(-Ô(8ñ%&ô %&ð !. ð "'¤¨|Ò!;Ð!;à$(×$GÒ$GØ(-Ô(8ñ%&ô %&ð !. õ '1Ø$G¸5¼:Ð$GÐ$Gñ'"ô '"ð !"ð 8=Ð4Ø?DÐ<Ø-:ð Lð Lð Lð Lð Lð Lð L cØ&) 	 	 	 	Ý#-Ø$'å(?Ý(Eð%&ñ$"ô $"ð !Lð @DÐ$<Ð$<õ %/¨sÕ4FÑ$GÔ$Gð!Là(+¬	Ý'6Ô'Bò)Cð )Cð HLÐ$Døð# .;ð&  @ð 'Ý,9Ø/3¬zÔ/DØ-1¬ZÔ-@å(;Ô(Gð	-"ñ -"ô -" 	ð !'ð2 Ð$àÔ-Ý*Ô6ò7ð  ð #ð  à#'×#DÒ#DÑ#FÔ#Fð  ð  ð  ð  ð  ð  ð  ˜aØ˜˜˜˜˜ð $Gð  ����à"ð å&Øœ:Ô.Ø!œYØ $Ô 1Ô FÝ(;Ô(Gð	ñ ô ð ð ð ð ð ð ð %Ð$ðð ðG  8ð &Ø % ñ&øði 7ðv ”z×;Ò;¸D¼IÑFÔFð -Ø”JÐ'Ô'¨1Ñ,Ð'Ô'ñgs-øõj Ô%ð 
	ð 
	ð 
	õ &Øœ:Ô0ØœÔ,Ý 3Ô ?ðñ ô ˆIð Ô ÔCð Øðð ð
	øøøðð Ð$àÔ-Ý*Ô6ò7ð  ð #ð  à#'×#DÒ#DÑ#FÔ#Fð  ð  ð  ð  ð  ð  ð  ˜aØ˜˜˜˜˜ð $Gð  ����à"ð å&Øœ:Ô.Ø!œYØ $Ô 1Ô FÝ(;Ô(Gð	ñ ô ð ð ð ð ð ð ð %Ð$ðð øð Ð$àÔ-Ý*Ô6ò7ð  ð #ð  à#'×#DÒ#DÑ#FÔ#Fð  ð  ð  ð  ð  ð  ð  ˜aØ˜˜˜˜˜ð $Gð  ����à"ð å&Øœ:Ô.Ø!œYØ $Ô 1Ô FÝ(;Ô(Gð	ñ ô ð ð ð ð ð ð %ðøøøs�   †B'Z
 ÃC(Ä/2Z
 Å!E.Å'D/Z
 ËKÌA%Z
 Í=N
Î Z
 Î#O2Î)A<Z
 ÑQ Ò'BZ
 Ô?VÕBZ
 ×8XÙ>Z
 Ú
A[Û] Û[Û] Ü
\Ý._Þ^ÞA_c                ó	  K  — | j         j        sdS i }t          j        t	          | j         j        ¦  «        ¦  «        }| j         j        }t          j        t          ¦  «        }| j
        j        j        D ]}||j
        xx         dz  cc<   Œ|d         dk    p|d         dk    }d}| }t          | j
        j        ¦  «        D ]Ì}	|�|r nÅ|	j        dk    rŒt          |	j        ¦  «        D ]£}
t#          |
t$          ¦  «        rb|
j        |k    rWt#          |
j        t*          ¦  «        r|
j        }n$d                     d„ |
j        D ¦   «         ¦  «        }|€d	|v r|}|sd
|v rd}Œyt#          |
t.          ¦  «        r|
j        | j         j        v rd}Œ¤ŒÍd}|��t5          j        d|¦  «        }d}|�X	 t          j        |                     d¦  «                             ¦   «         | j         j        ¦  «        }n# t@          $ r d}Y nw xY w|�§|j!        €kt5          j        d|¦  «        }| "                    t	          |r'|                     d¦  «                             ¦   «         n| j         j        ¦  «        ¬¦  «        }||z
   #                    ¦   «         dz  }d|cxk    o| j         j$        k    nc  }|r1| %                    | j         j        ¦  «        |d<   | j         j        |d<   |r|sd|d         › d|d         › d�|d<   | j
        j&        dk    rœ|  '                    ¦   «         ƒ d{V —†} | j(        j)        d i |¤Žƒ d{V —†}t          | j*        j+        | j(        j,        z  ¦  «        }|t[          d| j*        j+        | j         j.        z
  ¦  «        | j(        j,        z  k    rd|› d|› d�|d<   |rÛ| /                    | j         j0        ¦  «         t%          || j         j1         "                    dd                     d„ | 2                    ¦   «         D ¦   «         ¦  «        ¦  «        ¬¦  «        }| j
         3                    | j        |g¦  «         | j         j4        r3tk          | j
        j6        |j7        |j        |j        ¬¦  «        W V — dS dS dS )!aÙ  Inject the current runtime state (time, plan tasks and context
        usage) into the conversation context as a ``HintBlock``, so the agent
        stays aware of the information that changes across turns/replies.

        .. note:: The injection is **not** ephemeral. It is appended to the
            persistent context on purpose, so the agent can perceive how time
            elapses and what it did at each step, building a sense of time.

        .. note:: We attach a ``HintBlock`` instead of mutating the system
            prompt, so that prompt caching still works while the agent remains
            aware of the changing time / tasks / context.

        .. note:: Only information that *changes* within a conversation is
            injected here. Fixed information should live in the system prompt.

        The injection timing is decided per dimension:

        - **Time**: injected when (1) no time is recorded in the context (i.e.
          the first reply or right after a context compression), or (2) the
          elapsed time since the recorded one exceeds
          ``injection_config.time_interval`` hours. The injected time is the
          wall-clock time of ``injection_config.timezone``, and the timezone
          is injected next to it so that the elapsed time is still correct
          when the configured timezone changes within a conversation.
        - **Plan tasks**: injected when there are pending or in-progress tasks
          while the context contains neither task-related tool calls (e.g.
          they have been compressed away) nor a previous tasks injection.
        - **Context**: injected at the first iteration of a reply when the
          current input tokens are within
          ``injection_config.context_buffer_ratio`` of the compression
          threshold, letting the agent perceive that a compression is near.
          This dimension is evaluated independently of the two above.

        The user defined ``injection_config.extra_fields`` are attached to
        every injection, but never trigger one by themselves.

        Yields:
            `HintBlockEvent`:
                Emitted when a runtime-state hint is injected and
                ``injection_config.emit_hint_event`` is enabled.
        Nr   Úpendingr   Úin_progressr  rÀ   c              3   óN   K  — | ] }t          |t          ¦  «        ¯|j        V — Œ!d S ©N)rž   rF   Útextrq   s     rt   ú	<genexpr>z.Agent._inject_runtime_state.<locals>.<genexpr>W  sH   è è € ð 'ð 'à !Ý)¨!­YÑ7Ô7ð'ØœFð'ð 'ð 'ð 'ð 'ð 'rv   z<current-time>z<tasks>Tz"<current-time>(.*?)</current-time>z<timezone>(.*?)</timezone>)Útzinfoi  zcurrent-timeÚtimezonez	You have z in-progress tasks and z> pending tasks. Use `TaskList` to view them if you don't know.Útasksg        zYour current context contains z tokens. When reaching z) tokens, your context will be compressed.zcontext-lengthz{runtime_state}ú
c              3   ó4   K  — | ]\  }}d |› d|› d|› d�V — ŒdS )ú<ú>z</Nr³   )rr   ÚkÚvs      rt   rN  z.Agent._inject_runtime_state.<locals>.<genexpr>Ø  sS   è è € ð ð Ù.2¨a°Ð)˜AÐ)Ð) Ð)Ð) QÐ)Ð)Ð)ðð ð ð ð ð rv   )Úsourcer&  )r  Úblock_idrX  r&  r³   )8rj   r–   r   Únowr   rP  Úinjection_sourceÚcollectionsÚdefaultdictr½   re   Útasks_contextrQ  ÚreversedrÔ   r  rÄ   rž   rP   rX  r&  ÚstrÚjoinrH   r`   Útask_tool_namesÚreÚsearchÚstrptimeÚgroupÚstripÚtime_formatr•   rO  ÚreplaceÚtotal_secondsÚtime_intervalÚstrftimer   rÞ   rb   rß   rh   r”   rà   Úmaxr—   ÚupdateÚextra_fieldsÚtemplateÚitemsr4  Úemit_hint_eventr<   r  r  )r�   Ú
injectionsrZ  r[  Útask_statusÚtaskÚhas_uncompleted_tasksÚlast_time_textÚaware_of_tasksÚmsgr  rM  Úinject_timeÚmatchÚ	last_timeÚmatch_tzÚelapsed_hoursr°   Úinput_tokensÚtrigger_tokensÚ
hint_blocks                        rt   r5  zAgent._inject_runtime_stateö  sÿ  è è € ðX Ô$Ô9ð 	ØˆFàˆ
õ
 ŒlÕ,¨TÔ-BÔ-KÑLÔLÑMÔMˆð  Ô0ÔAÐõ (Ô3µCÑ8Ô8ˆØ”JÔ,Ô2ð 	)ð 	)ˆDØ˜œ
Ð#Ð#Ô# qÑ(Ð#Ð#Ñ#Ð#ð ˜	Ô" QÒ&ÐH¨+°mÔ*DÀqÒ*Hð 	ð &*ˆð
 3Ð2ˆå˜DœJÔ.Ñ/Ô/ð  	*ð  	*ˆCØÐ)¨nÐ)ð �àŒx˜;Ò&Ð&Øå! #¤+Ñ.Ô.ð *ð *�å˜u¥iÑ0Ô0ð*àœÐ(8Ò8Ð8å! %¤*­cÑ2Ô2ð Ø$œz˜˜à!Ÿwšwð 'ð 'à%*¤Zð'ñ 'ô 'ñ  ô  ˜ð &Ð-Ð2BÀdÐ2JÐ2JØ)-˜Ø)ð .¨i¸4Ð.?Ð.?Ø)-˜øõ ˜u¥mÑ4Ô4ð*àœ
 dÔ&;Ô&KÐKÐKà%)�Nøð/*ð< ˆØÑ%õ ”IØ5Øñô ˆEð ˆIØÐ ð%Ý (Ô 1ØŸš A™œ×,Ò,Ñ.Ô.ØÔ-Ô9ñ!ô !�I�Iøõ "ð %ð %ð %ð !%�I�I�Ið%øøøð
 Ð$ØÔ#Ð+õ  "œyØ5Ø&ñ ô  �Hð !*× 1Ò 1Ý0à'ð@˜HŸNšN¨1Ñ-Ô-×3Ò3Ñ5Ô5Ð5à!%Ô!6Ô!?ñ ô  ð !2ñ !ô !�Ið "% y¡× ?Ò ?Ñ AÔ AÀDÑ H�ð
 ˜ÐMÐMÒMÐM¨$Ô*?Ô*MÒMÐMÐMÐMð�ð ð 	DØ),¯ªØÔ%Ô1ñ*ô *ˆJ�~Ñ&ð &*Ô%:Ô%CˆJ�zÑ"ð !ð 	¨ð 	ðB˜K¨Ô6ð Bð BØ" 9Ô-ðBð Bð Bð �wÑð Œ:Ô !Ò#Ð#à×4Ò4Ñ6Ô6Ð6Ð6Ð6Ð6Ð6Ð6ˆFØ!8 ¤Ô!8Ð!BÐ!B¸6Ð!BÐ!BÐBÐBÐBÐBÐBÐBˆLå ØÔ#Ô1°D´JÔ4KÑKñô ˆNð ÝØØÔ'Ô5ØÔ+Ô@ñAñô ð
 ”*Ô)ñ*òð ð8°\ð 8ð 8Ø-;ð8ð 8ð 8ð Ð+Ñ,ð ð 	ð ×Ò˜dÔ3Ô@ÑAÔAÐAå"Ø'ð Ô*Ô3×;Ò;Ø%Ø—I’Ið ð Ø6@×6FÒ6FÑ6HÔ6Hðñ ô ñ ô ñô ð	
ñ 
ô 
ˆJð ŒJ×%Ò%Ø”	Ø�ñô ð ð Ô$Ô4ð Ý$Ø!œZÔ0Ø'œ]Ø%Ô,Ø#œð	ñ ô ð ð ð ð ð ð ð+	ð 	ð(ð s   Æ.AG3 Ç3HÈHr'  c                óÖ   ‡ ‡K  — ‰ j         s&‰                      |¬¦  «        2 3 d{V —†}|W V — Œ6 dS d|fdt          dt          dt          fˆˆ fd„Š ‰¦   «         2 3 d{V —†}|W V — Œ6 dS )z4Reasoning entry point (maybe wrapped by middleware).r(  Nr   r®   r'  rk   c                ó&  •‡ ‡K  — ‰ t          ‰j        ¦  «        k    r&‰                     |¬¦  «        2 3 d {V —†}|W V — Œ6 d S ‰j        ‰          }d|iŠdt          dt          fˆˆ ˆfd„}|                     ‰‰|¬¦  «        2 3 d {V —†}|W V — Œ6 d S )Nr(  r'  r°   rk   c                 óH   •K  —  ‰‰dz   fi i ‰¥| ¥¤Ž2 3 d {V —†}|W V — Œ6 d S r²   r³   rþ   s     €€€rt   r·   z=Agent._reasoning.<locals>.execute_chain.<locals>.next_handler  ów   øè è € Ø*7¨-Ø! A™Ið+ð +à8 Ð8°Ð8ð+ð +ð 'ð 'ð 'ð 'ð 'ð 'ð ' $ð #'˜J˜J˜J˜J˜Jð	+ð +ð +r   r¸   )rº   r‰   Ú_reasoning_implr   r	   rx   )r®   r'  rÿ   r¼   r·   r¶   rµ   r�   s   `    @€€rt   rµ   z'Agent._reasoning.<locals>.execute_chain  s2  øøøè è € ð �C Ô ;Ñ<Ô<Ò<Ð<Ø&*×&:Ò&:Ø$/ð ';ñ 'ô 'ð #ð #ð #ð #ð #ð #ð #˜dð #˜
˜
˜
˜
˜
ð'ð 'ð 'ð
 Ô4°UÔ;�BØ$1°;Ð#?�Lð'µSð '½^ð 'ð 'ð 'ð 'ð 'ð 'ð 'ð 'ð ')§o¢oØ"Ø%1Ø%1ð '6ñ 'ô 'ð #ð #ð #ð #ð #ð #ð #˜dð
 #˜
˜
˜
˜
˜
ð'ð 'ð 's   ´AÂB)r‰   r†  r½   rT   r	   )r�   r'  rÿ   rµ   s   `  @rt   r6  zAgent._reasoningé  s÷   øøè è € ð, Ô*ð !	Ø"×2Ò2¸{Ð2ÑKÔKð ð ð ð ð ð ð �dØ�
�
�
�
�
ð LÐKÐKð
 Ø*5ð#ð #Ýð#å'ð#õ  ð#ð #ð #ð #ð #ð #ð #ð6 ,˜m™oœoð ð ð ð ð ð ð �dØ�
�
�
�
�
ð .˜o˜os
   ¢/ÁA(c                ó(  K  — t          | j        j        | j        j        ¬¦  «        W V — |                      ¦   «         ƒ d{V —†} | j        dd|i|¤Žƒ d{V —†}ddg g dœ}d}t          j        |¦  «        r:|2 3 d{V —†}|j        r|}Œ|  	                    ||¦  «        2 3 d{V —†}|W V — Œ6 Œ66 n;t          |t          ¦  «        r&|}|  	                    ||¦  «        2 3 d{V —†}|W V — Œ6 |d         �$t          | j        j        |d         ¬¦  «        W V — |d         �$t          | j        j        |d         ¬¦  «        W V — |d         D ] }t          | j        j        |¬	¦  «        W V — Œ!|d
         D ] }	t          | j        j        |	¬¦  «        W V — Œ!|€t!          d¦  «        ‚t#          | j        j        |j        r|j        j        nd|j        r|j        j        nd|j        ¬¦  «        W V — |                      t/          |j        ¦  «        |j        ¦  «         t3          |j        ¦  «        ot5          d„ |j        D ¦   «         ¦  «        }
|j        t6          j        k    r¨t;          d„ |j        D ¦   «         ¦  «        sŒ|
sŒ|                      ¦   «         }|�,|j        �%t?          |j        j        |j        j        ¬¦  «        nd}tA          | j        j        | j!        t/          |j        ¦  «        |tD          j#        ¬¦  «        W V — dS dS dS dS )z6Core reasoning logic. Yields chunks with is_last flag.)r  Ú
model_nameNr'  )rM  ÚthinkingrÁ   ÚdatarM  ©r  rY  r‰  rÁ   ©r  r  rŠ  z®Model returned an empty streaming response: no is_last=True chunk was received.  The model call may have been interrupted mid-stream (network dropout, timeout, or model bug).r   )r  r  Úoutput_tokensrê   c              3   ó@   K  — | ]}t          |t          ¦  «        V — Œd S rL  )rž   rG   )rr   r  s     rt   rN  z(Agent._reasoning_impl.<locals>.<genexpr>š  sH   è è € ð L
ð L
àõ �u�mÑ,Ô,ðL
ð L
ð L
ð L
ð L
ð L
rv   c              3   ó@   K  — | ]}t          |t          ¦  «        V — Œd S rL  )rž   rH   rq   s     rt   rN  z(Agent._reasoning_impl.<locals>.<genexpr>¢  s@   è è € ð ð àõ ˜1�mÑ,Ô,ðð ð ð ð ð rv   ©r  r�  )r  r`   rÄ   Úusagerê   r³   )$r"   re   r  rb   rÞ   Ú_call_modelÚinspectÚ
isasyncgenÚis_lastÚ_convert_chat_response_to_eventrž   r>   r&   r)   r,   r8   r¢   r!   r‘  r  r�  rê   Ú_save_to_contextr  rÄ   ÚboolÚallrA   rë   ÚanyÚ_get_last_msgrO   rC   r`   r:   Ú	COMPLETED)r�   r'  r°   rÛ   Ú	block_idsÚcompleted_responserŸ   r@  r  Údata_block_idÚhas_only_thinking_blocksÚlast_ctxÚfinal_usages                rt   r†  zAgent._reasoning_impl"  s  è è € õ. "Ø”ZÔ(Ø”zÔ'ð
ñ 
ô 
ð 	
ð 	
ð 	
ð 	
ð ×0Ò0Ñ2Ô2Ð2Ð2Ð2Ð2Ð2Ð2ˆð %�DÔ$ð 
ð 
Ø#ð
àð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ˆð ØØØð	
ð 
ˆ	ð 37Ðõ Ô˜cÑ"Ô"ð 	Ø"ð "ð "ð "ð "ð "ð "ð "�eà”=ð 	"Ø).Ð&Ð&ð &*×%IÒ%IØ!Øñ&ô &ð "ð "ð "ð "ð "ð "ð "˜cð "˜	˜	˜	˜	˜	ð	&ð &ð  #˜sõ ˜�\Ñ*Ô*ð 	Ø!$ÐØ!×AÒAØØñô ð ð ð ð ð ð ð �cð �	�	�	�	�	ð	ð �VÔÐ(Ý#ØœÔ,Ø" 6Ô*ðñ ô ð ð ð ð ð �ZÔ Ð,Ý'ØœÔ,Ø" :Ô.ðñ ô ð ð ð ð ð & gÔ.ð 	ð 	ˆLÝ"ØœÔ,Ø)ðñ ô ð ð ð ð ð ð ' vÔ.ð 	ð 	ˆMÝ#ØœÔ,Ø&ðñ ô ð ð ð ð ð ð Ð%Ýðñô ð õ  Ø”ZÔ(à!Ô'ðÐ+Ô1Ô>Ð>àà!Ô'ðÐ,Ô2Ô@Ð@àØ.Ô>ð	
ñ 	
ô 	
ð 		
ð 		
ð 		
ð 		
ð 	×ÒÝÐ#Ô+Ñ,Ô,ØÔ$ñ	
ô 	
ð 	
õ $(Ð(:Ô(BÑ#CÔ#Cð $
Íð L
ð L
à+Ô3ðL
ñ L
ô L
ñ I
ô I
Ð ð Ô.µ.Ô2LÒLÐLÝð ð à+Ô3ðñ ô ñ ô ð Mð
 -ð Mð ×)Ò)Ñ+Ô+ˆHð Ð'¨H¬NÐ,Fõ	 Ø!)¤Ô!<Ø"*¤.Ô">ðñ ô ð ð
 ð õ Ø”:Ô&Ø”YåÐ/Ô7Ñ8Ô8Ø!å 3Ô =ðñ ô ð ð ð ð ð ð ð! MÐLÐLÐLÐLÐLs   Á9B/Â B-ÃC+r=  c              ƒ   ó˜  K  — | j                              | j        ¦  «        }d„ |D ¦   «         }d„ |D ¦   «         }|€4|s|r0t          dt	          |¦  «        › dt	          |¦  «        › d�¦  «        ‚t          |t          ¦  «        rW|st          d|› �¦  «        ‚t          d„ |j        D ¦   «         ¦  «        t          |¦  «        z
  }|rt          d	|› d
�¦  «        ‚t          |t          ¦  «        rW|st          d|› �¦  «        ‚t          d„ |j
        D ¦   «         ¦  «        t          |¦  «        z
  }|rt          d|› d�¦  «        ‚|duS )a¸  Check if the agent is waiting for the incoming event, if no, raise
        error.

        Args:
            event (`UserConfirmResultEvent | ExternalExecutionResultEvent             | None`):
                The incoming event to be checked.

        Raises:
            `ValueError`:
                If the agent is not waiting for the incoming event, or the
                event is not valid.

        Returns:
            `bool`:
                If the agent is waiting for the incoming event, that means
                this reply calling continues from the previous one. If not,
                the reply id and iteration count should be updated for the new
                reply.
        c                 óF   — g | ]}|j         t          j        k    ¯|j        ‘ŒS r³   )re   rM   ÚASKINGr  rq   s     rt   ru   z/Agent._check_incoming_event.<locals>.<listcomp>Ô  s4   € ð "
ð "
ð "
àØŒw�-Ô.Ò.Ð.ð ŒDà.Ð.Ð.rv   c                 óF   — g | ]}|j         t          j        k    ¯|j        ‘ŒS r³   )re   rM   r  r  rq   s     rt   ru   z/Agent._check_incoming_event.<locals>.<listcomp>Ù  s4   € ð (
ð (
ð (
àØŒw�-Ô1Ò1Ð1ð ŒDà1Ð1Ð1rv   NzAgent is waiting for z/ tool calls and external execution results for z# tool calls, but received no event.zQAgent is not waiting for user confirmation, but received UserConfirmResultEvent: c              3   ó.   K  — | ]}|j         j        V — Œd S rL  ©Ú	tool_callr  rq   s     rt   rN  z.Agent._check_incoming_event.<locals>.<genexpr>ò  s7   è è € ð ð Ø#$�””ðð ð ð ð ð rv   z3Received UserConfirmResultEvent with tool call ids z' that are not waiting for confirmation.z_Agent is not waiting for external execution result, but received ExternalExecutionResultEvent: c              3   ó$   K  — | ]}|j         V — Œd S rL  ©r  rq   s     rt   rN  z.Agent._check_incoming_event.<locals>.<genexpr>  s$   è è € ÐBÐB Q˜AœDÐBÐBÐBÐBÐBÐBrv   z9Received ExternalExecutionResultEvent with tool call ids z5 that are not waiting for external execution results.)re   Úget_awaiting_tool_callsr`   r•   rº   rž   r5   ÚsetÚconfirm_resultsr4   Úexecution_results)r�   r=  r  Úawaiting_confirmationsÚawaiting_external_executionsÚ	extra_idss         rt   r.  zAgent._check_incoming_event»  s5  è è € ð0 #œj×@Ò@ÀÄÑKÔKÐð"
ð "
à(ð"
ñ "
ô "
Ðð
(
ð (
à(ð(
ñ (
ô (
Ð$ð ˆ=Ø"ð Ø&Bð õ ð*­Ð,BÑ(CÔ(Cð *ð *åÐ3Ñ4Ô4ð*ð *ð *ñô ð õ �eÕ3Ñ4Ô4ð 	Ø)ð Ý ðDØ<AðDð Dñô ð õ ð ð Ø(-Ô(=ðñ ô ñ ô åÐ*Ñ+Ô+ñ,ˆIð ð Ý ðJØ ðJð Jð Jñô ð õ
 �eÕ9Ñ:Ô:ð 	Ø/ð Ý ðJØBGðJð Jñô ð õ
 ÐBÐB¨%Ô*AÐBÑBÔBÑBÔBÅSØ,ñFô Fñ ˆIð ð Ý ð*Ø$ð*ð *ð *ñô ð ð ˜DÐ Ð rv   c                óv  K  — |�t          | j        j        ¦  «        dk    rdS t          |t          ¦  «        �r6d„ |j        D ¦   «         }| j        j        d         }|                     d¦  «        D ]û}t          |¦  «        dk    r dS |j        |v rÚ||j                 }|j        rs|  	                    |j        t          j        ¦  «         |j        j        |_        |j        j        |_        |j        r$|j        D ]}| j                             |¦  «         Œn9|                      |d|j        › d�t&          j        ¬¦  «        2 3 d{V —†}|W V — Œ6 |                     |j        ¦  «         ŒüdS t          |t,          ¦  «        r¤|j        D ]š}|                      |j        |j        ¦  «        2 3 d{V —†}|W V — Œ6 t5          | j        j        |j        |j        |j        ¬	¦  «        W V — |                      |g¦  «         |  	                    |j        t          j        ¦  «         Œ›dS t?          d
|› �¦  «        ‚)aÛ  Handle the incoming event and update the context accordingly.

        Args:
            event (`UserConfirmResultEvent | ExternalExecutionResultEvent             | None`):
                The incoming event to be handled.

        Yields:
            `ToolResultStartEvent             | ToolResultTextDeltaEvent             | ToolResultDataDeltaEvent             | ToolResultEndEvent`:
                The events generated during the handling of the incoming event.
        Nr   c                 ó(   — i | ]}|j         j        |“ŒS r³   r¨  rq   s     rt   ú
<dictcomp>z0Agent._handle_incoming_event.<locals>.<dictcomp>,  s+   € ð $ð $ð $Ø&'�”” ð$ð $ð $rv   r  r©  z(<system-reminder>The execution of tool "z&" is denied by user!</system-reminder>)Úmessagere   ©r  r  re   ÚmetadatazInvalid event type: ) rº   re   rÔ   rž   r5   r®  Úget_content_blocksr  Ú	confirmedÚ_update_tool_call_staterM   r  r©  r`   ÚinputÚrulesr‡   Úadd_ruleÚ_handle_error_tool_callrN   ÚDENIEDr  r4   r¯  Ú_convert_tool_chunk_to_eventr  r/   r  r¸  r—  r  r•   )	r�   r=  Úconfirmed_tool_callsr  r©  ÚconfirmationÚruler@  Útool_results	            rt   r/  zAgent._handle_incoming_event  s  è è € ð2 ˆ=�C ¤
Ô 2Ñ3Ô3°qÒ8Ð8ØˆFå�eÕ3Ñ4Ô4ñ H	=ð$ð $Ø+0Ô+@ð$ñ $ô $Ð ð
 ”zÔ)¨"Ô-ˆHØ%×8Ò8¸ÑEÔEð %;ð %;�	ÝÐ+Ñ,Ô,°Ò1Ð1Ø�E�Eà”<Ð#7Ð7Ð7Ø#7¸	¼Ô#E�LØ#Ô-ð &à×4Ò4Ø%œLÝ)Ô1ñô ð ð *6Ô)?Ô)D˜	œØ*6Ô*@Ô*F˜	œð (Ô-ð <Ø(4Ô(:ð <ð < Ø $¤× 5Ò 5°dÑ ;Ô ;Ð ;Ð ;øð *.×)EÒ)EØ%ð!5Ø$-¤Nð!5ð !5ð !5õ #2Ô"8ð *Fñ *ô *ð 	&ð 	&ð 	&ð 	&ð 	&ð 	&ð 	& #ð #&˜I˜I˜I˜I˜Ið*ð )×,Ò,¨Y¬\Ñ:Ô:Ð:øðK%;ð %;õN ˜Õ;Ñ<Ô<ð 	=à$Ô6ð ð �Ø!%×!BÒ!BØ”NØÔ&ñ"ô "ð ð ð ð ð ð ð ˜#ð �I�I�I�I�Ið	"õ )Ø!œZÔ0Ø!,¤Ø%Ô+Ø(Ô1ð	ñ ô ð ð ð ð ð ×%Ò% { mÑ4Ô4Ð4ð ×,Ò,Ø”NÝ!Ô*ñô ð ð ð#ð õ. Ð;°EÐ;Ð;Ñ<Ô<Ð<s   ÅEÆ.F;c              ƒ   ó¸  ‡
K  — |�rÑt          |¦  «        }t          |t          ¦  «        r|g}|D �]¨}t          |t          ¦  «        r"|j        dk    s|                     g d¢¦  «        rt          d|› d�¦  «        ‚| j        j        j        }t          |j
        ¦  «        D �]\  }Š
t          ‰
t          ¦  «        rt          ˆ
fd„|D ¦   «         ¦  «        rŒ7d}t          ‰
j        t          ¦  «        rt          ‰
j        j        ¦  «        }nZ| j        �S| j                             ‰
¦  «        ƒ d{V —†}t          |j        t          ¦  «        rt          |j        j        ¦  «        }‰
j        rd‰
j        › d	�nd}|r
d
|› d|› d�}	nd|› d‰
j        j        › d�}	t+          d|	¬¦  «        |j
        |<   �Œ| j        j                             |¦  «         �Œ¨dS dS )zPCheck and handle the incoming messages before the reasoning-acting
        loop.rÂ   )r©  rÅ  r‰  zInvalid message in the input: z‰. The message should be a Msg object with role 'user' or 'assistant', and should not contain tool calls, tool results or thinking blocks.c              3   óL   •K  — | ]}t          ‰j        j        |¦  «        V — Œd S rL  )r   rX  Ú
media_type)rr   Úpatternr  s     €rt   rN  z2Agent._handle_incoming_messages.<locals>.<genexpr>‘  sF   øè è € ð ?ð ?à#õ   ¤Ô 7¸ÑAÔAð?ð ?ð ?ð ?ð ?ð ?rv   rÀ   Nznamed 'z' z"<system-reminder>An attached file zis saved into z.</system-reminder>z+<system-reminder>An unsupported input file zis attached with media type 'z'.</system-reminder>rM  )rÊ   rM  )r   rž   rB   r  Úhas_content_blocksr•   rb   Ú	formatterÚsupported_input_media_typesr  rÄ   rJ   rš  rX  rL   r`  Úurlrf   Úoffload_data_blockr`   rÈ  rF   re   rÔ   rå   )r�   r¦   Úcopied_msgsry  Ú	supportedrù   rÍ  Úsavedr`   rM  r  s             @rt   r¨   zAgent._handle_incoming_messagest  s†  øè è € ð ñ 5	/Ý (¨¡¤ˆKÝ˜+¥sÑ+Ô+ð ,Ø*˜m�Ø"ð 1/ñ 1/�å" 3­Ñ,Ô,ðà”x 8Ò+Ð+Ø×-Ò-Ø@Ð@Ð@ñô ð ,õ
 %ð<¸ð <ð <ð <ñô ð ð !œJÔ0ÔL�	Ý )¨#¬+Ñ 6Ô 6ð Gñ G‘H�A�uÝ% e­YÑ7Ô7ð !½3ð ?ð ?ð ?ð ?à'0ð?ñ ?ô ?ñ <ô <ð !ð !ð �CÝ! %¤,µ	Ñ:Ô:ð 8Ý! %¤,Ô"2Ñ3Ô3˜˜ØœÐ3Ø&*¤n×&GÒ&GÈÑ&NÔ&NÐ NÐ NÐ NÐ NÐ NÐ N˜Ý% e¤lµIÑ>Ô>ð 8Ý"% e¤lÔ&6Ñ"7Ô"7˜Cà7<´zÐIÐ3 U¤ZÐ3Ð3Ð3Ð3Àr�DØð 
ðCÀð Cð CØ*-ðCð Cð Cð ˜ðNØ#ðNð Nà %¤Ô 7ðNð Nð Nð õ
 &/°FÀÐ%FÑ%FÔ%F�C”K ‘N‘Nà”
Ô"×)Ò)¨#Ñ.Ô.Ð.Ñ.ðk5	/ð 5	/ð1/ð 1/rv   r*  c              ƒ   ó"  K  — g }|D �]}| j                              |j        ¦  «        ƒ d{V —†}|�|j        rkt	          |¦  «        dk    s|d         j        dk    r&|                     t          d|g¬¦  «        ¦  «         Œ{|d         j                             |¦  «         Œœt	          |¦  «        dk    s|d         j        dk    r&|                     t          d|g¬¦  «        ¦  «         Œæ|d         j                             |¦  «         �Œ|S )zÐBatch the tool calls into a sequence of batches that should be
        executed **sequentially** or **concurrently** according to the tool
        properties `is_concurrency_safe` and `is_read_only`.
        Nr   r  r,  )rÊ   r*  r+  )	rc   Úget_toolr`   Úis_concurrency_saferº   rÊ   rå   r   r*  )r�   r*  Úbatchesr©  Útools        rt   r7  zAgent._batch_tool_calls±  sF  è è € ð )+ˆØ#ð 	=ñ 	=ˆIØœ×.Ò.¨y¬~Ñ>Ô>Ð>Ð>Ð>Ð>Ð>Ð>ˆDð ˆ|˜tÔ7ˆ|Ý�w‘<”< 1Ò$Ð$¨°¬Ô(8¸LÒ(HÐ(HØ—N’NÝ&Ø!-Ø(1 {ðñ ô ñô ð ð ð ˜B”KÔ*×1Ò1°)Ñ<Ô<Ð<Ð<å�w‘<”< 1Ò$Ð$¨°¬Ô(8¸LÒ(HÐ(HØ—N’NÝ&Ø!-Ø(1 {ðñ ô ñô ð ð ð ˜B”KÔ*×1Ò1°)Ñ<Ô<Ð<Ñ<àˆrv   c                óü   K  — d}|D ]t}|                       |¦  «        2 3 d{V —†}|W V — t          |t          t          f¦  «        s*t          |t          ¦  «        r|j        t          j        k    rd} nŒW6 |r dS ŒudS )aÝ  Execute the given tool calls sequentially and yield the events.

        If "RequireUserConfirmEvent" or "RequireExternalExecutionEvent" is
        yielded during the execution, the execution will be paused in the
        sequential mode and wait for the outside trigger events.

        Args:
            tool_calls (`list[ToolCallBlock]`):
                The tool calls to be executed sequentially.

        Yields:
            `RequireUserConfirmEvent             | RequireExternalExecutionEvent             | ToolResultStartEvent             | ToolResultTextDeltaEvent             | ToolResultDataDeltaEvent             | ToolResultEndEvent`:
                The events generated during the execution of the tool calls.
        FNT)Ú_execute_tool_callrž   r2   r3   r/   re   rN   rë   )r�   r*  Úbreak_executionr©  r@  s        rt   r8  z$Agent._execute_sequential_tool_callsÙ  sÕ   è è € ð>  ˆØ#ð 	ð 	ˆIØ!×4Ò4°YÑ?Ô?ð ð ð ð ð ð ð �cØ�	�	�	�	ÝØå/Ý5ðñô ð õ ˜sÕ$6Ñ7Ô7ðð œ	¥_Ô%@Ò@Ð@à&*�OØ�Eøð @ð ð Ø��ðð	ð 	s   žA5c                ó¬  ‡ ‡‡‡‡	K  — t          ¦   «         Š	t          ¦   «         Šg Šdt          t          dz           fˆˆˆ ˆ	ˆfd„}t	          j         |¦   «         ¦  «        }	 	 ‰                     ¦   «         ƒ d{V —†}|‰	u rn|W V — Œ%n¥# t          j        $ r“ |                     ¦   «          	 |ƒ d{V —† n# t          j        $ r Y nw xY w	 	 ‰ 	                    ¦   «         }n# t          j
        $ r Y nw xY w|‰	u rŒ1|W V — Œ6t	          j        ¦   «                              ¦   «          Y dS w xY w|ƒ d{V —†}d„ |D ¦   «         }|rt          d|¦  «        ‚dS )a©  Execute the given tool calls concurrently and yield the events.

        All tool calls are executed concurrently. If one or more tool calls
        fail, the remaining ones are **not** cancelled and will run to
        completion. After all tool calls finish, every exception is collected
        and re-raised together as an :py:exc:`ExceptionGroup` so the caller
        can inspect each failure individually.

        The event stream is guaranteed to be complete: the loop exits only
        after a sentinel value placed by the gather task is received, which
        means every ``queue.put`` from every worker has already finished
        before the generator returns.

        If the caller task is cancelled from outside, the concurrent worker
        tasks are cancelled explicitly (to avoid orphan tasks), any events
        already queued by the workers (including interruption chunks emitted
        by ``toolkit.call_tool`` when it catches ``CancelledError``) are
        flushed to the caller, and the generator returns normally. The
        caller is expected to detect the interruption via the flushed
        ``ToolResultEndEvent(state=INTERRUPTED)`` events, mirroring the
        event-based propagation used by
        :meth:`_execute_sequential_tool_calls`.

        Args:
            tool_calls (`list[ToolCallBlock]`):
                The tool calls to be executed concurrently.

        Yields:
            `RequireUserConfirmEvent             | RequireExternalExecutionEvent             | ToolResultStartEvent             | ToolResultTextDeltaEvent             | ToolResultDataDeltaEvent             | ToolResultEndEvent`:
                The events generated during the execution of the tool calls.

        Raises:
            `ExceptionGroup`:
                Raised after all tool calls finish when one or more of them
                raised an exception. Each individual exception is included in
                the group.
        rk   Nc               “   óŒ   •K  — t          j        ˆˆˆfd„‰D ¦   «         ddiŽƒ d{V —†} ‰                     ‰¦  «        ƒ d{V —† | S )a%  Run all tool calls concurrently and push the sentinel when done.

            Returns:
                `list[BaseException | None]`:
                    One entry per tool call. Each entry is either ``None``
                    (success) or the exception raised by that tool call.
            c                 ó>   •— g | ]}‰                      |‰‰¦  «        ‘ŒS r³   )Ú_into_queue)rr   ÚtcÚ
kept_rulesÚqueuer�   s     €€€rt   ru   zJAgent._execute_concurrent_tool_calls.<locals>._run_all.<locals>.<listcomp>[  s;   ø€ ð ð ð àð ×$Ò$ R¨°
Ñ;Ô;ðð ð rv   Úreturn_exceptionsTN)rì   ÚgatherÚput)Úresultsrß  rà  r�   Úsentinelr*  s    €€€€€rt   Ú_run_allz6Agent._execute_concurrent_tool_calls.<locals>._run_allP  s�   øè è € õ $œNðð ð ð ð ð à(ðñ ô ðð
 #'ðð ð ð ð ð ð ð ˆGð —)’)˜HÑ%Ô%Ð%Ð%Ð%Ð%Ð%Ð%Ð%ØˆNrv   Tc                 ó<   — g | ]}t          |t          ¦  «        ¯|‘ŒS r³   )rž   rè   )rr   Úrs     rt   ru   z8Agent._execute_concurrent_tool_calls.<locals>.<listcomp>ˆ  s'   € ÐEÐEÐE˜A­J°q½)Ñ,DÔ,DÐE�aÐEÐEÐErv   z*One or more tool calls raised an exception)Úobjectr   r  ÚBaseExceptionrì   rî   rá   rí   ÚcancelÚ
get_nowaitÚ
QueueEmptyÚcurrent_taskÚuncancelÚExceptionGroup)
r�   r*  ræ  Úgather_taskr=  rä  Ú
exceptionsrß  rà  rå  s
   ``     @@@rt   r9  z$Agent._execute_concurrent_tool_calls  s  øøøøøè è € õp ‘8”8ˆõ ‘w”wˆð ,.ˆ
ð	¥¥]°TÑ%9Ô :ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	õ, Ô)¨(¨(©*¬*Ñ5Ô5ˆð	ðØ#Ÿiši™kœkÐ)Ð)Ð)Ð)Ð)Ð)�Ø˜HÐ$Ð$ØØ����ð	ð øåÔ%ð 	ð 	ð 	à×ÒÑ Ô Ð ðØ!Ð!Ð!Ð!Ð!Ð!Ð!Ð!Ð!øÝÔ)ð ð ð Ø�ðøøøððØ!×,Ò,Ñ.Ô.�E�EøÝÔ)ð ð ð Ø�Eðøøøà˜HÐ$Ð$ØØ����ðõ Ô Ñ"Ô"×+Ò+Ñ-Ô-Ð-ØˆFˆFð+	øøøð0 $Ð#Ð#Ð#Ð#Ð#Ð#ˆØEÐE ÐEÑEÔEˆ
Øð 	Ý Ø<Øñô ð ð	ð 	sZ   Á"&B	 Â	#D+Â-B6Â5D+Â6CÃD+ÃCÃD+ÃC"Ã!D+Ã"C4Ã1D+Ã3C4Ã43D+Ä*D+r©  rà  rß  c              ƒ   ó~   K  — |                       ||¦  «        2 3 d{V —†}|                     |¦  «        ƒ d{V —† Œ#6 dS )aT  Execute a single tool call and forward every event into *queue*.

        Args:
            tool_call (`ToolCallBlock`):
                The tool call to execute.
            queue (`Queue`):
                The shared async queue that collects events from all
                concurrent workers.
            kept_rules (`list[PermissionRule] | None`, defaults to `None`):
                The batch-shared accumulator of already-surfaced suggested
                rules, forwarded to :meth:`_execute_tool_call` for
                confirmation de-duplication within the concurrent batch.
        N)rØ  rã  )r�   r©  rà  rß  r@  s        rt   rÝ  zAgent._into_queue�  sq   è è € ð& ×0Ò0°¸JÑGÔGð 	!ð 	!ð 	!ð 	!ð 	!ð 	!ð 	!�#Ø—)’)˜C‘.”.Ð Ð Ð Ð Ð Ð Ð Ð ð HÐGÐGs   ™<rÖ  Ú
tool_inputc              ƒ   ó0  ‡ ‡K  — ‰ j         s‰                      |||¦  «        ƒ d{V —†S t          |¦  «        }t          |¦  «        }d|||fdt          dt          dt
          dt          t          t          f         dt          f
ˆˆ fd„Š ‰¦   «         ƒ d{V —†S )	aö  Run permission checking through the middleware onion.

        The middleware chain receives copies of the tool call and tool input;
        changes to these copies do not alter the eventual tool invocation. A
        call already allowed by user confirmation still traverses the
        middleware chain, but skips re-evaluation by the built-in engine.

        Args:
            tool_call (`ToolCallBlock`):
                The validated tool call metadata.
            tool (`ToolBase`):
                The resolved tool instance.
            tool_input (`dict[str, Any]`):
                The parsed and schema-validated tool input.

        Returns:
            `PermissionDecision`:
                The decision that the agent should consume.
        Nr   r®   r©  rÖ  rô  rk   c              “   ó  •‡ ‡K  — ‰ t          ‰j        ¦  «        k    r‰                     |||¦  «        ƒ d{V —†S ‰j        ‰          }|||dœŠdt          dt          fˆˆ ˆfd„}|                     ‰‰|¬¦  «        ƒ d{V —†S )z.Execute the check_permission middleware chain.N)r©  rÖ  rô  r°   rk   c               ›   ó4   •K  —  ‰‰dz   fi i ‰¥| ¥¤Žƒ d {V —†S r²   r³   r´   s    €€€rt   r·   zDAgent._check_permission.<locals>.execute_chain.<locals>.next_handlerß  sW   øè è € Ø*˜]Ø˜A‘Iðð à0˜Ð0¨Ð0ðð ð ð ð ð ð ð ð rv   r¸   )rº   rŠ   Ú_check_permission_implr   rX   rz   )	r®   r©  rÖ  rô  r¼   r·   r¶   rµ   r�   s	   `     @€€rt   rµ   z.Agent._check_permission.<locals>.execute_chainÊ  s  øøøè è € ð �˜DÔ>Ñ?Ô?Ò?Ð?Ø!×8Ò8ØØØñô ð ð ð ð ð ð ð ð Ô3°EÔ:ˆBà&ØØ(ðð ˆLð­Sð Õ5Gð ð ð ð ð ð ð ð ð ×/Ò/ØØ)Ø)ð 0ñ ô ð ð ð ð ð ð ð rv   )
rŠ   rø  r   r½   rH   rR   Údictr`  r   rX   )r�   r©  rÖ  rô  rµ   s   `   @rt   Ú_check_permissionzAgent._check_permission¥  sý   øøè è € ð4 Ô1ð 	Ø×4Ò4ØØØñô ð ð ð ð ð ð ð õ ˜YÑ'Ô'ˆ	Ý˜jÑ)Ô)ˆ
ð Ø'0Ø!Ø)3ð		ð 	Ýð	å$ð	õ ð	õ �S¥#˜Xœð		õ
  ð	ð 	ð 	ð 	ð 	ð 	ð 	ðB #�]‘_”_Ð$Ð$Ð$Ð$Ð$Ð$Ð$rv   c              ƒ   ó¨   K  — |j         t          j        k    rt          t          j        d¬¦  «        S | j                             ||¦  «        ƒ d{V —†S )a+  Core permission resolution, wrapped by ``on_check_permission``.

        A call already allowed by user confirmation short-circuits to ALLOW;
        otherwise the built-in engine evaluates the tool and its input. See
        :meth:`_check_permission` for the argument and return semantics.
        z%Already allowed by user confirmation.)Úbehaviorr¶  N)re   rM   r  rX   rV   ÚALLOWr‡   Úcheck_permission)r�   r©  rÖ  rô  s       rt   rø  zAgent._check_permission_implí  sd   è è € ð Œ?�mÔ3Ò3Ð3Ý%Ý+Ô1Ø?ðñ ô ð ð ”\×2Ò2°4¸ÑDÔDÐDÐDÐDÐDÐDÐDÐDrv   c           	     óœ
  K  — 	 | j                              |j        | j        j        j        ¦  «        ƒ d{V —†}t          |j        |j        ¦  «        }	 t          j
        ||j        ¦  «         n7# t          j        $ r%}t          d|j        › d|j        › �¦  «        |‚d}~ww xY wnM# t          $ r@}|                      ||j        t          j        ¬¦  «        2 3 d{V —†}|W V — Œ6 Y d}~dS d}~ww xY w|                      |||¦  «        ƒ d{V —†}|j        t&          j        t&          j        fv rÌ|j        t&          j        k    o|j        }|�<|s:|D ]7}	|	j        |j        k    rŒt1          |j        |	j        |¦  «        ƒ d{V —†r dS Œ8|�|                     |j        pg ¦  «         |                      |j        t>          j         ¦  «         |j        pg |_        tC          | j        j"        |g¬¦  «        W V — dS |j        t&          j#        k    r7|                      ||j        t          j$        ¬¦  «        2 3 d{V —†}|W V — Œ6 dS |j        t&          j%        k    �rÙ|                      |j        t>          j&        ¦  «         tO          | j        j"        |j        |j        ¬¦  «        W V — |j(        rF|                      |j        t>          j)        ¦  «         tU          | j        j"        |g¬¦  «        W V — dS |  +                    |¦  «        2 3 d{V —†}
tY          |
tZ          ¦  «        �rÙt]          |j        |j        tY          |
j/        t`          ¦  «        rtc          |
j/        ¬¦  «        gn|
j/        |
j        |
j2        ¬¦  «        }|  3                    |¦  «        ƒ d{V —†\  }}|�ðd	}d
}| j4        r1| j4         5                    | j        j6        |¦  «        ƒ d{V —†}d|› d�}| 7                    |¬¦  «        }tY          |j8        t`          ¦  «        r|xj8        |z  c_8        nsts          |j8        ¦  «        dk    r<tY          |j8        d         tb          ¦  «        r|j8        d         xj:        |z  c_:        n|xj8        tc          |¬¦  «        gz  c_8        |  ;                    |g¦  «         |                      |j        t>          j<        ¦  «         t{          | j        j"        |j        |
j        |
j2        ¬¦  «        W V — �Œö|  >                    |j        |
j/        ¦  «        2 3 d{V —†}|W V — Œ6 �Œ&6 dS t          d|j        › �¦  «        ‚)aÀ  Execute a single tool call with permission checking and context
        management.

        This method handles the full tool call lifecycle: input validation,
        permission checking, event emission, and context writes.  The raw
        tool execution (``toolkit.call_tool``) is delegated to
        :meth:`_acting`, which is the hook point for ``on_acting``
        middleware.

        Args:
            tool_call (`ToolCallBlock`):
                The tool call block to be executed.
            kept_rules (`list[PermissionRule] | None`, defaults to `None`):
                A batch-scoped, shared accumulator of the suggested rules
                already surfaced by earlier confirmations in the same
                concurrent batch. Passed only by
                :meth:`_execute_concurrent_tool_calls`; when provided, a
                non-safety ASK whose invocation is already covered by an
                accumulated rule is de-duplicated (left ``PENDING`` and
                not surfaced again). ``None`` disables de-duplication
                (e.g. sequential execution, which already parks at the
                first ASK).

        Yields:
            `RequireUserConfirmEvent             | RequireExternalExecutionEvent             | ToolResultStartEvent             | ToolResultTextDeltaEvent             | ToolResultDataDeltaEvent             | ToolResultEndEvent`:
                The events generated during the tool call execution.
        Nz"Input validation failed for tool 'z': )re   )r  r*  r  ©rM  )r  r`   r  re   r¸  z�
<<<TRUNCATED>>>
<system-reminder>The remaining content has been omitted for limited context.{offload_reminder}</system-reminder>rÀ   z You can refer to the file in 'z&' for the truncated content if needed.)Úoffload_reminderr   r  r·  z&Invalid permission decision behavior: )@rc   Úcheck_tool_availabler`   re   Útool_contextÚactivated_groupsr   r¼  Úinput_schemaÚ
jsonschemaÚvalidateÚValidationErrorr=   r¶  r¿  rN   ÚERRORrú  rü  rV   ÚASKÚPASSTHROUGHÚbypass_immuneÚ	tool_namer   Ú
match_ruleÚrule_contentÚextendÚsuggested_rulesr»  r  rM   r¥  r2   r  ÚDENYrÀ  rý  r  r0   Úis_external_toolr  r3   Ú_actingrž   rU   rI   rÄ   r`  rF   r¸  Ú"_split_tool_result_for_compressionrf   Úoffload_tool_resultrÑ   rÏ   r  rº   rM  r—  r  r/   rÁ  r•   )r�   r©  rß  rÖ  Úparsed_inputrø   r@  ÚdecisionÚis_safety_askrÄ  rŸ   Útool_result_blockÚreserved_tool_result_blockÚoffload_tool_result_blockÚreminderr  r×   s                    rt   rØ  zAgent._execute_tool_call   s»  è è € ðd#	àœ×:Ò:Ø”Ø”
Ô'Ô8ñô ð ð ð ð ð ð ˆDõ 3Ø”ØÔ!ñô ˆLðÝÔ# L°$Ô2CÑDÔDÐDÐDøÝÔ-ð ð ð Ý,ð#¸¼ð #ð #Ø”yð#ð #ñô ð ðøøøøðøøøð Eøõ &ð 	ð 	ð 	Ø!×9Ò9ØØ”	Ý%Ô+ð :ñ ô ð ð ð ð ð ð ð �cð
 �	�	�	�	�	ðð ˆFˆFˆFˆFˆFøøøøð	øøøð ×/Ò/ØØØñ
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ˆð ÔÝÔ"ÝÔ*ð!
ð 
ð 
ð Ô!Õ%7Ô%;Ò;ð +ØÔ*ð ð Ð%¨mÐ%Ø&ð 
ð 
�DØ”~¨¬Ò2Ð2Ø Ý8ØœØÔ)Ø$ñô ð ð ð ð ð ð ð ð ˜˜ðð Ð%ð ×!Ò! (Ô":Ð"@¸bÑAÔAÐAð ×(Ò(Ø”ÝÔ$ñô ð ð
 )1Ô(@Ð(FÀBˆIÔ%Ý)ØœÔ,Ø%˜;ðñ ô ð ð ð ð ð ˆFð ÔÕ 2Ô 7Ò7Ð7Ø!×9Ò9ØØÔ Ý%Ô,ð :ñ ô ð ð ð ð ð ð ð �cð
 �	�	�	�	�	ðð ˆFð ÔÕ 2Ô 8Ò8Ñ8Ø×(Ò(Ø”ÝÔ%ñô ð õ
 'ØœÔ,Ø&œ\Ø(œ~ðñ ô ð ð ð ð ð Ô$ð ð
 ×,Ò,Ø”LÝ!Ô+ñô ð õ 4Ø!œZÔ0Ø )˜{ðñ ô ð ð ð ð ð �ð
  $Ÿ|š|¨IÑ6Ô6ð X"ð X"ð X"ð X"ð X"ð X"ð X"�eå˜e¥\Ñ2Ô2ñ V"Ý(7Ø$œ<Ø&œ^å% e¤mµSÑ9Ô9ð +¥	¨u¬}Ð =Ñ =Ô =Ð>Ð>à"œ]Ø#œkØ!&¤ð)ñ )ô )Ð%ð  #×EÒEØ)ñô ð ð ð ð ð ð ñØ2Ø1ð 1Ð<ð1ð !ð ,.Ð(Øœ>ð 	Ø)-¬×)KÒ)KØ $¤
Ô 5Ø 9ñ*ô *ð $ð $ð $ð $ð $ð $˜Dð!HÀ$ð !Hð !Hð !Hð -ð
 $,§?¢?Ø-=ð $3ñ $ô $˜õ
 &Ð&@Ô&GÍÑMÔMð Ø6Ð=Ô=ÀÑIÐ=Ô=Ð=å Ø6Ô=ñô àòð å",Ø6Ô=¸bÔAÝ%ñ#ô #ðð 7Ô=Ø "ôð #ä" hñ/à"œd˜dð 7Ð=Ô=Ý )¨xÐ 8Ñ 8Ô 8ðBñ Ð=Ô=ð ×)Ò)Ð+EÐ*FÑGÔGÐGà×0Ò0Ø!œÝ%Ô.ñô ð õ
 -Ø!%¤Ô!4Ø%.¤\Ø#œkØ!&¤ð	ñ ô ð ð ð ð ñ ð &*×%FÒ%FØ!œØœñ&ô &ð "ð "ð "ð "ð "ð "ð "˜cð "˜	˜	˜	˜	˜	ð	&ñ &ði  7ðt ˆFåØH°XÔ5FÐHÐHñ
ô 
ð 	
sZ   „AB' ÁA/ Á.B' Á/B#Á> BÂB#Â#B' Â'
C1Â1'C,ÃC%ÃC,Ã,C1È8IÌT4Ô$T1)zToolChunk | ToolResponseNc                óÔ   ‡ ‡K  — ‰ j         s%‰                      |¦  «        2 3 d{V —†}|W V — Œ6 dS d|fdt          dt          dt          fˆˆ fd„Š ‰¦   «         2 3 d{V —†}|W V — Œ6 dS )uÊ  Raw tool execution entry point (maybe wrapped by middleware).

        This method is the hook point for ``on_acting`` middleware.  It
        delegates to :meth:`_acting_impl` which wraps
        ``toolkit.call_tool`` directly.  Permission checking and context
        writes are **not** part of this method â€” they are handled by
        :meth:`_execute_tool_call` before and after this call.

        Args:
            tool_call (`ToolCallBlock`):
                The tool call block to execute.

        Yields:
            `ToolChunk | ToolResponse`:
                Intermediate :class:`~agentscope.tool.ToolChunk` objects
                followed by a final :class:`~agentscope.tool.ToolResponse`.
        Nr   r®   r©  rk   c                ó$  •‡ ‡K  — ‰ t          ‰j        ¦  «        k    r%‰                     |¦  «        2 3 d {V —†}|W V — Œ6 d S ‰j        ‰          }d|iŠdt          dt          fˆˆ ˆfd„}|                     ‰‰|¬¦  «        2 3 d {V —†}|W V — Œ6 d S )Nr©  r°   rk   c                 óH   •K  —  ‰‰dz   fi i ‰¥| ¥¤Ž2 3 d {V —†}|W V — Œ6 d S r²   r³   rþ   s     €€€rt   r·   z:Agent._acting.<locals>.execute_chain.<locals>.next_handlerE	  r…  r   r¸   )rº   r‹   Ú_acting_implr   r	   r}   )r®   r©  rÿ   r¼   r·   r¶   rµ   r�   s   `    @€€rt   rµ   z$Agent._acting.<locals>.execute_chain:	  s#  øøøè è € ð �C Ô 8Ñ9Ô9Ò9Ð9Ø&*×&7Ò&7¸	Ñ&BÔ&Bð #ð #ð #ð #ð #ð #ð #˜dØ"˜
˜
˜
˜
˜
ð 'CÐ&BÐ&Bð Ô1°%Ô8�BØ$/°Ð#;�Lð'µSð '½^ð 'ð 'ð 'ð 'ð 'ð 'ð 'ð 'ð ')§l¢lØ"Ø%1Ø%1ð '3ñ 'ô 'ð #ð #ð #ð #ð #ð #ð #˜dð
 #˜
˜
˜
˜
˜
ð'ð 'ð 's   ³A ÂB)r‹   r!  r½   rH   r	   )r�   r©  rÿ   rµ   s   `  @rt   r  zAgent._acting 	  só   øøè è € ð* Ô'ð 	Ø"×/Ò/°	Ñ:Ô:ð ð ð ð ð ð ð �dØ�
�
�
�
�
ð ;Ð:Ð:ð
 Ø+4ð#ð #Ýð#å(ð#õ  ð#ð #ð #ð #ð #ð #ð #ð2 ,˜m™oœoð ð ð ð ð ð ð �dØ�
�
�
�
�
ð .˜o˜os
   ¡.ÁA'c                óf   K  — | j                              || j        ¦  «        2 3 d{V —†}|W V — Œ6 dS )u¡  Core tool execution logic.

        Wraps :meth:`~agentscope.tool.Toolkit.call_tool` and yields its
        output unchanged.  Does **not** perform permission checking or
        write to the agent context â€” those responsibilities belong to
        :meth:`_execute_tool_call`.

        .. note::
            Tools with ``is_state_injected=True`` receive the live
            ``agent.state`` object.  Offloading such tools to a background
            task (via ``on_acting`` middleware) may cause concurrent state
            mutations.  TODO: block background offloading for
            state-injected tools.

        Args:
            tool_call (`ToolCallBlock`):
                The tool call block to execute.

        Yields:
            `ToolChunk | ToolResponse`:
                Intermediate :class:`~agentscope.tool.ToolChunk` objects
                followed by a final :class:`~agentscope.tool.ToolResponse`.
        N)rc   Ú	call_toolre   )r�   r©  rŸ   s      rt   r!  zAgent._acting_implV	  s]   è è € ð6  œ<×1Ò1°)¸T¼ZÑHÔHð 	ð 	ð 	ð 	ð 	ð 	ð 	�%ØˆKˆKˆKˆKˆKð IÐHÐHs   £0r¶  c                óì  K  — t          | j        j        |j        |j        ¬¦  «        W V — t          t          |¬¦  «        g|¬¦  «        }|                      t          |j        |j        ||¬¦  «        g¦  «         |  	                    |j        |j
        ¦  «        2 3 d{V —†}|W V — Œ6 t          | j        j        |j        |¬¦  «        W V — |                      |j        t          j        ¦  «         dS )a´  A quick handling for the non-streaming tool results, and ends the
        lifecycle of the tool call by updating its state to "finished".

        Args:
            tool_call (`ToolCallBlock`):
                The tool call block that has errors.
            message (`str`):
                The error message to be returned for the tool call.
            state (`ToolResultState`):
                The state of the tool result, such as "error" or "denied".

        Yields:
            `ToolResultStartEvent             | ToolResultTextDeltaEvent             | ToolResultDataDeltaEvent             | ToolResultEndEvent`:
                The events generated for the error tool call.
        r  r   )rÄ   re   r  Nr  )r0   re   r  r  r`   rS   rF   r—  rI   rÁ  rÄ   r/   r»  rM   r  )r�   r©  r¶  re   Úresultr@  s         rt   r¿  zAgent._handle_error_tool_callt	  sj  è è € õ> #Ø”ZÔ(Ø"œØ$œ>ð
ñ 
ô 
ð 	
ð 	
ð 	
ð 	
õ Ý GÐ,Ñ,Ô,Ð-Øð
ñ 
ô 
ˆð 	×ÒåØ ”|Ø"œØ"Øð	ñ ô ðñ		
ô 		
ð 		
ð ×:Ò:ØŒLØŒNñ
ô 
ð 	ð 	ð 	ð 	ð 	ð 	ð 	�#ð ˆIˆIˆIˆIˆIð	
õ !Ø”ZÔ(Ø"œØð
ñ 
ô 
ð 	
ð 	
ð 	
ð 	
ð 	×$Ò$ØŒLÝÔ"ñ	
ô 	
ð 	
ð 	
ð 	
s   ÂB*Úto_reserved_tokensrÁ   c              ƒ   ó´  K  — t          d|                      ¦   «         ƒ d{V —†¬¦  «        g}| j        j        r-|                     t          d| j        j        ¦  «        ¦  «         t          | j        j        ¦  «        dz
  }|dk    rH| j         	                    || j        j        |d…         z   |¦  «        ƒ d{V —†}||k    rn|dz  }|dk    °H|dk     rg t          | j        j        ¦  «        fS | j        j        d|…         }| j        j        |dz   d…         }| j        j        |         }t          |¦  «        }	t          |¦  «        }
t          |¦  «        }|                     ¦   «         }t          |¦  «        dz
  }|dk    rK||d…         |_        ||gz   |z   }| j         	                    ||¦  «        ƒ d{V —†}||k    rn|dz  }|dk    °K	 i }t          t          |¦  «        dz
  |d¦  «        D ]Z}||         }t          |t          ¦  «        r|||j        <   Œ*t          |t"          ¦  «        r|                     |j        d¦  «         Œ[|sn"t'          |                     ¦   «         ¦  «        }Œ£|d|dz   …         |	_        ||dz   d…         |
_        t          |	j        ¦  «        dk    r||	gz  }t          |
j        ¦  «        dk    r|
g|z   }||fS )	a¸  Split context into parts to compress and parts to keep recent.

        Args:
            to_reserved_tokens (`float`):
                The tokens to be reserved.
            tools (`list[dict]`):
                The tools JSON schemas used for token counting.

        Returns:
            `tuple[list[Msg], list[Msg]]`:
                The message objects to be compressed and reserved during
                context compression.
        rÂ   NrÃ   rÅ   r   r   Tr  )rD   rä   re   rÓ   rå   rE   rº   rÔ   rb   rß   r   r¹  rÄ   ré   rž   rI   r  rH   r  rm  r  )r�   r&  rÁ   Ú
system_msgÚ	msg_indexÚreserved_tokensrÙ   rÚ   Úboundary_msgÚboundary_msg_to_compressÚboundary_msg_to_reserveÚattempt_msgÚboundary_msg_contentÚblock_indexÚtry_reservedÚremain_result_idsrù   r  s                     rt   râ   z$Agent._split_context_for_compression¿	  sŸ  è è € õ* ˜8°4×3JÒ3JÑ3LÔ3LÐ-LÐ-LÐ-LÐ-LÐ-LÐ-LÐMÑMÔMð
ˆ
ð
 Œ:Ôð 	Ø×ÒÝ˜ ¤
Ô 2Ñ3Ô3ñô ð õ ˜œ
Ô*Ñ+Ô+¨aÑ/ˆ	Ø˜1Šnˆnà$(¤J×$;Ò$;Ø˜TœZÔ/°	°
°
Ô;Ñ;Øñ%ô %ð ð ð ð ð ð ˆOð
 Ð"4Ò4Ð4ØØ˜‰NˆIð ˜1Šnˆnð �qŠ=ˆ=Ø•x ¤
Ô 2Ñ3Ô3Ð3Ð3ð  œ:Ô-¨j¨y¨jÔ9ÐØœ*Ô,¨Y¸©]¨_¨_Ô=ˆØ”zÔ)¨)Ô4ˆõ $,¨LÑ#9Ô#9Ð Ý"*¨<Ñ"8Ô"8Ðå˜|Ñ,Ô,ˆà+×>Ò>Ñ@Ô@ÐÝÐ.Ñ/Ô/°!Ñ3ˆØ˜QÒÐØ"6°{°|°|Ô"DˆKÔà%¨¨Ñ5¸ÑGˆLØ$(¤J×$;Ò$;ØØñ%ô %ð ð ð ð ð ð ˆOð Ð!3Ò3Ð3ØØ˜1ÑˆKð ˜QÒÐð	:ð !#ÐÝÝÐ(Ñ)Ô)¨AÑ-ØØñô ð 	:ð 	:�ð
 -¨QÔ/�Ý˜e¥_Ñ5Ô5ð :Ø23Ð% e¤hÑ/Ð/Ý ¥}Ñ5Ô5ð :Ø%×)Ò)¨%¬(°DÑ9Ô9Ð9øð %ð Øõ Ð/×6Ò6Ñ8Ô8Ñ9Ô9ˆKð+	:ð0 ,@Øˆk˜A‰oÐô,
Ð Ô(ð +?Ø˜!‰OÐÐô+
ÐÔ'õ Ð'Ô/Ñ0Ô0°1Ò4Ð4ØÐ!9Ð :Ñ:ÐåÐ&Ô.Ñ/Ô/°!Ò3Ð3Ø6Ð7¸/ÑIˆOà Ð0Ð0rv   rÚ   c              ƒ   ó¸  K  — t          ¦   «         }|D ] }|                     d¦  «        D ]ˆ}t          |t          ¦  «        r|j        dk    sŒ#	 t          |j        ¦  «        }n# t          $ r Y ŒEw xY w|                     d¦  «        }t          |t          ¦  «        r| 
                    |¦  «         Œ‰Œ¡| j        j                             |¬¦  «        ƒ d{V —† dS )z=Clean Read caches not referenced by reserved Read tool calls.r©  ÚReadÚ	file_path)Úreserved_file_pathsN)r­  r¹  rž   rH   r`   r   r¼  rè   rá   r`  Úaddre   r  Úclean_file_cache)r�   rÚ   Úreserved_pathsry  r  rô  r5  s          rt   rÒ   z"Agent._clear_unreserved_read_cache/
  s#  è è € õ
 $'¡5¤5ˆØ"ð 	2ð 	2ˆCØ×/Ò/°Ñ<Ô<ð 2ð 2�å˜u¥mÑ4Ô4ðØ9>¼ÀvÒ9MÐ9MàðÝ!8¸¼Ñ!EÔ!E�J�JøÝ ð ð ð Ø�Hðøøøð 'ŸNšN¨;Ñ7Ô7�	Ý˜i­Ñ-Ô-ð 2Ø"×&Ò& yÑ1Ô1Ð1øð2ð ŒjÔ%×6Ò6Ø .ð 7ñ 
ô 
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
s   ÁA#Á#
A0Á/A0rÅ  c              ƒ   óœ  K  — | j                              t          | j        |j        ¬¦  «        gd¦  «        ƒ d{V —†}|| j        j        k    r|dfS t          |¦  «        }t          |j        t          ¦  «        rt          |j        ¬¦  «        g|_        d}t          t          |j        ¦  «        dz
  dd¦  «        D ]e}|j        d|…         |_        | j                              t          | j        |j        ¬¦  «        gd¦  «        ƒ d{V —†}|| j        j        k     r|} nŒfd„ |j        d|…         D ¦   «         }d„ |j        |dz   d…         D ¦   «         }|j        |         }	t          |	t          ¦  «        �rÝ|	j        }
| j                              t          | j        |¬¦  «        gd¦  «        ƒ d{V —†}| j                              t          | j        ||	gz   ¬¦  «        gd¦  «        ƒ d{V —†}||z
  }| j        j        |z
  }|dk    r|dk    rt          |
¦  «        nd}n"t          ||z  t          |
¦  «        z  ¦  «        }t          dt!          t          |
¦  «        |¦  «        ¦  «        }|
d|…         }|
|d…         }|rdt          |¦  «        dk    r(|d         j        d	k    r|d         xj        |z  c_        n)|                     t          ||	j        ¬
¦  «        ¦  «         |rjt          |¦  «        dk    r-|d         j        d	k    r||d         j        z   |d         _        nA|                     dt          ||	j        ¬
¦  «        ¦  «         n|                     d|	¦  «         t          |¦  «        dk    r|dfS t+          |j        |j        ||j        ¬¦  «        }t+          |j        |j        ||j        ¬¦  «        }||fS )aT  Split the tool result for compression.

        Args:
            tool_result (`ToolResultBlock`):
                The tool result block.

        Returns:
            `tuple[ToolResultBlock, ToolResultBlock | None]`:
                A tuple of the tool result blocks to reserved in context and
                to offload (if any).
        )rÄ   Nr   r   r   r  c                 ó,   — g | ]}t          |¦  «        ‘ŒS r³   r   ©rr   Úbs     rt   ru   z<Agent._split_tool_result_for_compression.<locals>.<listcomp>}
  s+   € ð !
ð !
ð !
Ø�H�Q‰KŒKð!
ð !
ð !
rv   c                 ó,   — g | ]}t          |¦  «        ‘ŒS r³   r   r<  s     rt   ru   z<Agent._split_tool_result_for_compression.<locals>.<listcomp>€
  s+   € ð  
ð  
ð  
Ø�H�Q‰KŒKð 
ð  
ð  
rv   rM  )rM  r  r  )rb   rß   rC   r`   r  rh   Útool_result_limitr   rž   r`  rF   ré   rº   rM  r½   rm  ÚminrÊ   rå   r  ÚinsertrI   re   )r�   rÅ  Ún_tokensÚcopied_tool_resultÚboundary_indexrù   Ú
cur_tokensÚreserved_blocksÚoffload_blocksÚboundary_blockÚtruncated_textÚcur_tokens_plusÚtoken_deltaÚremaining_token_budgetr*  Úreserved_textÚoffload_textÚreserved_tool_resultr  s                      rt   r  z(Agent._split_tool_result_for_compressionI
  s	  è è € ð œ×0Ò0Ý˜$œ)¨[Ô-?Ð@Ñ@Ô@ÐAØñ
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ˆð �tÔ*Ô<Ò<Ð<Ø Ð$Ð$õ & kÑ2Ô2Ðõ Ð(Ô/µÑ5Ô5ð 	åÐ1Ô8Ð9Ñ9Ô9ð)ÐÔ%ð
 ˆÝ•sÐ-Ô4Ñ5Ô5¸Ñ9¸1¸bÑAÔAð 	ð 	ˆAØ(3Ô(:¸2¸A¸2Ô(>ÐÔ%Ø#œz×6Ò6å Øœ	Ø 2Ô 9ðñ ô ðð ñ ô  ð ð ð ð ð ð ˆJð ˜DÔ/ÔAÒAÐAØ!"�Ø�ð Bð!
ð !
Ø!,Ô!3°O°^°OÔ!Dð!
ñ !
ô !
ˆð 
ð  
Ø!,Ô!3°NÀQÑ4FÐ4HÐ4HÔ!Ið 
ñ  
ô  
ˆð
 %Ô+¨NÔ;ˆÝ�n¥iÑ0Ô0ñ B	5à+Ô0ˆNØ#œz×6Ò6Ý˜dœi°ÐAÑAÔAÐBØñ ô  ð ð ð ð ð ð ˆJð %)¤J×$;Ò$;å Øœ	Ø /°>Ð2BÑ Bðñ ô ðð ñ%ô %ð ð ð ð ð ð ˆOð *¨JÑ6ˆKàÔ#Ô5¸
ÑBð #ð ˜aÒÐà+AÀAÒ+EÐ+E•C˜Ñ'Ô'Ð'È1ð  �õ #&Ø*¨[Ñ8½3¸~Ñ;NÔ;NÑNñ#ô #�õ "ØÝ•C˜Ñ'Ô'¨Ñ9Ô9ñô ˆOð
 +Ð+;¨OÐ+;Ô<ˆMØ)¨/Ð*:Ð*:Ô;ˆLàð 
å˜Ñ(Ô(¨1Ò,Ð,Ø'¨Ô+Ô0°FÒ:Ð:à# BÔ'Ð,Ô,°Ñ=Ð,Ô,Ð,ð $×*Ò*Ý! }¸Ô9JÐKÑKÔKñô ð ð ð å˜Ñ'Ô'¨!Ò+Ð+Ø& qÔ)Ô.°&Ò8Ð8ð % ~°aÔ'8Ô'=Ñ=ð # 1Ô%Ô*Ð*ð
 #×)Ò)ØÝ! |¸Ô8IÐJÑJÔJñô ð øð ×!Ò! ! ^Ñ4Ô4Ð4åˆ~ÑÔ !Ò#Ð#Ø Ð$Ð$õ  /ØŒ~ØÔ!Ø"ØÔ#ð	 
ñ  
ô  
Ðõ .ØŒ~ØÔ!Ø!ØÔ#ð	
ñ 
ô 
Ðð $Ð%8Ð8Ð8rv   c              ƒ   ó¼  K  — | j         g}| j                             | j        j        j        ¦  «        ƒ d{V —†}|r|                     |¦  «         t          | j        t          ¦  «        r6| j         
                    ¦   «         ƒ d{V —†}|r|                     |¦  «         d                     |¦  «        }| j        D ]}|                     | |¦  «        ƒ d{V —†}Œ|S )z#Get the system prompt of the agent.NrR  )r„   rc   Úget_skill_instructionsre   r  r  rå   rž   rf   r\   Úget_instructionsra  r�   r�   )r�   ÚpromptÚskill_instructionsÚoffload_instructionsr%  r¼   s         rt   rä   zAgent._get_system_promptà
  s  è è € àÔ%Ð&ˆð $(¤<×#FÒ#FØŒJÔ#Ô4ñ$
ô $
ð 
ð 
ð 
ð 
ð 
ð 
Ðð ð 	.Ø�MŠMÐ,Ñ-Ô-Ð-õ �d”n¥mÑ4Ô4ð 	4Ø)-¬×)HÒ)HÑ)JÔ)JÐ#JÐ#JÐ#JÐ#JÐ#JÐ#JÐ Ø#ð 4Ø—’Ð2Ñ3Ô3Ð3à—’˜6Ñ"Ô"ˆð Ô1ð 	=ð 	=ˆBØ×.Ò.¨t°VÑ<Ô<Ð<Ð<Ð<Ð<Ð<Ð<ˆFˆFàˆrv   c              ƒ   ót  K  — t          d|                      ¦   «         ƒ d{V —†¬¦  «        g}| j        j        r.|                     t          d| j        j        ¬¦  «        ¦  «         |                     | j        j        ¦  «         | j         	                    | j        j
        j        ¦  «        ƒ d{V —†}||dœS )zÍA unified method to prepare the chat model input according to
        the current context.

        Returns:
            `dict[str, Any]`
                The keyword arguments passed to the model.
        rÂ   NrÃ   rÅ   )rË   rÁ   )rD   rä   re   rÓ   rå   rE   r  rÔ   rc   Úget_tool_schemasr  r  )r�   rË   rÁ   s      rt   rÞ   zAgent._prepare_model_inputù
  sé   è è € õ ˜8°4×3JÒ3JÑ3LÔ3LÐ-LÐ-LÐ-LÐ-LÐ-LÐ-LÐMÑMÔMð
ˆð Œ:Ôð 	Ø�OŠOÝ˜V¨T¬ZÔ-?Ð@Ñ@Ô@ñô ð ð 	�Š˜œ
Ô*Ñ+Ô+Ð+ð ”l×3Ò3ØŒJÔ#Ô4ñ
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ˆð
 !Øð
ð 
ð 	
rv   rË   c              ƒ   ó„  ‡ ‡
K  — ‰ j         g}‰ j        j        r|                     ‰ j        j        ¦  «         d}t	          |¦  «        D �]c\  }}|dk    rt          j        d|j         ¦  «         t          ‰ j        j        dz   ¦  «        D �]}	 ‰ j	        s ||||¬¦  «        ƒ d{V —†c c S d||||fdt          dt          dt          t                   d	t          t                   d
t          dt           t"          t           df         z  fˆ
ˆ fd„Š
 ‰
¦   «         ƒ d{V —†c c S # t$          $ r{}	|	}|‰ j        j        k     r0t          j        d|j         ‰ j        |dz   ‰ j        j        ¦  «         n.t          j        d|j         ‰ j        j        dz   ‰ j        ¦  «         Y d}	~	�Œd}	~	ww xY w�Œe|r|d‚t+          d¦  «        ‚)a’  Perform model inference with retry logic and middleware support.

        Args:
            messages (`list[Msg]`):
                The input messages to the model.
            tools (`list[dict]`):
                The function schemas of the tools.
            tool_choice (`ToolChoice | None`, optional):
                The tool choice strategy for the model call.

        Returns:
            `ChatResponse | AsyncGenerator[ChatResponse, None]`:
                The model response, which can be a `ChatResponse` for
                non-streaming models, or an async generator yielding
                `ChatResponse` chunks for streaming models.
        Nr   zFallback to model '%s'r   ©rË   rÁ   r'  r®   Úcurrent_modelrË   rÁ   r'  rk   c              “   ó  •‡ ‡K  — ‰ t          ‰	j        ¦  «        k    r ||||¬¦  «        ƒ d{V —†S ‰	j        ‰          }||||dœŠdt          dt          t          t          df         z  fˆˆ ˆfd„}|                     ‰	‰|¬¦  «        ƒ d{V —†S )zExecute the model chain.rY  N)rZ  rË   rÁ   r'  r°   rk   c               ›   ó4   •K  —  ‰‰dz   fi i ‰¥| ¥¤Žƒ d {V —†S r²   r³   r´   s    €€€rt   r·   z>Agent._call_model.<locals>.execute_chain.<locals>.next_handlera  sY   øè è € ð 2?°Ø(-°©	ð2&ð 2&à*D¨\Ð*D¸VÐ*Dð2&ð 2&ð ,&ð ,&ð ,&ð ,&ð ,&ð ,&ð %&rv   r¸   )rº   rŒ   r   r>   r	   r   )
r®   rZ  rË   rÁ   r'  r¼   r·   r¶   rµ   r�   s
   `      @€€rt   rµ   z(Agent._call_model.<locals>.execute_chainJ  s  øøøè è € ð  %­¨DÔ,HÑ(IÔ(IÒIÐIØ-:¨]Ø-5Ø*/Ø0;ð."ñ ."ô ."ð ("ð ("ð ("ð ("ð ("ð ("ð !"ð &*Ô%AÀ%Ô%H à5BØ08Ø-2Ø3>ð	0"ð 0" ð
!&Ý.1ð
!&õ %1Ý&4µ\À4Ð5GÔ&Hñ%Ið
!&ð 
!&ð 
!&ð 
!&ð 
!&ð 
!&ð 
!&ð 
!&ð .0×-=Ò-=Ø*.Ø1=Ø1=ð .>ñ ."ô ."ð ("ð ("ð ("ð ("ð ("ð ("ð !"rv   z6Model %s call failed for agent %s. Retrying (%d/%d)...z2Model %s exhausted all %d attempt(s) for agent %s.z=Model call failed after retries, but no exception was raised.)rb   rg   Úfallback_modelrå   r  r   rÕ   ré   Úmax_retriesrŒ   r½   r@   r  rB   rù  rT   r>   r	   rè   rã   r`   r¢   )r�   rË   rÁ   r'  ÚmodelsÚlast_exceptionr®   rb   Úattemptrø   rµ   s   `         @rt   r’  zAgent._call_model  sš  øøè è € ð, ”*�ˆð ÔÔ+ð 	<Ø�MŠM˜$Ô+Ô:Ñ;Ô;Ð;àˆõ & fÑ-Ô-ð R	ñ R	‰LˆE�5Ø�qŠyˆyÝ”Ø,Ø”Kñô ð õ
 ! Ô!2Ô!>ÀÑ!BÑCÔCð Kñ K�ðJàÔ7ð 15Ø%* UØ%-Ø"'Ø(3ð&ñ &ô &ð  ð  ð  ð  ð  ð  ð ð ð ð ð ð *+Ø;@Ø2:Ø05Ø6Að'"ð '"Ý#&ð'"å+8ð'"õ '+­3¤ið'"õ $(­¤:ð	'"õ
 *4ð'"õ *­N½<ÈÐ;MÔ,NÑNð'"ð '"ð '"ð '"ð '"ð '"ð '"ðR &3 ]¡_¤_Ð4Ð4Ð4Ð4Ð4Ð4Ð4Ð4Ð4Ð4Ð4øÝ ð ð ð Ø%&�Nð
  Ô!2Ô!>Ò>Ð>Ýœð2à!œKØ œIØ# a™KØ Ô-Ô9ñô ð ð õ œð,à!œKØ Ô-Ô9¸AÑ=Ø œIñô ð øøøøùøøøøð!øøøñkKðZ ð 	+Ø  dÐ*åØKñ
ô 
ð 	
s    ÂD$Â.A1D$Ä$
F)Ä.A0F$Æ$F)r  c                 ó$  — t          | j        j        ¦  «        dk    rdS | j        j        d         }|j        dk    s|j        | j        k    rdS |                     ¦   «         D ],}t          |t          ¦  «        r|j        |k    r
||_         dS Œ-dS )aq  Update the tool call state. This function is to avoid the update
        not reflected in the context due to the shallow copy of the content
        blocks somewhere in the code.

        Args:
            tool_call_id (`str`):
                The tool call id to be updated.
            state (`ToolCallState`):
                The new state of the tool call.
        r   Nr  r  )	rº   re   rÔ   r  r`   r¹  rž   rH   r  )r�   r  re   r  r  s        rt   r»  zAgent._update_tool_call_state“  s¢   € õ ˆtŒzÔ!Ñ"Ô" aÒ'Ð'ØˆFØ”:Ô% bÔ)ˆØŒ=˜KÒ'Ð'¨8¬=¸D¼IÒ+EÐ+EØˆFØ×0Ò0Ñ2Ô2ð 	ð 	ˆEÝ˜%¥Ñ/Ô/ð °E´HÀÒ4LÐ4LØ#�”Ø��øð	ð 	rv   Úblocksr‘  c                 ó\  — |�t          |j        |j        ¬¦  «        nd}d„ |D ¦   «         }|s|€dS | j                             | j        |¦  «         | j        j        d         }|�F|j        €	||_        dS |j        xj        |j        z  c_        |j        xj        |j        z  c_        dS dS )a  Save content blocks into the context.

        Newly created :class:`AssistantMsg` uses ``self.state.reply_id`` as
        its id so that one reply corresponds to one message and the message
        id matches the ``reply_id`` carried by streaming events.
        Nr�  c                 ó¼   — g | ]Y}t          |t          ¦  «        r@t          |j        t          t          f¦  «        r|j        j                             d ¦  «        °W|‘ŒZS )zaudio/)rž   rJ   rX  rK   rL   rÈ  Ú
startswithr<  s     rt   ru   z*Agent._save_to_context.<locals>.<listcomp>Ë  sp   € ð 
ð 
ð 
àå˜1�iÑ(Ô(ð	
õ
 ˜qœx­,½	Ð)BÑCÔCð
ð ”HÔ'×2Ò2°8Ñ<Ô<ð
Øð
ð 
ð 
rv   r  )rO   r  r�  re   r4  r`   rÔ   r‘  )r�   rc  r‘  Ú	msg_usageÚpersisted_blocksÚtails         rt   r—  zAgent._save_to_context¬  sï   € ð, Ð õ	 Ø"Ô/Ø#Ô1ðñ ô ð ð
 ð 	ð
ð 
àð
ñ 
ô 
Ðð  ð 	 IÐ$5ØˆFàŒ
×!Ò! $¤)Ð-=Ñ>Ô>Ð>àŒzÔ! "Ô%ˆØÐ ØŒzÐ!Ø&�”
�
�
à”
Ð'Ô'¨9Ô+AÑAÐ'Ô'Ø”
Ð(Ô(¨IÔ,CÑCÐ(Ô(Ð(Ð(ð !Ð rv   c                 ó¢   — t          | j        j        ¦  «        dk    rdS | j        j        d         }|j        dk    r|j        | j        k    r|S dS )z?Get the last message in the context that belongs to this agent.r   Nr  r  )rº   re   rÔ   r  r`   )r�   r  s     rt   r›  zAgent._get_last_msgá  sS   € åˆtŒzÔ!Ñ"Ô" aÒ'Ð'Ø�4Ø”:Ô% bÔ)ˆØŒ=˜KÒ'Ð'¨H¬M¸T¼YÒ,FÐ,FØˆOØˆtrv   r£   c                 ól  ‡‡	— | j                              | j        ¦  «        Š|                      ¦   «         }|�Sd„ |                     d¦  «        D ¦   «         Š	ˆˆ	fd„|                     d¦  «        D ¦   «         }|rt          |¬¦  «        S ‰r0t          dt          | j         j        | j        d¬¦  «        ¬	¦  «        S | j         j	        j
        du}| j         j	        j        du}|r‰|r‡t          t          | j         j        | j         j        t          j        ¬
¦  «        gt          | j         j        | j        dt          j        t!          | j         j	        j        ¦  «        ¬¦  «        ¬	¦  «        S |�r-|�s*d}d}| j         j        | j        j        | j        j        z   k    r‰t          t+          | j         j        | j        ¬¦  «        t          | j         j        | j         j        t          j        ¬
¦  «        gt          | j         j        | j        dt          j        ¬¦  «        ¬	¦  «        S | j         j        | j        j        k    rt/          t0          j        ¬¦  «        }d}t3          t5          t7          dt0          j        › d|› d�¬¦  «        gd¬¦  «        |¬¦  «        S |�@t          t          | j         j        | j         j        t          j        ¬
¦  «        g|¬	¦  «        S | j         j        | j        j        k    r®t9          j        d| j        | j        j        ¦  «         t          t+          | j         j        | j        ¬¦  «        t          | j         j        | j         j        t          j        ¬
¦  «        gt          | j         j        | j        dt          j        ¬¦  «        ¬	¦  «        S t3          ¦   «         S )zDecide the next action from the current state. Read-only: all
        side effects are performed by the caller ``_reply_impl``.Nc                 ó   — h | ]	}|j         ’Œ
S r³   r«  rq   s     rt   ú	<setcomp>z%Agent._next_action.<locals>.<setcomp>ù  s'   € ð ð ð Ø�”ðð ð rv   rÅ  c                 ó~   •— g | ]9}|j         ‰vr.|j        t          j        k    s|j        t          j        k    ¯5‰°7|‘Œ:S r³   )r  re   rM   r  ÚPENDING)rr   rs   r  Úfinished_idss     €€rt   ru   z&Agent._next_action.<locals>.<listcomp>þ  sZ   ø€ ð %ð %ð %àØ”4˜|Ð+Ð+à”G�}Ô4Ò4Ð4àœ¥=Ô#8Ò8Ð8Ø 3ð 9ð ð 9Ð8Ð8rv   r©  r)  zDI'm waiting for your permission or the external execution to finish.)r  r`   rÄ   )r$  r#  r  z,The required structured output is generated.)r  r`   rÄ   rê   r!  zCCall it when you are ready to generate the final structured output.)r  r`   z5The maximum reasoning-acting iterations are exceeded.r  )Úmodez|You have reached the maximum reasoning-acting iterations, so call this tool at once to generate the final structured output.zO<system-reminder>You're required to generate structured output by calling the 'z' tool. z</system-reminder>r   z@{"label": "System", "sublabel": "Structured Output Requirement"})r&  rX  r%  zCAgent %s exceeds the max iteration numbers %d. Stop the react loop.)re   r¬  r`   r›  r¹  r   r   rC   r  r0  r™   r!  r#   rÑ   r:   rœ  r   r   ri   Ú	max_itersÚstructured_output_grace_itersr9   ÚEXCEED_MAX_ITERSrT   rZ   r   rP   rF   r   rã   )
r�   r£   r  Úexecutable_tool_callsÚrequiredÚ	satisfiedr'  rò   r  rp  s
           @@rt   r3  zAgent._next_actionê  s„  øø€ ð #œj×@Ò@ÀÄÑKÔKÐà×%Ò%Ñ'Ô'ˆØÐðð Ø&×9Ò9¸-ÑHÔHðñ ô ˆLð
%ð %ð %ð %ð %à!×4Ò4°[ÑAÔAð%ñ %ô %Ð!ð %ð @åÐ)>Ð?Ñ?Ô?Ð?àð 	åà Ý%Ø”zÔ*Øœð4ð	ñ ô ð
ñ 
ô 
ð 
ð" ”:Ô+Ô=ÀTÐIˆØ”JÔ,Ô>ÀdÐJˆ	àð X	˜	ð X	åå!Ø#'¤:Ô#8Ø!%¤Ô!4Ý(;Ô(Eðñ ô ðõ &Ø”zÔ*ØœØJÝ$7Ô$AÝ&.Øœ
Ô0ÔBñ'ô 'ðñ ô ðñ ô ð ð& ñ C	˜iñ C	ð ˆKð%ð ð ”
Ô#ØÔ$Ô.ØÔ#ÔAñBòBð Bõ å+Ø%)¤ZÔ%8Ø!%¤ðñ ô õ &Ø'+¤zÔ'<Ø%)¤ZÔ%8å 3Ô Dð	ñ ô ð!õ *Øœ:Ô.Ø!œYð!(å(;Ô(Lðñ ô ðñ ô ð ð. ŒzÔ" dÔ&7Ô&AÒAÐAõ )Ý2Ô7ðñ ô �ð3ð õ Ýå!ð!>å$=Ô$Bð!>ð !>ð $*ð!>ð !>ð !>ðñ ô ð	ð7ðñ ô ð (ðñ ô ð ð. Ð Ýå!Ø#'¤:Ô#8Ø!%¤Ô!4Ý(;Ô(Eðñ ô ðð #ð	ñ 	ô 	ð 	ð Œ:Ô $Ô"3Ô"=Ò=Ð=ÝŒNð'à”	ØÔ!Ô+ñ	ô ð õ å'Ø!%¤Ô!4Ø!œYðñ ô õ "Ø#'¤:Ô#8Ø!%¤Ô!4Ý(;Ô(Lðñ ô ð
õ &Ø”zÔ*Øœð å$7Ô$Hðñ ô ðñ ô ð õ, ‰{Œ{Ðrv   r�  rŸ   c                ó  K  — g g g }}}g }|j         D ]­}t          |t          ¦  «        r|                     |¦  «         Œ-t          |t          ¦  «        r|                     |¦  «         ŒXt          |t
          ¦  «        r|                     |¦  «         Œƒt          |t          ¦  «        r|                     |¦  «         Œ®|r�|                     d¦  «        s5t          ¦   «         |d<   t          | j
        j        |d         ¬¦  «        W V — t          | j
        j        |d         d                     d„ |D ¦   «         ¦  «        ¬¦  «        W V — n@|                     d¦  «        r+|s)t          | j
        j        |d         ¬¦  «        W V — d|d<   |r�|                     d¦  «        s5t          ¦   «         |d<   t          | j
        j        |d         ¬¦  «        W V — t!          | j
        j        |d         d                     d„ |D ¦   «         ¦  «        ¬¦  «        W V — n@|                     d¦  «        r+|s)t#          | j
        j        |d         ¬¦  «        W V — d|d<   |D ]ƒ}|j        |d	         vrI|d	                              |j        ¦  «         t'          | j
        j        |j        |j        ¬
¦  «        W V — t+          | j
        j        |j        |j        ¬¦  «        W V — Œ„t/          |d	         ¦  «        t/          d„ |D ¦   «         ¦  «        z
  }	|	D ];}
t1          | j
        j        |
¬¦  «        W V — |d	                              |
¦  «         Œ<|D ]³}t          |j        t6          ¦  «        sŒ|j        |d         vrN|d                              |j        ¦  «         t9          | j
        j        |j        |j        j        ¬¦  «        W V — t=          | j
        j        |j        |j        j        |j        j        ¬¦  «        W V — Œ´dS )a“  Convert a ChatResponse chunk into a sequence of agent events. To
        keep the identifiers of the content blocks reasonable, the input
        blocks_ids is used to track the block ids.

        Args:
            block_ids (`dict`):
                The block ids used to track the block generation.
            chunk (`ChatResponse`):
                The chat response chunk to be converted.
        r‰  r‹  rÀ   c                 ó   — g | ]	}|j         ‘Œ
S r³   )r‰  rq   s     rt   ru   z9Agent._convert_chat_response_to_event.<locals>.<listcomp>Ý  s   € ÐCÐCÐC¨a˜qœzÐCÐCÐCrv   )r  rY  r  NrM  c                 ó   — g | ]	}|j         ‘Œ
S r³   r   rq   s     rt   ru   z9Agent._convert_chat_response_to_event.<locals>.<listcomp>ô  s   € Ð;Ð;Ð;¨!˜qœvÐ;Ð;Ð;rv   rÁ   r  r
  c              3   ó$   K  — | ]}|j         V — Œd S rL  r«  rq   s     rt   rN  z8Agent._convert_chat_response_to_event.<locals>.<genexpr>  s5   è è € ð 5
ð 5
ØˆAŒDð5
ð 5
ð 5
ð 5
ð 5
ð 5
rv   rŒ  rŠ  )r  rY  rÈ  )r  rY  rŠ  rÈ  ) rÄ   rž   rF   rå   rG   rH   rJ   rá   r   r*   re   r  r(   ra  r)   r'   r%   r&   r  r-   r`   r+   r¼  r­  r,   ÚremoverX  rK   r6   rÈ  r7   rŠ  )r�   r�  rŸ   Útext_blocksÚthinking_blocksÚtool_call_blocksÚdata_blocksr  r©  rp  Úfinished_idÚ
data_blocks               rt   r–  z%Agent._convert_chat_response_to_event¯  sF  è è € ð" :<¸RÀÐ&6�_ˆØˆØ”]ð 	*ð 	*ˆEÝ˜%¥Ñ+Ô+ð *Ø×"Ò" 5Ñ)Ô)Ð)Ð)Ý˜E¥=Ñ1Ô1ð *Ø×&Ò& uÑ-Ô-Ð-Ð-Ý˜E¥=Ñ1Ô1ð *Ø ×'Ò'¨Ñ.Ô.Ð.Ð.Ý˜E¥9Ñ-Ô-ð *Ø×"Ò" 5Ñ)Ô)Ð)øð ð 	)à—=’= Ñ,Ô,ð Ý(4©¬�	˜*Ñ%Ý-Ø!œZÔ0Ø& zÔ2ðñ ô ð ð ð ð õ
 *ØœÔ,Ø" :Ô.Ø—g’gÐCÐC°?ÐCÑCÔCÑDÔDðñ ô ð ð ð ð ð ð �]Š]˜:Ñ&Ô&ð 	)¨{ð 	)Ý'ØœÔ,Ø" :Ô.ðñ ô ð ð ð ð ð %)ˆI�jÑ!ð
 ð 	%Ø—=’= Ñ(Ô(ð Ý$0¡N¤N�	˜&Ñ!Ý)Ø!œZÔ0Ø& vÔ.ðñ ô ð ð ð ð õ &ØœÔ,Ø" 6Ô*Ø—g’gÐ;Ð;¨{Ð;Ñ;Ô;Ñ<Ô<ðñ ô ð ð ð ð ð ð
 �]Š]˜6Ñ"Ô"ð 	%¨;ð 	%Ý#ØœÔ,Ø" 6Ô*ðñ ô ð ð ð ð ð !%ˆI�fÑð *ð 	ð 	ˆIàŒ| 9¨WÔ#5Ð5Ð5Ø˜'Ô"×)Ò)¨)¬,Ñ7Ô7Ð7Ý(Ø!œZÔ0Ø!*¤Ø#,¤>ðñ ô ð ð ð ð õ
 %ØœÔ,Ø&œ\Ø”oðñ ô ð ð ð ð ð õ ˜9 WÔ-Ñ.Ô.µð 5
ð 5
Ø*ð5
ñ 5
ô 5
ñ 2
ô 2
ñ 
ˆð (ð 	3ð 	3ˆKÝ"ØœÔ,Ø(ðñ ô ð ð ð ð ð �gÔ×%Ò% kÑ2Ô2Ð2Ð2ð &ð 	ð 	ˆJÝ˜jÔ/µÑ>Ô>ð ð ØŒ} I¨fÔ$5Ð5Ð5Ø˜&Ô!×(Ò(¨¬Ñ7Ô7Ð7Ý)Ø!œZÔ0Ø'œ]Ø)Ô0Ô;ðñ ô ð ð ð ð õ
 &ØœÔ,Ø#œØÔ&Ô+Ø%Ô,Ô7ð	ñ ô ð ð ð ð ð ð	ð 	rv   Úoutput_blocksc           	     ór  K  — t          |t          ¦  «        r!t          | j        j        ||¬¦  «        W V — dS |D ]û}t          |t
          ¦  «        r%t          | j        j        ||j        ¬¦  «        W V — Œ<t          |t          ¦  «        rªt          |j        t          ¦  «        r5t          | j        j        ||j        j        |j        j        ¬¦  «        W V — Œ t          |j        t          ¦  «        rAt          | j        j        ||j        j        t          |j        j        ¦  «        ¬¦  «        W V — ŒüdS )z4Convert a ToolChunk into a sequence of agent events.r
  N)r  r  rÈ  rŠ  )r  r  rÈ  rÍ  )rž   r`  r1   re   r  rF   rM  rJ   rX  rK   r.   rÈ  rŠ  rL   rÍ  )r�   r  rƒ  r  s       rt   rÁ  z"Agent._convert_tool_chunk_to_event0  s‰  è è € õ �m¥SÑ)Ô)ð 	Ý*ØœÔ,Ø)Ø#ðñ ô ð ð ð ð ð
 ˆFà"ð 	ð 	ˆEÝ˜%¥Ñ+Ô+ð Ý.Ø!œZÔ0Ø!-Øœ*ðñ ô ð ð ð ð ð õ ˜E¥9Ñ-Ô-ð Ý˜eœl­LÑ9Ô9ð Ý2Ø!%¤Ô!4Ø%1Ø#(¤<Ô#:Ø"œ\Ô.ð	ñ ô ð ð ð ð ð õ   ¤­iÑ8Ô8ð Ý2Ø!%¤Ô!4Ø%1Ø#(¤<Ô#:Ý ¤Ô 0Ñ1Ô1ð	ñ ô ð ð ð ð øð#	ð 	rv   )NNNNNNNNrÝ   )NNF)NNrL  )kÚ__name__Ú
__module__Ú__qualname__Ú__doc__r`  r@   rQ   r  r]   r   r[   r   r   r   r   r�   r…   rB   r5   r;   r4   r   r   r˜  r	   r    r    r¥   r©   rP   r¾   r»   r�   r0   r1   r/   r  r  r<   r5  rT   r"   r'   r%   r&   rH   r+   r,   r*   r(   r)   r6   r7   r8   r!   r6  r†  r.  r.   r/  r¨   r   r7  r2   r3   r8  r9  r   rY   rÝ  rR   rù  r   rX   rú  rø  rØ  r  r!  rN   r¿  ÚfloatÚtuplerâ   rÒ   rI   r  rä   rÞ   r>   r’  rM   r»  r
   rF   rG   rJ   r?   r—  r›  r   r   r   r3  r–  r   rÁ  r³   rv   rt   r_   r_   o   s	  € € € € € ØÐð #'Ø37Ø#'Ø&*à+/Ø/3Ø+/Ø37ðb
ð b
àðb
ð ðb
ð ð	b
ð
 ˜4‘ðb
ð ˜.Ô)¨DÑ0ðb
ð ˜DÑ ðb
ð ˜tÑ#ðb
ð " DÑ(ðb
ð &¨Ñ,ðb
ð " DÑ(ðb
ð *¨DÑ0ðb
ð 
ðb
ð b
ð b
ð b
ðHð ð ð ðX Ø48Ø %ð*ð *àØ
ˆsŒ)ñà
 ñ!ð ñð 'ñ	'ð
 ñð*ð   	œ?¨TÑ1ð*ð ð*ð 
˜
 SÑ(¨$Ð.Ô	/ð*ð *ð *ð *ðf Ø48ð/ð /àØ
ˆsŒ)ñà
 ñ!ð ñð 'ñ	'ð
 ñð/ð   	œ?¨TÑ1ð/ð 
ð/ð /ð /ð /ðb3ð 3 #¨¨S¬	¡/°DÑ"8ð 3ÀDð 3ð 3ð 3ð 3ð 04Ø)-ð6"ð 6"à%¨Ñ,ð6"ð   $Ñ&ð6"ð 
ð	6"ð 6"ð 6"ð 6"ðt 04Ø)-ð^ð ^à%¨Ñ,ð^ð   $Ñ&ð^ð 
ð	^ð ^ð ^ð ^ðV Ø48ð;ð ;àØ
ˆsŒ)ñà
 ñ!ð ñð 'ñ	'ð
 ñð;ð   	œ?¨TÑ1ð;ð 
˜
 SÑ(¨$Ð.Ô	/ð;ð ;ð ;ð ;ðz?à	ØÐ7Ñ7Ð:LÑLØð	ô
ð?ð ?ð ?ð ?ðP Ø48ð}ð }àØ
ˆsŒ)ñà
 ñ!ð ñð 'ñ	'ð
 ñð}ð   	œ?¨TÑ1ð}ð 
˜
 SÑ(¨$Ð.Ô	/ð}ð }ð }ð }ð~qà	˜¨Ð,Ô	-ðqð qð qð qðj *.ð7ð 7à $Ñ&ð7ð 
ØØ
ñ	à
ñ	ð ñ	ð ñ		ð
 ñ	ð ñ	ð "ñ	"ð "ñ	"ð  ñ		 ð ñ
	ð ñ	ð ñ	ð ñ	ð ñ	ð 	ð	ô
ð7ð 7ð 7ð 7ðv *.ðWð Wà $Ñ&ðWð 
ØØ
ñ	à
ñ	ð ñ	ð ñ		ð
 ñ	ð ñ	ð "ñ	"ð "ñ	"ð  ñ		 ð ñ
	ð ñ	ð ñ	ð ñ	ð ñ	ð 	ð	ô
ðWð Wð Wð WðrQ!à%Ð(DÑDÀtÑKðQ!ð 
ðQ!ð Q!ð Q!ð Q!ðfd=à%Ð(DÑDÀtÑKðd=ð 
ØØ
"ñ	#à
"ñ	#ð ñ	ð 	ð		ô
ðd=ð d=ð d=ð d=ðL;/à�D˜”I‰o Ñ$ð;/ð 
ð;/ð ;/ð ;/ð ;/ðz&à˜Ô'ð&ð 
ˆnÔ	ð&ð &ð &ð &ðP0à˜Ô'ð0ð 
ØØ
'ñ	(à
ñ	ð #ñ	#ð #ñ		#ð
 ñ	ð 	ð	ô
ð0ð 0ð 0ð 0ðdBà˜Ô'ðBð 
ØØ
'ñ	(à
ñ	ð #ñ	#ð #ñ		#ð
 ñ	ð 	ð	ô
ðBð Bð Bð BðP 37ð	!ð !à ð!ð ð!ð ˜Ô(¨4Ñ/ð	!ð
 
ð!ð !ð !ð !ð,F%à ðF%ð ðF%ð ˜˜c˜”Nð	F%ð
 
ðF%ð F%ð F%ð F%ðPEà ðEð ðEð ˜˜c˜”Nð	Eð
 
ðEð Eð Eð Eð, 37ð^
ð ^
à ð^
ð ˜Ô(¨4Ñ/ð^
ð 
ØØ
'ñ	(à
ñ	ð #ñ	#ð #ñ		#ð
 ñ	ð 	ð	ô
ð	^
ð ^
ð ^
ð ^
ð@	4à ð4ð 
Ð8Ô	9ð4ð 4ð 4ð 4ðlà ðð 
Ð8Ô	9ðð ð ð ð<E
à ðE
ð ðE
ð ð	E
ð
 
ØØ
"ñ	#à
"ñ	#ð ñ	ð 	ð		ô
ðE
ð E
ð E
ð E
ðVn1à!ðn1ð �DŒzðn1ð 
ˆt�CŒy˜$˜sœ)Ð#Ô	$ð	n1ð n1ð n1ð n1ð`
à˜cœð
ð 
ð
ð 
ð 
ð 
ð4R9à$ðR9ð 
ˆ °$Ñ 6Ð6Ô	7ðR9ð R9ð R9ð R9ðn¨#ð ð ð ð ð2
¨D°°c°¬Nð 
ð 
ð 
ð 
ðD *.ð	z
ð z
à�s”)ðz
ð �DŒzðz
ð   $Ñ&ð	z
ð
 
˜ |°TÐ'9Ô:Ñ	:ðz
ð z
ð z
ð z
ðxàðð ðð 
ð	ð ð ð ðD #'ð3Dð 3DàØØñàñð ñð ñ	ô
ð3Dð ˜4Ñð3Dð 
ð3Dð 3Dð 3Dð 3Dðj˜s T™zð ð ð ð ð !%ðCð Cà˜‘:ðCð 
�VÑ	˜dÑ	"ðCð Cð Cð CðJàðð ðð 
ð	ð ð ð ðB$àð$ð ˜T )¨iÑ"7Ô8Ñ8ð$ð 
ð	$ð $ð $ð $ð $ð $rv   r_   )qrˆ  rì   r\  r“  rc  r   Úcopyr   r   r   Útypingr   r	   r
   r   r   r   r  Úpydanticr   Ú_configr   r   r   r   re   r   Ústate._stater   Ú_utilsr   r   r   r   r   Ú_loggingr   Ú_utils._commonr   r   r   r=  r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   Ú	exceptionr=   rb   r>   r?   r@   rA   r¶  rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rÖ  rQ   rR   rS   rT   rU   Ú
permissionrV   rW   rX   rY   Ú_structured_output_toolrZ   Ú	workspacer[   r\   Ú
middlewarer]   r_   r³   rv   rt   ú<module>r˜     sÜ  ðà 4Ð 4Ø €€€Ø Ð Ð Ð Ø €€€Ø 	€	€	€	à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ Ð Ð Ð Ð Ð Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NØ Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð
ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð> /Ð .Ð .Ð .Ð .Ð .ðð ð ð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð"ð ð ð ð ð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð ð ð ð ð ?Ð >Ð >Ð >Ð >Ð >Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0àð Ø+Ð+Ð+Ð+Ð+Ð+Ð+à€Nðe3ð e3ð e3ð e3ð e3ñ e3ô e3ð e3ð e3ð e3rv   