Tool Registry

ractogateway.tools — Tool Registry & Schema Builder.

Provides a ToolRegistry that accepts standard Python functions (via a @tool decorator) or Pydantic models and translates them into provider-specific tool/function-calling schemas.

class ractogateway.tools.ToolRegistry[source]

Bases: object

A registry that collects tools and exposes them as canonical schemas.

Usage:

registry = ToolRegistry()

@registry.register
def get_weather(city: str, unit: str = "celsius") -> str:
    '''Get the current weather for a city.'''
    ...

# Or register a Pydantic model:
registry.register(WeatherRequest)

# Iterate schemas:
for schema in registry.schemas:
    print(schema.name)
get_callable(name)[source]

Look up the original callable by tool name.

Return type:

Callable[..., Any] | None

get_schema(name)[source]

Look up a single tool schema by name.

Return type:

ToolSchema | None

register(target=None, *, name=None, description=None)[source]

Register a function or Pydantic model as a tool.

Works as a decorator (@registry.register) or as a direct call (registry.register(MyModel)).

Return type:

Callable[..., Any] | type[BaseModel]

property schemas: list[ToolSchema]

Return all registered tool schemas.

class ractogateway.tools.ToolSchema(**data)[source]

Bases: BaseModel

Provider-agnostic canonical representation of a callable tool.

description: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
parameters: list[ParamSchema]
to_json_schema()[source]

Return an OpenAI-compatible JSON Schema parameters object.

Return type:

dict[str, Any]

ractogateway.tools.tool(fn=None, *, name=None, description=None)[source]

Decorator that marks a function as an LLM-callable tool.

Can be used bare (@tool) or with overrides (@tool(name="my_tool", description="…")).

The decorated function gains a _tool_schema attribute containing the canonical ToolSchema.

Return type:

Callable[..., Any]