+
    ^eòj¶'  ã                  ó&  € R t ^ RIHt ^ RIHtHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHtHtHtHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt RRRRRRRRRRRR/R R lltRRRRRR/R R lltRRRRRRRRRR/R R lltR R ltR R lt. ROtR# )a4  Tool lifecycle helpers.

Use this module when you want NeMo Relay to emit tool start and end events around a
piece of application logic.

``execute()`` is the usual entry point and runs the full middleware pipeline.
``call()`` and ``call_end()`` are the lower-level manual lifecycle APIs.

Example::

    import nemo_relay

    async def search(args):
        return nemo_relay.ToolExecutionResult({"result": args["query"].upper()})

    result = await nemo_relay.tools.execute("search", {"query": "hello"}, search)
    assert result.result == {"result": "HELLO"}
)Úannotations)Ú	AwaitableÚCallable)Údatetime)ÚJson)Úensure_scope_stack)ÚScopeHandleÚToolAttributesÚToolExecutionResultÚ
ToolHandle)Ú	tool_call)Útool_call_end)Útool_call_execute)Útool_conditional_execution)Útool_request_interceptsÚhandleNÚ
attributesÚdataÚmetadataÚtool_call_idÚ	timestampc               ó<   € V ^8„  d   QhRRRRRRRRR	R
RR
RRRRRR/	# )é   ÚnameÚstrÚargsr   r   úScopeHandle | Noner   úToolAttributes | Noner   úJson | Noner   r   ú
str | Noner   údatetime | NoneÚreturnr   © )Úformats   "Ú‡/opt/data/installs/351f81cc06284494/environments/aa258815729c481f8402f54f4c368f83/venv/lib/python3.14/site-packages/nemo_relay/tools.pyÚ__annotate__r%   5   sm   € ÷ Bñ BØ
ðBà
ðBð ð	Bð
 &ðBð ðBð ðBð ðBð ðBð ñBó    c               ó<   € \        4        \        V VVVVVVVR7      # )ab  Start a manual tool span and return its ``ToolHandle``.

Args:
    name: Tool name recorded on emitted lifecycle events.
    args: JSON-compatible tool arguments to associate with the call.
    handle: Optional parent scope handle. When omitted, the current scope
        becomes the parent.
    attributes: Optional native tool attributes attached to the start event.
    data: Optional JSON application payload stored on the tool handle.
    metadata: Optional JSON metadata recorded on the emitted start event.
    tool_call_id: Optional provider-specific tool call identifier to attach
        to the emitted events.
    timestamp: Optional timezone-aware ``datetime`` recorded as the handle
        start time and on the emitted start event. When omitted, the current
        runtime time is used.

Returns:
    ToolHandle: Handle used to finish the manual span with ``call_end()``.

Notes:
    This starts only the manual tool lifecycle span. It applies
    sanitize-request guardrails to the emitted start-event payload but does
    not run request or execution intercepts. ``timestamp`` must be a
    timezone-aware ``datetime``; strings and naive datetimes are rejected.

Example::

    import nemo_relay

    handle = nemo_relay.tools.call(
        "search",
        {"query": "hello"},
        handle=None,
        attributes=None,
        data={"attempt": 1},
        metadata={"path": "manual"},
        tool_call_id="tool-call-1",
    )
    nemo_relay.tools.call_end(
        handle,
        nemo_relay.ToolExecutionResult({"result": "ok"}),
        data={"cached": False},
        metadata={"status": "success"},
    )
)r   r   r   r   r   r   )r   Ú_native_tool_call)r   r   r   r   r   r   r   r   s   &&$$$$$$r$   Úcallr)   5   s0   € ôp ÔÜØØØØØØØ!Øô	ð 	r&   c               ó0   € V ^8„  d   QhRRRRRRRRRR	R
R/# )r   r   r   ÚresultzToolExecutionResult[Json]r   r   r   r   r    r!   ÚNoner"   )r#   s   "r$   r%   r%   z   sL   € ÷  dñ  dØð dà%ð dð ð	 dð
 ð dð ð dð 
ñ dr&   c               ó2   € \        4        \        WW#VR7      # )a  Finish a manual tool span started by ``call()``.

Args:
    handle: Tool handle returned by ``call()``.
    result: Canonical ``ToolExecutionResult`` to record on the end event.
    data: Optional JSON payload used when the sanitized ``result`` is JSON null.
    metadata: Optional JSON metadata recorded on the emitted end event.
    timestamp: Optional timezone-aware ``datetime`` recorded on the emitted
        end event. When omitted, the runtime default end timestamp is used.

Returns:
    None: This function returns after an immutable end-event snapshot and
    its middleware/subscriber chains have been queued for publication.

Notes:
    ``call_end()`` remains synchronous. Sanitize-response guardrails,
    event sanitizers, and subscriber delivery run later on Relay's serial
    publication path. Callback failures are logged and fail closed; they
    cannot be raised by this call. The caller-owned ``result`` is not
    altered.
    ``timestamp`` must be a timezone-aware ``datetime``; strings and naive
    datetimes are rejected.
)r   r   r   )r   Ú_native_tool_call_end)r   r+   r   r   r   s   &&$$$r$   Úcall_endr/   z   s   € ô> ÔÜ  °dÐYbÔcÐcr&   c               ó<   € V ^8„  d   QhRRRRRRRRR	R
RRRRRRRR/	# )r   r   r   r   r   ÚfunczRCallable[[Json], ToolExecutionResult[Json] | Awaitable[ToolExecutionResult[Json]]]r   r   r   r   r   r   r   r   r   r!   z$Awaitable[ToolExecutionResult[Json]]r"   )r#   s   "r$   r%   r%   �   sn   € ÷ Mñ MØ
ðMà
ðMð ]ðMð
 ðMð &ðMð ðMð ðMð ðMð *ñMr&   c               ó<   € \        4        \        V VVVVVVVR7      # )a�  Run a tool through the managed middleware pipeline.

