Skip to main content

Class

Overview

ToolSpec describes a tool’s interface as JSON Schema. It is used by SyntheticWorld to tell the backend what kind of response to generate. In most cases you don’t create ToolSpec manually — the @world.tool decorator calls ToolSpec.from_function() automatically. Use ToolSpec directly when you need full control over the schema.

Constructor

string
required
Tool name. Used as the identifier in world.call().
string
required
Human-readable description of what the tool does.
dict
required
JSON Schema for the tool’s input parameters.
dict
required
JSON Schema for the tool’s return value.
list[str] | None
default:"None"
Ordered parameter names for positional argument mapping. Set automatically by from_function().

Methods

from_function(fn)

Extracts a ToolSpec from a Python function using its type hints and docstring. Type mapping: Parameters with default values are marked as optional. Parameters without defaults are required.

to_schema()

Returns the full schema as a dictionary with name, description, parameters, and returns keys.

build_input(*args, **kwargs)

Maps positional and keyword arguments to a dictionary using the parameter names. Used internally by the @world.tool decorator.

Examples

Manual schema

From function

See Also