Skip to content

Simulator

relai.simulator.simulated(func)

Decorator to mark a function to be simulated using a mocker in simulation mode. All such functions must have a corresponding mocker set in the simulation configuration. Supports both synchronous and asynchronous functions.

relai.simulator.EnvGenerator

Bases: Protocol

Protocol for functions that generate simulation configurations. These functions take an optional RELAISample and return a SimulationConfigT which is a dictionary mapping qualified function names of functions decorated with @simulated to their respective mocker instances.

relai.simulator.random_env_generator(config_set)

An environment generator that uniformly samples a mocker for each simulated function from the provided set of mockers.

Parameters:

Name Type Description Default
config_set dict[str, Sequence[BaseMocker]]

A mapping from qualified function names to a sequence of possible mockers for that function.

required

relai.simulator.SyncSimulator(agent_fn, env_generator=None, benchmark=None, log_runs=True, client=None)

Bases: BaseSimulator

A simulator for synchronous agent functions.

Parameters:

Name Type Description Default
agent_fn SyncAgent

The synchronous agent function to be simulated.

required
env_generator EnvGenerator | None

An optional environment generator function. If not provided, a default generator that returns an empty configuration will be used. The default generator can only be used with simulations that don't require any mockers.

None
benchmark Benchmark | None

An optional benchmark to source simulation samples from.

None
log_runs bool

Whether to log the runs to the RELAI platform. Defaults to True.

True
client RELAI | None

A synchronous RELAI client for logging. Must be provided if log_runs is True.

None

rerun(simulation_tapes, group_id=None)

Rerun the simulator for a list of simulation tapes.

Parameters:

Name Type Description Default
simulation_tapes list[SimulationTape]

The list of simulation tapes to rerun. This allows for re-executing the agent in an environment identical to a previous run and is useful for debugging and optimization.

required
group_id str

An optional group ID to associate all runs together. If not provided, a new UUID will be generated.

None

run(num_runs, group_id=None)

Run the simulator for a specified number of times.

Parameters:

Name Type Description Default
num_runs int

The number of simulation runs to execute.

required
group_id str

An optional group ID to associate all runs together. If not provided, a new UUID will be generated.

None

relai.simulator.AsyncSimulator(agent_fn, env_generator=None, benchmark=None, log_runs=True, client=None)

Bases: BaseSimulator

A simulator for asynchronous agent functions.

Parameters:

Name Type Description Default
agent_fn AsyncAgent

The asynchronous agent function to be simulated.

required
env_generator EnvGenerator | None

An optional environment generator function. If not provided, a default generator that returns an empty configuration will be used. The default generator can only be used with simulations that don't require any mockers.

None
benchmark Benchmark | None

An optional benchmark to source simulation samples from.

None
log_runs bool

Whether to log the runs to the RELAI platform. Defaults to True.

True
client RELAI | None

A asynchronous RELAI client for logging. Must be provided if log_runs is True.

None

rerun(simulation_tapes, group_id=None) async

Rerun the simulator for a list of simulation tapes.

Parameters:

Name Type Description Default
simulation_tapes list[SimulationTape]

The list of simulation tapes to rerun. This allows for re-executing the agent in an environment identical to a previous run and is useful for debugging and optimization.

required
group_id str

An optional group ID to associate all runs together. If not provided, a new UUID will be generated.

None

run(num_runs, group_id=None) async

Run the simulator for a specified number of times.

Parameters:

Name Type Description Default
num_runs int

The number of simulation runs to execute.

required
group_id str

An optional group ID to associate all runs together. If not provided, a new UUID will be generated.

None