Pipeline order:

1. tool conditional-execution guardrails
2. tool request intercepts
3. tool sanitize-request guardrails for emitted start events
4. tool execution intercepts
5. ``func(args)``
6. tool sanitize-response guardrails for emitted end events

Args:
    name: Tool name recorded on emitted lifecycle events.
    args: JSON-compatible arguments passed through the middleware pipeline.
    func: Tool implementation invoked as ``func(args)`` after guardrails and
        intercepts run. It must return ``ToolExecutionResult``.
    handle: Optional parent scope handle. When omitted, the current scope
        becomes the parent.
    attributes: Optional native tool attributes attached to the start event.
    data: Optional JSON application payload stored on the managed tool handle.
    metadata: Optional JSON metadata recorded on the emitted start event.
    tool_call_id: Optional provider-specific tool call identifier recorded
        on the emitted start and end events.

Returns:
    ToolExecutionResult: The canonical result returned by ``func`` or an
    execution intercept.

Raises:
    RuntimeError: If a guardrail rejects the call or the runtime fails.
    Exception: An exception raised by ``func`` or an execution intercept
        propagates to caller unchanged.

Notes:
    Sanitize guardrails affect emitted event payloads only. They do not
    mutate the arguments passed to ``func`` or the value returned to the
    caller.

Example::

    import nemo_relay

    async def local_tool(args):
        return nemo_relay.ToolExecutionResult({"count": len(args["items"])})

    result = await nemo_relay.tools.execute(
        "count",
        {"items": [1, 2, 3]},
        local_tool,
        handle=None,
        attributes=None,
        data={"source": "example"},
        metadata={"request_id": "req-1"},
    )
    assert result.result["count"] == 3
)r   r   r   r   r   )r   Ú_native_tool_call_execute)r   r   r1   r   r   r   r   r   s   &&&$$$$$r$   Úexecuter4   �   s0   € ôF ÔÜ$ØØØØØØØØ!ô	ð 	r&   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   r   r   r!   zJson | Awaitable[Json]r"   )r#   s   "r$   r%   r%   í   s"   € ÷ 7ñ 7˜Sð 7¨ð 7Ð1Gñ 7r&   c                ó,   € \        4        \        W4      # )a0  Apply global tool request intercepts to ``args``.

Args:
    name: Tool name used when evaluating the registered intercept chain.
    args: JSON-compatible tool arguments to pass through the intercepts.

Returns:
    Json | Awaitable[Json]: The arguments produced by the final request
    intercept. Outside a running event loop this is returned directly.
    Inside an event loop, await the returned value.

Raises:
    RuntimeError: If an async intercept is registered when called outside an event loop.
    Exception: An exception raised by an intercept.

Notes:
    This runs only the request-intercept chain. It does not execute
    conditional guardrails, sanitize guardrails, or the tool callback.
    Outside an event loop, middleware runs on a Relay helper thread while
    the caller waits for the result.
)r   Ú_native_tool_request_intercepts©r   r   s   &&r$   Úrequest_interceptsr9   í   s   € ô, ÔÜ*¨4Ó6Ð6r&   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   r   r   r!   zAwaitable[None] | Noner"   )r#   s   "r$   r%   r%     s"   € ÷ :ñ : ð :¨4ð :Ð4Jñ :r&   c                ó,   € \        4        \        W4      # )a  Run tool conditional-execution guardrails for ``args``.

Args:
    name: Tool name used when evaluating registered guardrails.
    args: JSON-compatible tool arguments to validate.

Returns:
    Awaitable[None] | None: ``None`` when execution is allowed, returned
    directly outside an event loop or through an awaitable inside one.

Notes:
    This helper evaluates only the conditional-execution guardrail chain
    and does not invoke request intercepts or tool execution.
    Outside an event loop, middleware runs on a Relay helper thread while
    the caller waits for the result.

Raises:
    RuntimeError: If a guardrail rejects the call or an asynchronous
        guardrail is registered when called outside an event loop.
    Exception: An exception raised by a guardrail.
)r   Ú"_native_tool_conditional_executionr8   s   &&r$   Úconditional_executionr=     s   € ô, ÔÜ-¨dÓ9Ð9r&   )r)   r/   r4   r9   r=   ) Ú__doc__Ú
__future__r   Úcollections.abcr   r   r   Ú
nemo_relayr   Únemo_relay._contextr   Únemo_relay._nativer   r	   r
   r   r   r(   r   r.   r   r3   r   r<   r   r7   r)   r/   r4   r9   r=   Ú__all__r"   r&   r$   Ú<module>rE      sÿ   ðñõ& #ç /Ý å Ý 2÷ó õõõõõð
Bð "&ð	Bð
 )-ðBð ðBð !ðBð  $ðBð "&÷BðJ dð ð	 dð
 !ð dð "&÷ dðFMð
 "&ðMð )-ðMð ðMð !ðMð  $÷Mõ`7õ4:ò4 Y‚r&   