Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
factory.cpython-313.pyc534 linesDownload Raw Back to __pycache__
1�

2��j�&��F�SrSSKJr SSKrSSKrSSKJrJrJr SSK	J3r4JrJrJ
r
JrJrJrJr SSKJr SSKJrJrJrJr SSKJr SS	KJr SS5KJrJr SSK J!r! SSK"J#r# SS
K$J%r% SSK&J'r'J(r( SSK)J*r* SSK+J,r,J-r-J.r. SSK/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9J:r:J;r;J<r< SSK=J>r>J?r?J@r@JArAJBrBJCrCJDrDJErEJFrF SSKGJHrH \"SS\
\855rI\6(a�SSKJJKrKJLrLJMrM SSKNJOrOJPrP SSKQJRrR SSK JSrS SSKTJUrU SSKVJWrW SSK&JXrX SSK/JYrY \L\5\2\L\5\2/\64/\6\-\3-4rZ\L\5\2\L\5\2/\64/\I4r[\L\5\2\L\5\2/\K\64/\K\6\-\3-4r\\L\5\2\L\5\2/\K\64/\K\I4r]Sr^SR�5r`S<S jra/S!QrbS=S"jrcS>S?S#jjrdS@S$jreSAS%jrf\R�"S&S'9SBS(j5rhSCS)jriS>SDS*jjrjSES+jrkSFS,jrlS>SGS-jjrmSHS.jrnSIS/jroSJS0jrpS>SS1SSSSSSSS2SSSS3.
SKS4jjjrqSLS5jrrSMS6jrsSNS7jrtSOS8jruSPS9jrvSQS:jrwS;/rxg)Rz:Agent factory for creating agents with middleware support.�)�annotationsN)�	dataclass�field�fields)�
TYPE_CHECKING�	Annotated�Any�Generic�cast�get_args�7get_origin�get_type_hints)�
BaseChatModel)�	AIMessage�8AnyMessage�
SystemMessage�ToolMessage)�BaseTool)�RunnableCallable)�END�START)�9StateGraph)�ToolCallTransformer)�ToolNode)�Command�Send)�	traceable)�NotRequired�Required�	TypedDict)
�AgentMiddleware�10AgentState�ContextT�ExtendedModelResponse�JumpTo�ModelRequest�
ModelResponse�OmitFromSchema�	ResponseT�	StateT_co�ToolCallRequest�_InputAgentState�_OutputAgentState)	�AutoStrategy�MultipleStructuredOutputsError�OutputToolBinding�ProviderStrategy�ProviderStrategyBinding�ResponseFormat�StructuredOutputError�StructuredOutputValidationError�ToolStrategy)�init_chat_modelc�<�\rSrSr%SrS\S'\"\S9rS\S'Sr	g	)11�_ComposedExtendedModelResponse�<z�Internal result from composed ``wrap_model_call`` middleware.12 13Unlike ``ExtendedModelResponse`` (user-facing, single command), this holds the14full list of commands accumulated across all middleware layers during15composition.16zModelResponse[ResponseT]�model_response)�default_factory�list[Command[Any]]�commands�N)17�__name__�18__module__�__qualname__�__firstlineno__�__doc__�__annotations__r�listr>�__static_attributes__r?��^D:\code\apps\devtools\python\user_packages\Python313\site-packages\langchain/agents/factory.pyr9r9<s%���-�,�(�#(��#>�H� �>�TrHr9)�	Awaitable�Callable�Sequence)�Runnable�RunnableConfig)�	BaseCache)�CompiledStateGraph)�Runtime)�	BaseStore)�Checkpointer)�ToolCallWrapperz)Error: {error}19 Please fix your mistakes.a�20Middleware added tools that the agent doesn't know how to execute.21 22Unknown tools: {unknown_tool_names}23Registered tools: {available_tool_names}24 25This happens when middleware modifies `request.tools` in `wrap_model_call` to include26tools that weren't passed to `create_agent()`.27 28How to fix this:29 30Option 1: Register tools at agent creation (recommended for most cases)31    Pass the tools to `create_agent(tools=[...])` or set them on `middleware.tools`.32    This makes tools available for every agent invocation.33 34Option 2: Handle dynamic tools in middleware (for tools created at runtime)35    Implement `wrap_tool_call` to execute tools that are added dynamically:36 37    class MyMiddleware(AgentMiddleware):38        def wrap_tool_call(self, request, handler):39            if request.tool_call["name"] == "dynamic_tool":40                # Execute the dynamic tool yourself or override with tool instance41                return handler(request.override(tool=my_dynamic_tool))42            return handler(request)43c�H�UR5nURSS5 URS5n[U[[4445(aN[
U5Vs0sH4o3RS:wdMUR[X#R5_M6 snUS'U$s snf)zQRemove ``runtime`` and ``handler`` from trace inputs before sending to LangSmith.�handlerN�request�runtime)	�copy�pop�get�45isinstancer&r+r�name�getattr)�inputs�filtered�req�fs    rI�
_scrub_inputsrc�s����{�{�}�H��L�L��D�!�46�,�,�y�47!�C��#��o�6�7�7�28��+�48�2=�Q���9�AT�(�A�F�F�G�C���(�(�+�49�����O��50s�B�3$B)�grokzgpt-5zgpt-4.1zgpt-4ozgpt-osszo3-prozo3-minic��[U[5(a[U/SS9$[U[5(aUR$U$)z�Normalize middleware return value to ModelResponse.51 52At inner composition boundaries, ``ExtendedModelResponse`` is unwrapped to its53underlying ``ModelResponse`` so that inner middleware always sees ``ModelResponse``54from the handler.55N��result�structured_response)r\rr'r$r;)rgs rI�_normalize_to_model_responseri�s?���&�)�$�$��V�H�$�G�G��&�/�0�0��$�$�$��MrHc�z�SUR0nURbURUS'U=(d /H]nUR(a
Sn[U5eUR(a
Sn[U5eUR56(dMRSn[U5e [
US9/nURU=(d /5 U$)aBuild a list of Commands from a model response and middleware commands.57 58The first Command contains the model response state (messages and optional59structured_response). Middleware commands are appended as-is.60 61Args:62    model_response: The model response containing messages and optional63        structured output.64    middleware_commands: Commands accumulated from middleware layers during65        composition (inner-first ordering).66 67Returns:68    List of ``Command`` objects ready to be returned from a model node.69�messagesrhz�Command goto is not yet supported in wrap_model_call middleware. Use the jump_to state field with before_model/after_model hooks instead.zBCommand resume is not yet supported in wrap_model_call middleware.zACommand graph is not yet supported in wrap_model_call middleware.)�update)rgrh�goto�NotImplementedError�resume�graphr�extend)r;�middleware_commands�state�cmd�msgr>s      rI�_build_commandsrv�s���$(��)>�)>�?�E��)�)�5�'5�'I�'I��#�$�"�(�b�(���8�8�[�
�&�c�*�*��:�:�V�C�%�c�*�*��9�9�9�U�C�%�c�*�*�)�%,�5�$9�#:�H��O�O�'�-�2�.��OrHc��^^�U(dgS	S70Sjjm[U5S:XaUSmSUU4SjjnU$SU4SjjnU"USUS5n[USS5HnU"XC5nM
 U$)
a�Compose multiple ``wrap_model_call`` handlers into single middleware stack.71 72Composes handlers so first in list becomes outermost layer. Each handler receives a73handler callback to execute inner layers. Commands from each layer are accumulated74into a list (inner-first, then outer) without merging.75 76Args:77    handlers: List of handlers.78 79        First handler wraps all others.80 81Returns:82    Composed handler returning ``_ComposedExtendedModelResponse``,83    or ``None`` if handlers empty.84Nc�`�[U=(d /5n[U[5(a(URUR5 UR85nOU[U[5(a5UR86nURbURUR5 O[U5n[X2S9$�z?Normalize any handler result to _ComposedExtendedModelResponse.)r;r>�87rFr\r9rqr>r;r$�command�appendri�rg�extra_commandsr>r;s    rI�_to_composed_result�7_chain_model_call_handlers.<locals>._to_composed_result����88(,�N�,@�b�'A���f�<�=�=��O�O�F�O�O�,�#�2�2�N�
�� 5�
6�
6�#�2�2�N��~�~�)�������/��9�&�A�N�-�^�_�_rH�rc� >�T"T"X55$�Nr?�rWrVr�single_handlers  ��rI�normalized_single�5_chain_model_call_handlers.<locals>.normalized_singles���'�~�g�'G�H�HrHc�,>^^�SUUU4SjjnU$)z-Compose two handlers where outer wraps inner.c�P>^^�/mSUUU4SjjnT"X5nT"UT=(d SS9$)Nc�V>�TR5 T"UT5n[U[5(a'TRUR5 UR89$[U[5(a4URbTRUR5 UR90$[U5$r��91�clearr\r9rqr>r;r$r{r|ri�ra�inner_result�accumulated_commandsrV�inners  ���rI�
inner_handler�X_chain_model_call_handlers.<locals>.compose_two.<locals>.composed.<locals>.inner_handlers����$�*�*�,�$�S�'�2���l�,J�K�K�(�/�/��0E�0E�F�'�6�6�6��l�,A�B�B�#�+�+�7�,�3�3�L�4H�4H�I�'�6�6�6�3�L�A�ArH�r~�ra�ModelRequest[ContextT]�returnr'r?�rWrVr��outer_resultr�rr��outers `  @���rI�composed�A_chain_model_call_handlers.<locals>.compose_two.<locals>.composeds;���928:� �
B�
B�!��8�L�&��3�;�t��
rH�rWr�rVz1Callable[[ModelRequest[ContextT]], ModelResponse]r�r9r?�r�r�r�rs`` �rI�compose_two�/_chain_model_call_handlers.<locals>.compose_twos.���	�+�	�F�	�,�	�	�4�rH����������r��rgzRModelResponse | AIMessage | ExtendedModelResponse | _ComposedExtendedModelResponser~�list[Command[Any]] | Noner�r9r�)r��A_ModelCallHandler[ContextT] | _ComposedModelCallHandler[ContextT]r�r�r�z#_ComposedModelCallHandler[ContextT]��len�reversed��handlersr�r��composed_handler�hrr�s     @@rI�_chain_model_call_handlersr��s����$��59�`�b�`�1�`�93(�`�$�8�}���!�!���	I�+�	I�F�	I�,�	I�	I�!� � �P� �P� �94-� �F#�8�B�<��"��>��
�h�s��m�
$��&�q�;��%��rHc��^^�U(dgS	S95Sjjm[U5S:XaUSmSUU4SjjnU$SU4SjjnU"USUS5n[USS5HnU"XC5nM
 U$)
aCompose multiple async ``wrap_model_call`` handlers into single middleware stack.96 97Commands from each layer are accumulated into a list (inner-first, then outer)98without merging.99 100Args:101    handlers: List of async handlers.102 103        First handler wraps all others.104 105Returns:106    Composed async handler returning ``_ComposedExtendedModelResponse``,107    or ``None`` if handlers empty.108Nc�`�[U=(d /5n[U[5(a(URUR5 UR109nOU[U[5(a5UR110nURbURUR5 O[U5n[X2S9$ryrzr}s    rIr�=_chain_async_model_call_handlers.<locals>._to_composed_resultMr�rHr�rc��<># �T"T"X5IShv�N5$N7fr�r?r�s  ��rIr��;_chain_async_model_call_handlers.<locals>.normalized_singlebs����'�^�G�-M�'M�N�N�'M�s���	c�,>^^�SUUU4SjjnU$)z3Compose two async handlers where outer wraps inner.c��l>^^# �/mSUUU4SjjnT"X5IShv�NnT"UT=(d SS9$N7f)Nc��r># �TR5 T"UT5IShv�Nn[U[5(a'TRUR5 UR111$[U[5(a4URbTRUR5 UR112$[U5$N�7fr�r�r�s  ���rIr��^_chain_async_model_call_handlers.<locals>.compose_two.<locals>.composed.<locals>.inner_handlerws�����$�*�*�,�%*�3��%8�8���l�,J�K�K�(�/�/��0E�0E�F�'�6�6�6��l�,A�B�B�#�+�+�7�,�3�3�L�4H�4H�I�'�6�6�6�3�L�A�A� 9�s�B7�B5�BB7r�r�r?r�s `  @���rIr��G_chain_async_model_call_handlers.<locals>.compose_two.<locals>.composedpsF����1138:� �
B�
B�"'�w�!>�>�L�&��3�;�t��
�?�s�4�2�4�rWr�rVz<Callable[[ModelRequest[ContextT]], Awaitable[ModelResponse]]r�r9r?r�s`` �rIr��5_chain_async_model_call_handlers.<locals>.compose_twojs.���	�+�	�Q�	�,�	�	�4�rHr�r�r�r�r�)r��K_AsyncModelCallHandler[ContextT] | _ComposedAsyncModelCallHandler[ContextT]r�r�r�z(_ComposedAsyncModelCallHandler[ContextT]r�r�s     @@rI� _chain_async_model_call_handlersr�9s����"��59�`�b�`�1�`�114(�`�$�8�}���!�!���	O�+�	O�Q�	O�,�	O�	O�!� � �Z� �Z� �1152� �F#�8�B�<��"��>��
�h�s��m�
$��&�q�;��%��rH�d)�maxsizec��[USS9$)z&Return cached type hints for a schema.T)�include_extras)r��schemas rI�_get_schema_type_hintsr��s���&��6�6rHc��UVs0sHo[U5_M nn[USS5[USS5[USS54$s snf)uResolve state, input, and output schemas for the given schemas.116 117Schemas are merged in list order; later entries override earlier ones when the118same field is declared by multiple schemas.  Duplicates are harmless — a type119that appears more than once is processed at its last position.120�StateSchemaN�InputSchema�input�OutputSchema�output)r��_resolve_schema)�schemasr��schema_hintss   rI�_resolve_schemasr��sW��JQ�Q��v�2�6�:�:��L�Q���m�T�:���m�W�=���n�h�?����Rs�Ac�"�0nUR5HonUR5HXupVSnU(a=[U5nUH,n	[U	[5(dM[X�5SLdM*Sn O U(aMTXcU'MZ Mq [
X5$)aUResolve schema by merging schemas and optionally respecting `OmitFromSchema` annotations.121 122Args:123    schema_hints: Resolved schema annotations to merge124    schema_name: Name for the generated `TypedDict`125    omit_flag: If specified, omit fields with this flag set (`'input'` or126        `'output'`)127 128Returns:129    Merged schema as `TypedDict`130FT)�values�items�_extract_metadatar\r(r^r )131r��schema_name�	omit_flag�all_annotations�hints�132field_name�133field_type�should_omit�metadata�metas134          rIr�r��s��� �O��$�$�&��&+�k�k�m�"�J��K��,�Z�8��$�D�!�$��7�7�G�D�<T�X\�<\�&*���%�135�;�.8�136�+�'4�'��[�2�2rHc���[U5[[1;a:[U5Sn[U5[La[[U5SS5$/$[U5[La[[U5SS5$/$)z_Extract metadata from a field type, handling `Required`/`NotRequired` and `Annotated` wrappers.rr�N)r
rrrrrF)�type_�137inner_types  rIr�r��s~���%��X�{�3�3��e�_�Q�'�138��j�!�Y�.����,�Q�R�0�1�1�/��I�139�E�	�i�	'��H�U�O�A�B�'�(�(�
�IrHc�R�[[US5n[[SU3S5n[URUS5nU(a!XBLa[US5(aUR$[URSU3S5nU(a!XSLa[US5(aUR$/$)aGet the `can_jump_to` list from either sync or async hook methods.140 141Args:142    middleware: The middleware instance to inspect.143    hook_name: The name of the hook (`'before_model'` or `'after_model'`).144 145Returns:146    List of jump destinations, or empty list if not configured.147N�a�__can_jump_to__)r^r!�	__class__�hasattrr�)�148middleware�	hook_name�base_sync_method�base_async_method�sync_method�async_methods      rI�_get_can_jump_tor��s�����	�4�@����1�Y�K��$�G���*�.�.�	�4�@�K���/��K�!2�3�3��*�*�*��:�/�/�1�Y�K��$�G�L���1��L�"3�4�4��+�+�+�
�IrHc��^�Sm[U[5(aUmO�[U[5(a�[USS5=(d! [USS5=(d
 [USS5mURnUb[URS5(aEU(a=[T[5(a(STR
5;aSTR
5;dg	T(a[U4S149j[55$S$)a|Check if a model supports provider-specific structured output.150 151Args:152    model: Model name string or `BaseChatModel` instance.153    tools: Optional list of tools provided to the agent.154 155        Needed because some models don't support structured output together with tool calling.156 157Returns:158    `True` if the model supports provider-specific structured output, `False` otherwise.159N�160model_name�model�model_id��structured_output�geminizgemini-3Tc3�H># �UHoTR5;v� M g7fr�)�lower)�.0�partr�s  �rI�	<genexpr>�._supports_provider_strategy.<locals>.<genexpr>%s����Z�3Y�4�J�$�$�&�&�3Y�s�"F)	r\�strrr^�profiler[r��any�&FALLBACK_MODELS_WITH_STRUCTURED_OUTPUT)r��tools�
model_profiler�s   @rI�_supports_provider_strategyr��s����"�J��%�����161�	�E�=�	)�	)��E�<��.�
.��u�g�t�,�
.��u�j�"�-�	�162�
�
�
��%��!�!�"5�6�6���z�3�/�/��163� 0� 0� 2�2��j�&6�&6�&8�8���	�Z�3Y�Z�Z���rHc�0^�[U[5(dgURnUSLagUSLaS[R	[T5S94$[U[1645(aSU4$[U[5(aE[U[5(a/[TU5(aS[R	[T5S94$g[U[5(a9[U4SjU55(aS[R	[T5S94$gSU"T54$)zOHandle structured output error.165 166Returns `(should_retry, retry_tool_message)`.167)Fr�FT)�errorc3�<># �UHn[TU5v� M g7fr�)r\)r��exc_type�	exceptions  �rIr��2_handle_structured_output_error.<locals>.<genexpr>Cs����M�}�8�z�)�X�.�.�}�s�)r\r6�
handle_errors� STRUCTURED_OUTPUT_ERROR_TEMPLATE�formatr��type�168issubclass�	Exception�tupler�)r�response_formatrs`  rI�_handle_structured_output_errorr+s�����o�|�4�4��#�1�1�M���������5�<�<�3�y�>�<�R�R�R��-��%�%��]�"�"��-��&�&��m�Y�/�/�J�y�-�4X�4X��9�@�@�s�9�~�@�V�V�V���-��'�'��M�}�M�M�M��9�@�@�s�9�~�@�V�V�V����y�)�)�)rHc��U(dg[U5S:XaUS$SSjnUSn[USS5HnU"X25nM
 U$)ajCompose wrappers into middleware stack (first = outermost).169 170Args:171    wrappers: Wrappers in middleware order.172 173Returns:174    Composed wrapper, or `None` if empty.175 176Example:177    ```python178    wrapper = _chain_tool_call_wrappers([auth, cache, retry])179    # Request flows: auth -> cache -> retry -> tool180    # Response flows: tool -> retry -> cache -> auth181    ```182Nr�rc�(^^�SUU4SjjnU$)z-Compose two wrappers where outer wraps inner.c�(>^�SUU4SjjnT"X5$)Nc�>�T"UT5$r�r?�ra�executer�s ��rI�183call_inner�T_chain_tool_call_wrappers.<locals>.compose_two.<locals>.composed.<locals>.call_inneris����S�'�*�*rH�rar+r��ToolMessage | Command[Any]r?�rWrrr�r�s ` ��rIr��@_chain_tool_call_wrappers.<locals>.compose_two.<locals>.composedds���184
+�
+���-�-rH)rWr+rz7Callable[[ToolCallRequest], ToolMessage | Command[Any]]r�rr?�r�r�r�s`` rIr��._chain_tool_call_wrappers.<locals>.compose_twoas.���		.�$�		.�L�		.�(�		.�		.��rHr�)r�rTr�rTr�rTr���wrappersr�rg�wrappers    rI�_chain_tool_call_wrappersrIsV��$��185�8�}�����{���"�b�\�F��H�S�b�M�*���W�-��+��MrHc��U(dg[U5S:XaUS$SSjnUSn[USS5HnU"X25nM
 U$)z�Compose async wrappers into middleware stack (first = outermost).186 187Args:188    wrappers: Async wrappers in middleware order.189 190Returns:191    Composed async wrapper, or `None` if empty.192Nr�rc�(^^�SUU4SjjnU$)z3Compose two async wrappers where outer wraps inner.c��D>^# �SUU4SjjnT"X5IShv�N$N7f)Nc��2># �T"UT5IShv�N$N7fr�r?rs ��rIr�Z_chain_async_tool_call_wrappers.<locals>.compose_two.<locals>.composed.<locals>.call_inner�s����"�3��0�0�0�0�s�
��rr?rs ` ��rIr��F_chain_async_tool_call_wrappers.<locals>.compose_two.<locals>.composed�s#����193
1�
1��w�3�3�3�3�s� �� )rWr+rzBCallable[[ToolCallRequest], Awaitable[ToolMessage | Command[Any]]]r�rr?rs`` rIr��4_chain_async_tool_call_wrappers.<locals>.compose_two�s.���		4�$�		4�W�		4�(�		4�		4��rHr�)r���Callable[[ToolCallRequest, Callable[[ToolCallRequest], Awaitable[ToolMessage | Command[Any]]]], Awaitable[ToolMessage | Command[Any]]]r�r%r�r%r�rs    rI�_chain_async_tool_call_wrappersr&yst��,��194�8�}�����{���195��196197��198��:�b�\�F��H�S�b�M�*���W�-��+��MrHr?F)
�
system_promptr�r199�state_schema�context_schema�checkpointer�store�interrupt_before�interrupt_after�debugr]�cache�transformersc
��^^^B^C^D^E^F^G^H^I^J^K^L^M^N^O�[T[5(a[T5mSmKUb![U[5(aUmKO	[US9mKUc/nUcSmIO?[U[[20045(aUmIO![U[5(aUmIO	[
US9mISmM[TI[5(a[	TIRS9mMO[TI[5(aTImM0mJTM(aBTMRH2n[R"U5nUTJURR'M4 UVVs/sHn[US/5HnUPM M nnnUVs/sHUnURR[ RLd)URR"[ R"LdMSUPMW nnSmOU(aFUVs/sH.n[%URS3[&S9"UR5PM0 nn[)U5mOUVs/sHUnURR"[ R"Ld)URR[ RLdMSUPMW nnSmGU(aFUVs/sH.n[%URS3[&S9"UR"5PM0 nn[+U5mGSmLUVs/sHn[U[,5(dMUPM nnUVs/sHn[U[,5(aMUPM nnUU-nU(dTO(dTG(a[/UTOTGS9OSmLTL(a'[1TLR2R555U-mHO[1U5mH[7UVs1sHnURiM sn5[7U5:wa
S	n5eUVs/sHUnURR:[ R:Ld)URR<[ R<LdMSUPMW nnUVs/sHUnURR>[ R>Ld)URR@[ R@LdMSUPMW nnUVs/sHUnURRB[ RBLd)URRD[ RDLdMSUPMW nnUVs/sHUnURRF[ RFLd)URRH[ RHLdMSUPMW nnUVs/sHUnURRJ[ RJLd)URRL[ RLLdMSUPMW n nUVs/sHUnURRL[ RLLd)URRJ[ RJLdMSUPMW n!nSmNU (aFU Vs/sH.n[%URS2013[&S9"URJ5PM0 n"n[OU"5mNSmFU!(aFU!Vs/sH.n[%URS3[&S9"URL5PM0 n#n[QU#5mFUbUO[Rn$/SU5QU$Pn%[UU%5un&n'n([WU&U'U(US
9n)S0UJ4SjjmES1UGUIUJULUMUO4SjjmDS2UDUEU4SjjmCS3UCUHUIUUKUN4Sjjn*S2UDUEU4SjjmBS3UBUFUHUIUUK4Sjjn+U)RYS[[U*U+SS95 TLbU)RYSTL5 UGH�nURR:[ R:Ld'URR<[ R<La�URR:[ R:LaUR:OSn,URR<[ R<LaUR<OSn-[[U,U-SS9n.U)RYURS3U.U&S9 URR>[ R>Ld'URR@[ R@La�URR>[ R>LaUR>OSn/URR@[ R@LaUR@OSn0[[U/U0SS9n1U)RYURS3U1U&S9 URRB[ RBLd'URRD[ RDLa�URRB[ RBLaURBOSn2URRD[ RDLaURDOSn3[[U2U3SS9n4U)RYURS3U4U&S9 URRF[ RFLd*URRH[ RHLdGM�URRF[ RFLaURFOSn5URRH[ RHLaURHOSn6[[U5U6SS9n7U)RYURS3U7U&S9 GM� U(aUSRS3n8OU(aUSRS3n8OSn8U(aUSRS3n9OSn9U(aUSRS3n:OSn:U(aUSRS3n;O[\n;U)R_[`U85 TLb�U9/n<[cSTLR2R5555(dTJ(aU<ReU;5 U)RgS[[[iTLU9TJU;S9SS9U<5 SU;/n=U(dU:S:waU=ReU95 U)RgU:[[[kU9TJU;S 9SS9U=5 Oy[7TJ5S:�a&U)RgU:[[[mU9U;S!9SS9U9U;/5 ODU:S:XaU)R_U:U;5 O+[oU)USRS3U;U9U;[qUSS"5S#9 U(a}[rRt"U5H8un>n?[oU)U>RS3U?RS3U9U;[qU>S$5S#9 M: [oU)USRS3U9U9U;[qUSS$5S#9 U(a}[rRt"U5H8un>n?[oU)U>RS3U?RS3U9U;[qU>S%5S#9 M: [oU)USRS3SU9U;[qUSS%5S#9 U(a�U)R_SUSRS35 [w[7U5S&-202SS5HBn@UU@n>UU@S&-203n?[oU)U>RS3U?RS3U9U;[qU>S"5S#9 MD U(a�[w[7U5S&-204SS5HBn@UU@n>UU@S&-205n?[oU)U>RS3U?RS3U9U;[qU>S'5S#9 MD [oU)USRS3[\U9U;[qUSS'5S#9 S(S)0nAS*S+0UAS,'T(aTWAS,S-'U)RyUUU	U206UTU
[z/U=(d S.QS/9R}WA5$s snnfs snfs snfs snfs snfs snfs snfs snfs snfs snfs snfs snfs snfs snfs snfs snf)4aCreates an agent graph that calls tools in a loop until a stopping condition is met.207 208For more details on using `create_agent`,209visit the [Agents](https://docs.langchain.com/oss/python/langchain/agents) docs.210 211Args:212    model: The language model for the agent.213 214        Can be a string identifier (e.g., `"openai:gpt-4"`) or a direct chat model215        instance (e.g., [`ChatOpenAI`][langchain_openai.ChatOpenAI] or other another216        [LangChain chat model](https://docs.langchain.com/oss/python/integrations/chat)).217 218        For a full list of supported model strings, see219        [`init_chat_model`][langchain.chat_models.init_chat_model(model_provider)].220 221        !!! tip ""222 223            See the [Models](https://docs.langchain.com/oss/python/langchain/models)224            docs for more information.225    tools: A list of tools, `dict`, or `Callable`.226 227        If `None` or an empty list, the agent will consist of a model node without a228        tool calling loop.229 230 231        !!! tip ""232 233            See the [Tools](https://docs.langchain.com/oss/python/langchain/tools)234            docs for more information.235    system_prompt: An optional system prompt for the LLM.236 237        Can be a `str` (which will be converted to a `SystemMessage`) or a238        `SystemMessage` instance directly. The system message is added to the239        beginning of the message list when calling the model.240    middleware: A sequence of middleware instances to apply to the agent.241 242        Middleware can intercept and modify agent behavior at various stages.243 244        !!! tip ""245 246            See the [Middleware](https://docs.langchain.com/oss/python/langchain/middleware)247            docs for more information.248    response_format: An optional configuration for structured responses.249 250        Can be a `ToolStrategy`, `ProviderStrategy`, or a Pydantic model class.251 252        If provided, the agent will handle structured output during the253        conversation flow.254 255        Raw schemas will be wrapped in an appropriate strategy based on model256        capabilities.257 258        !!! tip ""259 260            See the [Structured output](https://docs.langchain.com/oss/python/langchain/structured-output)261            docs for more information.262    state_schema: An optional `TypedDict` schema that extends `AgentState`.263 264        When provided, this schema is used instead of `AgentState` as the base265        schema for merging with middleware state schemas. This allows users to266        add custom state fields without needing to create custom middleware.267 268        Generally, it's recommended to use `state_schema` extensions via middleware269        to keep relevant extensions scoped to corresponding hooks / tools.270    context_schema: An optional schema for runtime context.271    checkpointer: An optional checkpoint saver object.272 273        Used for persisting the state of the graph (e.g., as chat memory) for a274        single thread (e.g., a single conversation).275    store: An optional store object.276 277        Used for persisting data across multiple threads (e.g., multiple278        conversations / users).279    interrupt_before: An optional list of node names to interrupt before.280 281        Useful if you want to add a user confirmation or other interrupt282        before taking an action.283    interrupt_after: An optional list of node names to interrupt after.284 285        Useful if you want to return directly or run additional processing286        on an output.287    debug: Whether to enable verbose logging for graph execution.288 289        When enabled, prints detailed information about each node execution, state290        updates, and transitions during agent runtime. Useful for debugging291        middleware behavior and understanding agent execution flow.292    name: An optional name for the `CompiledStateGraph`.293 294        This name will be automatically used when adding the agent graph to295        another graph as a subgraph node - particularly useful for building296        multi-agent systems.297    cache: An optional `BaseCache` instance to enable caching of graph execution.298    transformers: Optional sequence of scope-aware `StreamTransformer`299        factories to register on the compiled graph in addition to300        the agent defaults. Each factory is invoked per-scope301        (`factory(scope)`) so subgraph mini-muxes get fresh302        instances. Appended after the built-in `ToolCallTransformer`.303 304Returns:305    A compiled `StateGraph` that can be used for chat interactions.306 307Raises:308    AssertionError: If duplicate middleware instances are provided.309 310The agent node calls the language model with the messages list (after applying311the system prompt). If the resulting [`AIMessage`][langchain.messages.AIMessage]312contains `tool_calls`, the graph will then call the tools. The tools node executes313the tools and adds the responses to the messages list as314[`ToolMessage`][langchain.messages.ToolMessage] objects. The agent node then calls315the language model again. The process repeats until no more `tool_calls` are present316in the response. The agent then returns the full list of messages.317 318Example:319    ```python320    from langchain.agents import create_agent321 322 323    def check_weather(location: str) -> str:324        '''Return the weather forecast for the specified location.'''325        return f"It's always sunny in {location}"326 327 328    graph = create_agent(329        model="anthropic:claude-sonnet-4-5-20250929",330        tools=[check_weather],331        system_prompt="You are a helpful assistant",332    )333    inputs = {"messages": [{"role": "user", "content": "what is the weather in sf"}]}334    for chunk in graph.stream(inputs, stream_mode="updates"):335        print(chunk)336    ```337N)�contentr�r�z.wrap_tool_call)r]�process_inputsz.awrap_tool_call)r��wrap_tool_call�awrap_tool_callz-Please remove duplicate middleware instances.z.wrap_model_callz.awrap_model_callc3�8# �UHoRv� M g7fr�)r()r��ms  rIr��create_agent.<locals>.<genexpr>s���"F�:�a�>�>�:���)r(�input_schema�
output_schemar)c	�d>�[U[5(aNUR(d8[R"UR3385nUR
U5nU/US.$SU/0$[U[5(Ga[U[5(a�UR(a�URVs/sHowST;dM
UPM nnU(a�Sn	[U5S:�a]UVs/sHowSPM	 n339n[X�5n	[X�5up�U(dU	eUVs/sHn[!UUSUSS	9PM n
nSU/U
Q0$US340nTUSnUR
US5nUR"=(d SU3nU[!UUSUSS	9/US.$SU/0$![a4n[UR341RSS5n[XTU5nXdeSnAff=fs snfs snfs snf![aDn[USX@5n	[X�5up�U(dX�eSU[!UUSUSS	9/0sSnA$SnAff=f)
z�Handle model output including structured responses.342 343Args:344    output: The AI message output from the model.345    effective_response_format: The actual strategy used (may differ from initial346        if auto-detected).347)rkrhr@r348Nrkr]r��id)r2�tool_call_idr]r�argszReturning structured response: )r\r1�349tool_callsr2�from_schema_spec�schema_spec�parserr^r�r5r6rr�r/rr�tool_message_content)r��effective_response_format�provider_strategy_bindingrh�excr��validation_error�tc�structured_tool_callsr�350tool_names�should_retry�
error_message�
tool_messages�	tool_call�structured_tool_bindingrD�structured_output_toolss                 �rI�_handle_model_output�*create_agent.<locals>._handle_model_output"s�����/�1A�B�B��$�$�,C�,T�,T�-�9�9�-�)�	^�*C�*I�*I�&�*Q�'�*0��I\�]�]����)�)�
�0�,�?�?��6�9�-�-��!�!�$�.�.�%�.�r�V�*�@W�2W��.�
"�%�%�:>�	��,�-��1�7L�!M�7L��V�*�7L�J�!M� >�z� R�I�2Q�!�3�/�L�(�'��#8�
%�#8�B�$�$1�)+�D��!#�F���351#8�
"�%�'��(@�-�(@�A�A�2�!�4�	�%�.E�i�PV�FW�.X�+�*A�*G�*G�	�RX�HY�*Z�'�2�F�F�S�<�=P�<Q�R�)�#�'�(<�-6�t�_�%.�v�%6��%�0C�352�353�<�V�H�%�%��i!�4�")�1�=�=�D�D�j�Rc�#�K�(G�{�Y_�'`�$�*�3��4�� %��"N��%��@!�� ?�	�&�@Q�SV� _�I�2Q�!�3�/�L�(�'�0�#�"�'�(5�-6�t�_�%.�v�%6��%�	�	���sO�	F�/G�?G�#G�G�A	G!�354G�/G355�356G�!357H/�+9H*�$H/�*H/c�z>�T=(d Tn0nT(aTRR5nU(d�/nURH^n[U[5(aM[U[3585(dM1URU;dMCURUR5 M` U(a8[UR55n[RUUS9n[U5eURnUb)[U[[[ 45(d	[US9n[U[5(aV[#UR$URS9(a[!UR&S9nO!UTLaTbTnO[UR&S9nOUn[)UR5n	[U[5(a:TR+5V359s/sHo�R,PM nn360U	R/U5 [U[ 5(a=UR15nUR$R2"U	4SS0UDUR4D6U4$[U[5(a~UR6H.n
U
RT;dMSU
RS3n[U5e T(aS	OUR8nUR$R2"U	4S361U0UR4D6U4$U	(a5UR$R2"U	4S362UR80UR4D6S4$UR$R:"S0UR4D6S4$s sn363f)aGet the model with appropriate tool bindings.364 365Performs auto-detection of strategy if needed based on model capabilities.366 367Args:368    request: The model request containing model, tools, and response format.369 370Returns:371    Tuple of `(bound_model, effective_response_format)` where372    `effective_response_format` is the actual strategy used (may differ from373    initial if auto-detected).374 375Raises:376    ValueError: If middleware returned unknown client-side tool names.377    ValueError: If `ToolStrategy` specifies tools not declared upfront.378)�unknown_tool_names�available_tool_namesNr�)r��strictTzToolStrategy specifies tool 'zP' which wasn't declared in the original response format when creating the agent.r��tool_choicer?)�
tools_by_namerYr�r\�dictrr]r|�sorted�keys�DYNAMIC_TOOL_ERROR_TEMPLATEr�379ValueErrorr380r.r6r1r�r�r�rFr��toolrq�to_model_kwargs�381bind_tools�model_settings�schema_specsrX�bind)rW�has_wrap_tool_call�available_tools_by_namerU�trVrur382rE�final_tools�info�structured_tools�kwargsrIrX�awrap_tool_call_wrapper�initial_response_formatrQ�	tool_node�tool_strategy_for_setup�wrap_tool_call_wrappers               ������rI�_get_bound_model�&create_agent.<locals>._get_bound_model�s&���,4�N�7N��#%���&/�&=�&=�&B�&B�&D�#�"�!#���]�]���a��&�&���a��*�*�q�v�v�=T�/T�&�-�-�a�f�f�5�#�"�'-�.E�.J�.J�.L�'M�$�1�8�8�'9�)=�9���!��o�%�=D�<S�<S���&�z��l�L�:J�K�0383�0384�+�/�B�O��o�|�4�4�*�7�=�=��
�
�N�,<�O�DZ�DZ�,[�)� �$;�;�@W�@c�-D�)�,8��@V�@V�,W�)�)8�%�385�7�=�=�)���/��>�>�6M�6T�6T�6V�W�6V�d�	�	�6V��W����/�0��/�1A�B�B�.�>�>�@�F��
�
�(�(���(,��06��:A�:P�:P��*�	�
��/��>�>�0�<�<���7�7�"9�9�7����y�AC�C��386%�S�/�)�=�$;�%��@S�@S�K��
�
�(�(���-8��<C�<R�<R��*�	�
���
�
�(�(���-4�-@�-@��DK�DZ�DZ���	�
��}�}�!�!�;�G�$:�$:�;�T�A�A��_ Xs�L8c��>�T"U5upURnUR(aUR/UQnURU5nT387(aT388UlT	"XB5nUSnUR	S5n[UUS9$)z�Execute model and return response.389 390This is the core model execution logic wrapped by `wrap_model_call` handlers.391 392Raises any exceptions that occur during model invocation.393rkrhrf)rk�system_message�invoker]r[r'�rW�model_rErkr��handled_output�
messages_listrhrqrRr]s        ���rI�_execute_model_sync�)create_agent.<locals>._execute_model_syncs����-=�W�,E�)���#�#���!�!��.�.�:��:�H����x�(����F�K�.�f�P��&�z�2�
�,�0�0�1F�G��� � 3�394�	395rHc�>�[TTT	TUSSUUS9nT396cT"U5n[U5$T397"UT5n[URUR5$)zASync model request handler with sequential middleware processing.rkN�r�r�rtr398rkrXrsrX�r&rvr;r>)rsrXrWr;rgrz�
default_toolsrmr�rt�wrap_model_call_handlers     ������rI�399model_node� create_agent.<locals>.model_node&sk������)�3��:�&����	400��#�*�0��9�N�"�>�2�2�(��2E�F���v�4�4�f�o�o�F�FrHc��># �T"U5upURnUR(aUR/UQnURU5IShv�NnT401(aT402UlT	"XB5nUSnUR	S5n[UUS9$N:7f)z�Execute model asynchronously and return response.403 404This is the core async model execution logic wrapped by `wrap_model_call`405handlers.406 407Raises any exceptions that occur during model invocation.408Nrkrhrf)rkrt�ainvoker]r[r'rvs        ���rI�_execute_model_async�*create_agent.<locals>._execute_model_async:s�����-=�W�,E�)���#�#���!�!��.�.�:��:�H��~�~�h�/�/����F�K�.�f�P��&�z�2�
�,�0�0�1F�G��� � 3�409�	410�0�s�AB�B	�;Bc���># �[T	TT411TUSSUUS9nTcT"U5IShv�Nn[U5$T"UT5IShv�Nn[URUR5$N@N&7f)zBAsync model request handler with sequential middleware processing.rkNr}r~)rsrXrWr;rgr��awrap_model_call_handlerrrmr�rts     ������rI�amodel_node�!create_agent.<locals>.amodel_nodeVs��������)�3��:�&����	412��$�+�#7��#@�@�N�"�>�2�2�/��9M�N�N���v�4�4�f�o�o�F�F�	A�O�s!�"A*�A&�A*�A(�%A*�(A*r�F��tracez
.before_agent)r:z
.before_modelz.after_modelz.after_agentrr�c3�8# �UHoRv� M g7fr�)�
return_direct)r�r_s  rIr�r8�s���P�/O�t�"�"�/O�r9)rn�model_destinationrQ�end_destination)r�rQr��r�r��after_model)r]�default_destinationr�r��can_jump_to�before_agent�before_modelr��after_agent�recursion_limiti'�ls_integration�langchain_create_agentr��
lc_agent_namer?)r*r+r,r-r.r]r/r0)r�rrEzResponseFormat[Any] | Noner��dict[str, Any])rWr�r�z5tuple[Runnable[Any, Any], ResponseFormat[Any] | None])rWr�r�r')rszAgentState[Any]rXzRuntime[ContextT]r�r=)?r\r�r7rr6r1r.r�rcr0rAr_r]r^r�r4r!r5rrcrr&rZrrFrYr�r��AssertionErrorr��
abefore_agentr��
abefore_modelr��aafter_modelr��aafter_agent�wrap_model_call�awrap_model_callr�r�r"r�r�add_noderr�add_edgerr�r|�add_conditional_edges�_make_tools_to_model_edge�_make_model_to_tools_edge�_make_model_to_model_edge�_add_middleware_edger��	itertools�pairwise�range�compiler�with_config)Pr�r�r'r�r413r(r)r*r+r,r-r.r]r/r0�response_schema�structured_tool_infor7rg�middleware_tools�middleware_w_wrap_tool_callr�middleware_w_awrap_tool_call�async_wrappers�built_in_tools�
regular_tools�available_toolsru�middleware_w_before_agent�middleware_w_before_model�middleware_w_after_model�middleware_w_after_agent�middleware_w_wrap_model_call�middleware_w_awrap_model_call�
sync_handlers�async_handlers�414base_state�
state_schemas�resolved_state_schemar:r;rpr�r��sync_before_agent�async_before_agent�before_agent_node�sync_before�async_before�before_node�415sync_after�async_after�416after_node�sync_after_agent�async_after_agent�after_agent_node�417entry_node�loop_entry_node�loop_exit_node�	exit_node�tools_to_model_destinations�model_to_tools_destinations�m1�m2�idx�configr�rzrqrRr�rlrrmrQrtrnror�rpsP`           `                                                     @@@@@@@@@@@@@@rI�create_agentr��se����r�%������&��,0�N�� ��m�]�3�3�*�N�*�=�A�N�
�}�����"&��	�O�l�4D�%E�	F�	F�"1��	�O�\�	2�	2�"1��#/�o�"F��9=���)�<�8�8�".�6M�6T�6T�"U��	�+�\�	:�	:�"9��AC���6�C�C�O�#4�#E�#E�o�#V� �FZ�#�$8�$=�$=�$B�$B�C� D�$.�O�:�a�w�q�'�2�7N�!��7N��:��O��#��A��;�;�%�%�_�-K�-K�K��;�;�&�&�o�.M�.M�M�	418�� �#�"��"�4191�	420�1��
�a�f�f�X�_�5�m�T�� � �
�1�		�421�";�8�!D���$��A��;�;�&�&�o�.M�.M�M��;�;�%�%�_�-K�-K�K�	422��!�$�#��#�4232�	424�2��
�a�f�f�X�%5�6�}�U��!�!�
�2�		�425�#B�.�"Q��"&�I�!&�>��A�*�Q��*=�a��N�>� %�A��1�Z��4�-@�Q��M�A�'��6�O��4�8O�	�!�1�3�	426�����Y�4�4�;�;�=�>��O�
��^�,�
��J�'�J�q�A�F�F�J�'�(�C�427�O�;�=���S�!�!��!��A��;�;�#�#�?�+G�+G�G��;�;�$�$�O�,I�,I�I�	428���!��!��A��;�;�#�#�?�+G�+G�G��;�;�$�$�O�,I�,I�I�	429���!�� ��A��;�;�"�"�/�*E�*E�E��;�;�#�#�?�+G�+G�G�	430��� �� ��A��;�;�"�"�/�*E�*E�E��;�;�#�#�?�+G�+G�G�	431��� ��$��A��;�;�&�&�o�.M�.M�M��;�;�'�'��/O�/O�O�	432��!�$��%��A��;�;�'�'��/O�/O�O��;�;�&�&�o�.M�.M�M�	433��"�%�#��#�4342�	435�2��
�a�f�f�X�%5�6�}�U��!�!�
�2�		�436�#=�]�"K�� $��$�4373�	438�3��
�a�f�f�X�%6�7�
�V��"�"�
�3�		�439�$D�N�#S� �!-�!9��z�J�!T�"F�:�"F� S�440� S�M�9I�-�9X�6��<��441	�*�!�#�%�		�442�f&��f&�6P�f&�	�f&�PB�'�B�	>�B�B�B443�444�6G�G�(445�446�8G�G�*447�N�N�7�,�Z��E�R�S���
���w�	�*���
�K�K�$�$�O�,H�,H�H��{�{�(�(��0M�0M�M��;�;�+�+�?�3O�3O�O�����
��;�;�,�,�O�4Q�4Q�Q�����
�448!1�1B�DV�^c� d���N�N��6�6�(�-�(�*;�J_�
�
�449
�K�K�$�$�O�,H�,H�H��{�{�(�(��0M�0M�M��;�;�+�+�?�3O�3O�O�����
��;�;�,�,�O�4Q�4Q�Q�����
�450+�;��E�R�K��N�N��6�6�(�-�(�+�DY�
�
�451
�K�K�#�#�?�+F�+F�F��{�{�'�'��/K�/K�K��;�;�*�*�/�2M�2M�M��
�
��
��;�;�+�+�?�3O�3O�O�����
�452*�*�k��O�J��N�N�a�f�f�X�\�2�J�Mb�N�c�
�K�K�#�#�?�+F�+F�F��{�{�'�'��/K�/K�K��;�;�*�*�/�2M�2M�M��
�
��
��;�;�+�+�?�3O�3O�O�����
�453 0�0@�BS�[`�a���N�N��6�6�(�,�'�)9�H]�
�
�_�h!�1�!�4�9�9�:�-�H�454�	"�1�!�4�9�9�:�-�H�455��456�!�6�q�9�>�>�?�}�M��!�� �4�Q�7�<�<�=�\�J�� �� �/��3�8�8�9��F�	��	�	�N�N�5�*�%���(7�&7�#��P�y�/F�/F�/M�/M�/O�P�P�P�&�'�.�.�y�9�
�#�#���)�'�&5�,C�$-�	��
�
(�	457�((/�	�&:�#��n��7�'�.�.��?�
�#�#���)�&5�,C�$-��458�

�
(�	459�460
�
$�	%��	)�
�#�#���)�&5�$-���
��i�(�461	462�463�7�	"�
���~�y�1�	��,�Q�/�4�4�5�\�B� )�-�%�(�)A�!�)D�m�T�
	464�!��(�(�)B�C�F�B�� �����y�
�.�')�w�w�i�}�$=�"1� )�,�R��@�

�D�	��-�b�1�6�6�7�}�E� /�-�%�(�)B�2�)F��W�
	465�!��(�(�)B�C�F�B�� �����y�
�.�')�w�w�i�}�$=�"1� )�,�R��@�

�D�	��-�b�1�6�6�7�}�E� '�-�%�(�)B�2�)F��W�
	466� �
���w�#;�B�#?�#D�#D�"E�\� R�S���5�6��:�A�r�B�C�)�#�.�B�)�#��'�2�B� �����y��-�')�w�w�i�|�$<�"1� )�,�R��?�

�C� ���5�6��:�A�r�B�C�)�#�.�B�)�#��'�2�B� �����y��-�')�w�w�i�|�$<�"1� )�,�R��?�

�C�	��,�Q�/�4�4�5�\�B� #�-�%�(�)A�!�)D�m�T�
	467�0��7�F�*�,D�E�F�:���.2��z��?�+��=�=�!��)�'��
��)�A�\�-?�R�A��	��k�&��	��OP��468#��469��$��470��?��A��6(��!��!�� �� ��$��%��471��472s��3!|#�A|)�1|)�5|.�A|3�"|3�75|8�?|=�|=�(}�}�6}�1A}�}�A}�)}�5A}�}�A}�-}�9A} �} �A}%�1}%�5}*�5}/c�2�US:XaU$US:XaU$US:Xagg)Nr��endr�r?)�jump_tor�r�s   rI�
_resolve_jumpr��s.���'�� � ��%�����'���rHc��[[U5S-473SS5H[n[X[5(dM[	SX5nXS-SVs/sHn[U[4745(dMUPM nnX$4s $ S/4$s snf)aReturn the last AI message and any subsequent tool messages.475 476Args:477    messages: List of messages to search through.478 479Returns:480    A tuple of (last_ai_message, tool_messages). If no AIMessage is found,481    returns (None, []). Callers must handle the None case appropriately.482r�r�rN)r�r�r\rrr)rk�i�last_ai_messager7rNs     rI� _fetch_last_ai_and_tool_messagesr��s���3�x�=�1�$�b�"�
-���h�k�9�-�-�"�;���<�O�(0�Q���(9�X�(9�1�Z��;�=W�Q�(9�M�X�"�1�1�	.���8�O��Ys�
A=�*A=c�(^^^�SUUU4SjjnU$)Nc��>�URS5=n(a[UT483T	S9$[US5up#UcT	$UVs/sHoDRPM nn[	UR4845S:XaT	$UR485Vs/sHnUSU;dMUST;dMUPM nnU(aUVs/sHn[
SU/5PM sn$SU;aT	$T486$s snfs snfs snf)	Nr�r�rkrr=r]r�rh)r[r�r�r>r�r@r)rsr�r�rNr7�tool_message_ids�c�pending_tool_callsrOr�r�rQs         ���rI�model_to_tools�1_make_model_to_tools_edge.<locals>.model_to_tools�s����i�i�	�*�*�7�*� ��"3� /��
�*J�%�PZ�J[�)\�&���"�"�"�4A�B�M�q�N�N�M��B���)�)�*�a�/�"�"�%�/�/�487�/����w�.�.�
�34�V�9�D[�3[�
�/�	�488��@R�S�@R�9�D��9�+�.�@R�S�S�!�E�)�"�"�!� ��5C��489��Ts�C�>
C�C�C�-C�rsr�r�zstr | list[Send] | Noner?)r�rQr�r�s``` rIr�r��s&���+!��+!�	 �+!�+!�Z�rHc�$^^�SUU4SjjnU$)Nc�^>�URS5=n(a[UTTS9$SU;aT$T$)Nr�r�rh)r[r�)rsr�r�r�s  ��rI�model_to_model�1_make_model_to_model_edge.<locals>.model_to_model�sG����i�i�	�*�*�7�*� ��"3� /��
�!�E�)�"�"�!� rHr�r?)r�r�r�s`` rIr�r��s%���490!��!�	 �!�!�&�rHc�$^^^^�SUUUU4SjjnU$)Nc�>�[US5upUcT$URVs/sHo3STR;dMUPM nnU(a[U4SjU55(aT$[	U4SjU55(aT$T$s snf)Nrkr]c3�\># �UH!nTRUSRv� M# g7f)r]N)rYr�)r�r�rns  �rIr��D_make_tools_to_model_edge.<locals>.tools_to_model.<locals>.<genexpr>s*����*491�F\��I�#�#�A�f�I�.�<�<�F\�s�),c3�@># �UHoRT;v� M g7fr�)r])r�rgrQs  �rIr�r� s����H�-�Q�v�v�0�0�-�s�)r�r@rY�allr�)	rsr�rNr��client_side_tool_callsr�r�rQrns	     ����rI�tools_to_model�1_make_tools_to_model_edge.<locals>.tools_to_models����)I�%�PZ�J[�)\�&���"�$�$�492'�1�1�"493�1�!�v�Y�)�BY�BY�5Y�A�1�	�"494�"�c�*495�F\�*496�'497�'498�#�"��H�-�H�H�H�"�"�499!� ��"500s501�B�B)rsr�r��502str | Noner?)rnr�rQr�r�s```` rIr�r�s���!�!�4�rHc�$^^^�U(atSUUU4SjjnT/nSU;aURT5 SU;aURS5 SU;aUT:waURT5 URU[USS9U5 gURUT5 g)	a�Add an edge to the graph for a middleware node.503 504Args:505    graph: The graph to add the edge to.506    name: The name of the middleware node.507    default_destination: The default destination for the edge.508    model_destination: The destination for the edge to the model.509    end_destination: The destination for the edge to the end.510    can_jump_to: The conditionally jumpable destinations for the edge.511c�J>�[URS5TTS9=(d T$)Nr�r�)r�r[)rsr�r�r�s ���rI�	jump_edge�'_add_middleware_edge.<locals>.jump_edgeBs,�����I�I�i�(�&7�$3��'�512'�

rHr�r�r�Fr�N)rsr�r�r�)r|r�rr�)rpr]r�r�r�r�r��destinationss  ```   rIr�r�+s����*�	�	�,�,���K������0��k�!�����(��k�!�d�.?�&?���� 1�2�
�#�#�D�*:�9�E�*R�T`�a�	���t�0�1rHr�)r_r�r�r�)rgz1ModelResponse | AIMessage | ExtendedModelResponser�r'r�)r;r'rrr�r�r=)r�z%Sequence[_ModelCallHandler[ContextT]]r�z*_ComposedModelCallHandler[ContextT] | None)r�z*Sequence[_AsyncModelCallHandler[ContextT]]r�z/_ComposedAsyncModelCallHandler[ContextT] | None)r�rr�r�)r�z513list[type]r�ztuple[type, type, type])r�zdict[type, dict[str, Any]]r�r�r�r�r�r)r�rr�z	list[Any])r�zAgentMiddleware[Any, Any]r�r�r�zlist[JumpTo])r��str | BaseChatModelr�z&list[BaseTool | dict[str, Any]] | Noner��bool)rrr514zResponseFormat[Any]r�ztuple[bool, str])rzSequence[ToolCallWrapper]r�zToolCallWrapper | None)rz�Sequence[Callable[[ToolCallRequest, Callable[[ToolCallRequest], Awaitable[ToolMessage | Command[Any]]]], Awaitable[ToolMessage | Command[Any]]]]r�z�Callable[[ToolCallRequest, Callable[[ToolCallRequest], Awaitable[ToolMessage | Command[Any]]]], Awaitable[ToolMessage | Command[Any]]] | None) r�r�r�z?Sequence[BaseTool | Callable[..., Any] | dict[str, Any]] | Noner'zstr | SystemMessage | Noner�z.Sequence[AgentMiddleware[StateT_co, ContextT]]r515zCResponseFormat[ResponseT] | type[ResponseT] | dict[str, Any] | Noner(z"type[AgentState[ResponseT]] | Noner)ztype[ContextT] | Noner*zCheckpointer | Noner+zBaseStore | Noner,�list[str] | Noner-rr.r�r]r�r/zBaseCache[Any] | Noner0z1Sequence[Callable[[tuple[str, ...]], Any]] | Noner�zcCompiledStateGraph[AgentState[ResponseT], ContextT, _InputAgentState, _OutputAgentState[ResponseT]])r�z
JumpTo | Noner�r�r�r�r�r�)rkzlist[AnyMessage]r�z*tuple[AIMessage | None, list[ToolMessage]])r�r�rQ�!dict[str, OutputToolBinding[Any]]r�r�r��3Callable[[dict[str, Any]], str | list[Send] | None])r�r�r�r�r�r)516rnrr�r�rQrr�r�r�z&Callable[[dict[str, Any]], str | None])rpz[StateGraph[AgentState[ResponseT], ContextT, _InputAgentState, _OutputAgentState[ResponseT]]r]r�r�r�r�r�r�r�r�zlist[JumpTo] | Noner��None)yrD�517__future__r�	functoolsr��dataclassesrrr�typingrrr	r518rrr
r�*langchain_core.language_models.chat_modelsr�langchain_core.messagesrrrr�langchain_core.toolsr�langgraph._internal._runnabler�langgraph.constantsrr�langgraph.graph.stater�langgraph.prebuiltr�langgraph.prebuilt.tool_noder�langgraph.typesrr�	langsmithr�typing_extensionsrrr �!langchain.agents.middleware.typesr!r"r#r$r%r&r'r(r)r*r+r,r-�"langchain.agents.structured_outputr.r/r0r1r2r3r4r5r6�langchain.chat_modelsr7r9�collections.abcrJrKrL�langchain_core.runnablesrMrN�langgraph.cache.baserOrP�langgraph.runtimerQ�langgraph.store.baserRrSrT�_ModelCallHandler�_ComposedModelCallHandler�_AsyncModelCallHandler�_ComposedAsyncModelCallHandlerr�stripr]rcr�rirvr�r��	lru_cacher�r�r�r�r�r�rrr&r�r�r�r�r�r�r��__all__r?rHrI�<module>r"s"��@�"���0�0�	�	�	�E�U�U�)�:�*�,�2�1�)��>�>�����519�520�521�2��U�W�Y�%7�U��U��=�=�A�.�8�)�.�,�A� �	�h�	��<��+A�*B�M�*Q�!R�S��	�!�$9�9�	;���522!)�	�h�	��<��+A�*B�M�*Q�!R�S�&�	(�!��523&�	�h�	��<��+A�*B�I�m�D\�*\�!]�^��-�)�+�.C�C�D�	F���524&.�	�h�	��<��+A�*B�I�m�D\�*\�!]�^��0�1�	3�&�"�$P� ��0525�E�G�1�6	�526*�&�
�=�
��
�$6:�'�!�'�2�'��'�TY�3�Y�/�Y�xX�8�X�4�X�v���S�!�7�"�7�527�$!� 3�,� 3�� 3�� 3�528�	 3�F� �HQU�*��*�'M�*�	�*�Z*��*�(�*��*�<-�'�-��-�`=��=��=�DNR�V�15�AC�[_�7;�,0�(,�"�)-�(,���#'�FJ�!V��V�J�V�.�	V�529?�V�Y�
V�5�V�*�V�&�V��V�'�V�&�V��V��V�!�V� D�!V�"�#V�r�
�����	�530�����/��*3��3�?�3��	3�5319�3�l�����9�	�6!��!��!�?�	!�532�!�,�
!�H-2��-2�533�-2��
-2��-2��-2�%�-2�534�-2�b��rH
codekingpro/portable-devtools · Team Ai