xr_ai_tools#

Toolkit-independent native XR tools.

Submodules#

Classes#

AsyncTool

A validated asynchronous tool independent of any output transport.

Tool

A Pydantic-validated tool shared by agents, voice, and background triggers.

ToolInvocationResult

A model-visible result from one local tool invocation.

ToolSet

A native tool catalog with model-visible dispatch names.

Package Contents#

class xr_ai_tools.AsyncTool(
name: str,
description: str,
request_model: type[RequestT],
chunk_model: type[ChunkT],
handler: collections.abc.Callable[[RequestT], collections.abc.AsyncIterator[ChunkT]],
)#

A validated asynchronous tool independent of any output transport.

async stream(
request: RequestT | collections.abc.Mapping[str, object],
) collections.abc.AsyncIterator[ChunkT]#

Validate and yield chunks produced in an isolated Relay tool scope.

The producer task owns the scope and handler cleanup; chunks are yielded in the consumer’s context. Parent scope-local registrations are not transferred into the isolated context.

class xr_ai_tools.Tool(
name: str,
description: str,
request_model: type[RequestT],
result_model: type[pydantic.BaseModel] | None,
handler: collections.abc.Callable[[RequestT], collections.abc.Awaitable[ResultT] | ResultT],
*,
return_direct: bool = False,
render_result: collections.abc.Callable[[ResultT], str] | None = None,
)#

A Pydantic-validated tool shared by agents, voice, and background triggers.

async execute(request: RequestT) ResultT#

Run one validated request through the shared Relay tool lifecycle.

async invoke(arguments: str) ToolInvocationResult#

Validate and run one model-supplied JSON argument payload.

class xr_ai_tools.ToolInvocationResult#

A model-visible result from one local tool invocation.

content: str#

Model-visible serialized result or validation error.

return_direct: bool#

Whether the agent should return the content without another model turn.

class xr_ai_tools.ToolSet(
tools: collections.abc.Iterable[Tool[Any, Any]] | collections.abc.Mapping[str, Tool[Any, Any]],
)#

A native tool catalog with model-visible dispatch names.

classmethod namespaced(
namespaces: collections.abc.Mapping[str, collections.abc.Iterable[Tool[Any, Any]]],
) ToolSet#

Build a catalog named <namespace>__<tool> for each group.

get(name: str) Tool[Any, Any] | None#

Return the named tool when this catalog owns it.

items() tuple[tuple[str, Tool[Any, Any]], Ellipsis]#

Return model-visible names paired with their underlying tools.