GitHub

WithHandler

API reference for WithHandler.

A toolkit with its handlers: handle runs a tool call.

Attributes

AttributeTypeDescription
toolsMapping[str, AnyTool]
servicesContext[Any] = field(repr=False)

Functions

__init__

__init__(tools, services) -> None
ParameterTypeDescription
toolsMapping[str, AnyTool]
servicesContext[Any]

handle

handle(name, params, tool_call_id=None, options=None) -> Effect[Stream[HandlerResult, HE_co | AiError, R_co], AiError, R_co]

The results of calling the tool name with params (as the model sent them, decoded with options): preliminary values, then the final one. Invalid parameters, a handler failure or an invalid result fail the stream in "error" mode and are a failed result in "return" mode.

ParameterTypeDescription
namestr
paramsobject
tool_call_idstr | None = None
optionsS.ParseOptions | None = None

Returns Effect[Stream[HandlerResult, HE_co | AiError, R_co], AiError, R_co]

def handle(
    self,
    name: str,
    params: object,
    tool_call_id: str | None = None,
    options: S.ParseOptions | None = None,
) -> Effect[Stream[HandlerResult, HE_co | AiError, R_co], AiError, R_co]:
    """The results of calling the tool ``name`` with ``params`` (as the
    model sent them, decoded with ``options``): preliminary values, then
    the final one. Invalid parameters, a handler failure or an invalid
    result fail the stream in ``"error"`` mode and are a failed result in
    ``"return"`` mode."""
    return cast("Any", _handle(self, name, params, tool_call_id, options or {}))