Overview
Synthetic Worlds let you develop and test agents that use tools — without calling the real tools. Instead of hitting live APIs, databases, or services, your tool calls get realistic responses generated on the fly. This is useful when:- Real tools are slow or expensive — external APIs, database writes, third-party services
- You need deterministic behavior — reproducible runs for debugging and CI
- The real service doesn’t exist yet — build your agent against the contract, not the implementation
- You want to test failure handling — simulate timeouts, errors, and rate limits
How it works
You create a world — an isolated session that intercepts your tool calls and returns generated responses. Define your tools as normal Python functions with type hints. The SDK extracts the schema automatically and sends it to the backend, which generates a realistic response that matches the return type.with block exits, the world is destroyed and resources are freed.
Setup
1. Set environment variables
2. Create a world and register tools
Registering tools
Using the @world.tool decorator
The simplest way. Your function’s type hints and docstring become the tool schema automatically:
- name from the function name (
search_products) - description from the docstring (
Search the product catalog.) - parameters from the type hints (
query: strrequired,limit: intoptional with default) - return type from the return annotation (
dict)
search_products("shoes", limit=5) routes through the synthetic backend and returns a generated response.
Using register_tool
For cases where you need manual control over the schema:
Generation modes
Control how responses are generated by setting themode parameter:
| Mode | Description | Use case |
|---|---|---|
schema_only | Generates responses from the tool schema alone | Fast iteration, no trace history needed |
examples | Grounds generation in real tool call examples from your traces | More realistic responses based on actual production data |
stateful | Remembers prior calls within the session | Multi-step workflows where consistency matters |
Deterministic output
Pass aseed for reproducible responses. The same seed, tool, and input produce the same output every time:
Simulating failures
Test your agent’s error handling by injecting failures:timeout, internal_error, rate_limit, not_found, bad_request.
Idempotency
Pass anidempotency_key to cache responses. Repeated calls with the same key return the cached result without hitting the backend:
Resetting a world
Reset the step counter and optionally clear all cached and stateful data:Choosing a model
By default, the backend picks the generation model. You can override it:Full example
See Also
- create_synthetic_world() — Full parameter reference
- ToolSpec — Manual schema construction
- Testing — Write tests without real API calls

