AgentTool#

Build typed tools from annotations and docstrings. See the guide.

class zett_agent.tools.base.AgentTool(name, description, parameters, handler, guidelines, snippet='', return_schema=None, execution_mode=ToolExecutionMode.PARALLEL, deferred=False, local_tool_search=False, returns_description='')[source]#

A tool is a name, an input schema, and an async callable.

Parameters:
  • name (str)

  • description (str)

  • parameters (dict[str, Any])

  • handler (Callable[[...], Awaitable[ToolResult]])

  • guidelines (tuple[str, ...])

  • snippet (str)

  • return_schema (dict[str, Any] | None)

  • execution_mode (ToolExecutionMode)

  • deferred (bool)

  • local_tool_search (bool)

  • returns_description (str)

name: str#

Unique name exposed to the model and used for dispatch.

description: str#

Natural-language purpose used by the model to select this tool.

parameters: dict[str, Any]#

JSON Schema describing this tool’s keyword arguments.

handler: Callable[[...], Awaitable[ToolResult]]#

Async handler that validates arguments and performs the local operation.

guidelines: tuple[str, ...]#

Model-facing rules rendered beside this tool in prompt guidance. Tools that share one rule through another channel, such as a server-level system message, may leave this empty so the rule is not repeated per tool.

snippet: str#

Optional invocation examples rendered into prompt guidance.

return_schema: dict[str, Any] | None#

JSON Schema describing this tool’s return value, when its function has a return annotation that can be described. None means the tool says nothing about its result. The value is never validated against a result; it only tells the model what to expect, and only when a renderer asks for it.

execution_mode: ToolExecutionMode#

Whether this local handler runs serially or may run in parallel.

deferred: bool#

Whether Responses API providers may defer loading this tool’s schema through tool search. Other provider protocols ignore this flag.

Whether this tool answers client-side tool search for one request.

A search tool is internal: the model never calls it directly. The Responses adapter declares tool_search with execution: "client" and routes every search request to this handler, whose result decides which tools the model may load. Other provider protocols reject it.

returns_description: str#

Prose describing the return value, taken from the docstring’s Returns section. Empty means the tool says nothing about its result in words. Like return_schema it is shown only to renderers that ask for return information; it ends the tool’s description, after its snippet and guidelines. It stays last among the fields so a caller that passes the others positionally keeps working.

async __call__(arguments)[source]#

Execute with a mapping of model-provided keyword arguments.

Parameters:

arguments (Mapping[str, Any]) – Input object validated by the decorated function’s schema.

Returns:

The function’s typed result before JSON serialization.

Return type:

ToolResult

Examples

Invoke a decorated tool from Python:

result = await read_file({"file_path": "README.md"})

Note

Decorated synchronous functions run in a worker thread; async functions are awaited directly. A manually supplied handler owns its validation policy.

serialize_result(value)[source]#

Convert Pydantic models, dataclasses, and plain values into JSON.

Strings pass through unchanged so plain-text tool results reach the model without JSON quoting.

Parameters:

value (ToolResult)

Return type:

str

sync(*, runtime=None)#

Return a context-managed synchronous view; optionally share a runtime.

Omitting runtime creates a new background thread for this view. Passing an existing runtime reuses its loop and leaves its shutdown to the caller. This API is for service entry points, not Extension lifecycle hooks.

Examples

Use a model or tool from a plain function:

with read_file.sync() as read:
    result = read({"file_path": "README.md"})
Parameters:

runtime (SyncRuntime | None)

Return type:

SyncObject[Self]