Skip to content

autonmi

autonmi

AUTONMI: populations of agents as nodes of an AsyncFlow application, on Flowgentic.

A mini-app is an AsyncFlow application: its script owns the engine, its telemetry and its graph. AUTONMI adds populations of agents to that graph. Each population runs its agents on Flowgentic's agent host and loop, with its own AsyncFlow engine for the agents' tasks, and writes its telemetry into the run directory, where autonmi.assemble reads it back.

An application gives an AgentDefinition: how its agents decide, their tools, their knobs and their checks. autonmi.conformance.toy holds two small ones, a scripted and a tool-calling one.

Modules:

Name Description
agent

What an application gives AUTONMI, an agent definition, and the contract between the two.

assemble

Verify a run's rows and model servers, check the run's components together, and summarize it.

campaign

A campaign: an application's agents, in populations, as nodes of a mini-app's AsyncFlow graph.

conformance

Check an application's agent definition against AUTONMI's agent contract.

mcp

Helpers for an application's MCP server processes: free ports, waiting for a server, stopping them.

models

The model servers: finding the model job's servers, and the fleet's transports to them.

pools

Executors for a population's simulations on one machine, and the test for a task lost with its worker.

population

One population: a share of a campaign's agents, run together on an AsyncFlow engine of its own.

scripted

Scripted agents: the application's code chooses each step, and a model is one of its services.

store

Where agents keep their state and simulations their results: Flowgentic's stores, by spec.

telemetry

The process's OpenTelemetry, configured into the run directory: what Flowgentic contributes.

vllm

The model servers' own counters, sampled over a run.

Classes:

Name Description
AgentDefinition

An application, as AUTONMI runs it.

AgentSpec

One agent: its id and its first input (a string, or OpenAI-format messages).

Check

One of the application's checks on the run's result.

PopulationContext

What AUTONMI gives an application when it builds a population's agents.

ToolAgent

A tool-calling agent, run by Flowgentic's LoopRunner: the model chooses each step.

Campaign

An application's agents, run as populations on a mini-app's AsyncFlow engine.

CampaignConfig

A campaign's settings, recorded in the run's campaign.json.

PopulationConfig

How each population of a campaign runs (CampaignConfig.population).

PopulationResult

One population's rows and stats, as run_population wrote them.

ScriptedAgent

A scripted agent, as an application's build(pop) gives it to its population.

Telemetry

How a process's OpenTelemetry export is configured (configure).

AgentDefinition

Bases: Protocol

An application, as AUTONMI runs it.

Methods:

Name Description
agents

Return every agent of the campaign, in order: the same agents, with unique ids, on every call.

build

Build the agent of one population.

stub

Return a stub model, as a Flowgentic transport, for runs without model servers.

rows

Return one row per agent of the population, whatever its end, for the results and the checks.

verify

Check the whole campaign's rows, in the mini-app's process at Campaign.check().

services

Start the application's MCP servers, and return once each listens.

agents

agents() -> Iterable[AgentSpec]

Return every agent of the campaign, in order: the same agents, with unique ids, on every call.

Called in the mini-app's process at Campaign.run(), which splits them in order into populations, and again at Campaign.check().

build

build(pop: PopulationContext) -> Any

Build the agent of one population.

Called once in the population's process, before any of its agents starts.

Returns:

Type Description
Any

A ToolAgent, or an autonmi.scripted.ScriptedAgent.

stub

stub(replica: int) -> Any

Return a stub model, as a Flowgentic transport, for runs without model servers.

Called in the population's process after build, once per replica, when the population has no model. Its replies depend only on the agent (flowgentic.host.current_agent()) and the messages.

Parameters:

Name Type Description Default
replica int

Which of the population's stub replicas this is, from 0 to PopulationConfig.stub_replicas - 1.

required

rows

rows(pop: PopulationContext) -> list[dict]

Return one row per agent of the population, whatever its end, for the results and the checks.

Called once in the population's process, once every agent has ended. Each row carries agent_id and finished (the agent delivered its result: true only when its status is done), and anything else the application keeps. It may carry simulations, the application's own count of its agent's tasks that completed: the run checks it against AUTONMI's, agent by agent. AUTONMI adds the fields in ROW_FIELDS, which the application sets none of. Rows are written to <run>/app/agents-p<index>.jsonl.

verify

verify(rows: list[dict], store: Any) -> list[Check]

Check the whole campaign's rows, in the mini-app's process at Campaign.check().

Parameters:

Name Type Description Default
rows list[dict]

Every agent's row, population by population, with AUTONMI's fields.

required
store Any

The campaign's store, which the populations wrote to.

required

Returns:

Type Description
list[Check]

The application's checks. It does not raise: a failure is a Check that did not pass.

services

services(
    run_dir: Path, servers: int = 1
) -> tuple[list, list[str]]

Start the application's MCP servers, and return once each listens.

Called at Campaign.start_services(), in a thread of the mini-app's process, so it may block. The campaign stops the processes at stop_services(), with autonmi.mcp.stop_servers.

Parameters:

Name Type Description Default
run_dir Path

The directory for the servers' files, <run>/services, which may not exist yet.

required
servers int

How many servers to start.

1

Returns:

Type Description
list

The servers' processes (subprocess.Popen) and their URLs; ([], []) for an application

list[str]

without MCP servers.

AgentSpec dataclass

AgentSpec(id: str, input: Any)

One agent: its id and its first input (a string, or OpenAI-format messages).

Check dataclass

Check(name: str, ok: bool, detail: Any = None)

One of the application's checks on the run's result.

PopulationContext dataclass

PopulationContext(
    index: int,
    agent_ids: list[str],
    store: Any,
    store_spec: str,
    run_dir: Path,
    knobs: Any,
    state: dict = dict(),
)

What AUTONMI gives an application when it builds a population's agents.

ToolAgent dataclass

ToolAgent(
    system_prompt: str,
    tools: list,
    max_model_calls: int = 25,
    model_kwargs: dict = dict(),
    order: Any = None,
    on_task: Callable | None = None,
    on_done: Callable | None = None,
    on_call: Callable | None = None,
    nudge: Callable[[str], str | None] | None = None,
)

A tool-calling agent, run by Flowgentic's LoopRunner: the model chooses each step.

tools are Flowgentic task_tool and mcp_tool declarations and inline functions. Each tool runs where it declares: a task tool as a task on the population's engine, an MCP tool through the tool service, an inline function in the agent's process. order is the tool runtime's order policy (admission of tasks), on_task a listener on every task's record, on_done the host's callback for every agent that ends, on_call the fleet's listener on every model call. nudge is called with an agent's id when the agent ends (its model answered without a tool call): a message to send it, as the user, to go on with its conversation, or None. An agent is nudged at most once, as when a model ends without delivering its result.

Campaign

Campaign(
    flow: WorkflowEngine,
    definition: AgentDefinition,
    config: CampaignConfig,
    *,
    app: MiniApp | None = None,
)

An application's agents, run as populations on a mini-app's AsyncFlow engine.

A campaign's life is five calls, in this order: start_services, run, stop_services, check and close. Call close whatever happened before, in a finally. A run directory holds one campaign.

Constructing a campaign starts no service and no population, but it has side effects. It creates run_dir, writes campaign.json (the application's name, its knobs, the configuration, and the engine's uid as session), and gives app the run's parameters. Locally, with config.telemetry set, it configures this process's OpenTelemetry SDK (autonmi.telemetry.configure) to export into run_dir/otel/, until close shuts the export down. A process's SDK is configured once: when it already is, by the script or by an earlier campaign, the campaign warns and leaves it, and the run checks an export only if run_dir/otel/ holds one. Under Dragon each population configures its own export, in its own process, into run_dir/otel/<population>/.

Examples:

In a mini-app's script, which owns flow and app, and shuts them down:

campaign = Campaign(flow, definition, CampaignConfig(run_dir="runs/a"), app=app)
try:
    await campaign.start_services()
    await campaign.run()
    await campaign.stop_services()
    ok = campaign.check()
finally:
    await campaign.close()

Parameters:

Name Type Description Default
flow WorkflowEngine

The mini-app's engine. The campaign adds one node per population to its graph, and neither starts it nor shuts it down.

required
definition AgentDefinition

The application.

required
config CampaignConfig

The campaign's settings.

required
app MiniApp | None

The run's wfMiniAPI MiniApp. None: each population verifies its own telemetry, check adds the check population_telemetry_complete, and nothing assembles the run.

None

Raises:

Type Description
ValueError

run_dir already holds a run (campaign.json, app/, populations/ or otel/); runtime is neither "local" nor "dragon"; or, under Dragon, store_manager_gib is over 2, or store_timeout_s is neither None nor a positive number.

Attributes:

Name Type Description
flow

The mini-app's engine.

app

The run's MiniApp, or None.

definition

The application.

config

The campaign's settings.

run_dir

config.run_dir, as a Path.

runtime

The runtime config.runtime names. Its nodes are the runtime's nodes by hostname, the mini-app's first.

store

The campaign's store in this process, a Flowgentic KeyValueStore: in memory, and under Dragon on RaDEX once start_services has started it.

results list[PopulationResult]

The populations' results, in order; empty until run returns.

checks list[Check]

The checks check made; empty until it runs.

failure dict | None

Why the populations did not all end, as run wrote it into app/failure.json before it raised; None until then.

Methods:

Name Description
start_services

Start the store under Dragon, the application's MCP servers and the tool services.

stop_services

Stop the tool services, then the application's MCP servers, even when the first fails.

close

Stop what still runs, and release what the campaign holds, whatever failed before.

run

Run every agent to its end, one AsyncFlow node per population on the mini-app's engine.

rows

Return every agent's row, population by population; none unless run returned.

check

Check the run: the application's checks, then the campaign's own.

store_spec property

store_spec: str

The spec another process opens the campaign's store with (autonmi.store.open_store).

memory:<name> locally, and under Dragon until start_services starts RaDEX; then radex:<descriptor>. A task of the mini-app's that reads what the agents stored opens it.

start_services async

start_services() -> None

Start the store under Dragon, the application's MCP servers and the tool services.

First refuse the node and GPU settings that cannot run, so that nothing has started when that raises. Then, under Dragon, start RaDEX, which becomes store and store_spec. Start the application's MCP servers (definition.services(run_dir / "services", mcp_servers)) and, when they have URLs, the tool services: one per population, up to toolservices. Wait for each tool service to report that it is ready. An application without MCP servers gets no tool service. What definition.services raises, this raises. Once it has returned, a failure leaves what has started running, for close to stop.

Raises:

Type Description
RuntimeError

Under Dragon on several nodes, the populations have CPU workers and RHAPSODY's native backend has no hosts=; or a tool service failed as it started.

ValueError

The GPU settings (simulation_gpus, population.gpus) do not hold on the runtime's nodes.

TimeoutError

The tool services did not all report ready within service_timeout_s; or, under Dragon, the store failed to start within store_timeout_s.

stop_services async

stop_services() -> None

Stop the tool services, then the application's MCP servers, even when the first fails.

Call it once run has returned or raised. Each tool service reports its stats as it stops, and writes its calls' times into run_dir/services/toolservice-<k>-times.npy. Once every one has reported, write each one's stats into run_dir/services/toolservice-<k>.json; on a timeout or a failure, none is written. A second call does nothing: what did not stop is left to close.

Raises:

Type Description
TimeoutError

The tool services did not all report done within service_timeout_s.

RuntimeError

A tool service failed.

close async

close() -> None

Stop what still runs, and release what the campaign holds, whatever failed before.

Stop the services if they still run (after a start_services or a run that raised), with a warning if they do not stop cleanly. Stop the runtime: join its threads or its Dragon processes, and under Dragon shut RaDEX down. Shut down the threads that ran store calls (autonmi.store.awaited), drop the in-memory store, and flush and shut down the OpenTelemetry export that construction configured. What stopping the runtime raises, close raises, once the store and the export are released.

run async

run() -> list[PopulationResult]

Run every agent to its end, one AsyncFlow node per population on the mini-app's engine.

Split definition.agents() in order into populations contiguous parts, the first ones larger by one when the split is uneven, and run each part as a population: an AsyncFlow block in this process locally, an AsyncFlow function task in a Dragon process of its own under Dragon. With app, each population that keeps RHAPSODY's telemetry reports into its part of the run (p000, p001, ...). The populations write their rows and records into the run directory. Once every agent has ended, flush this process's OpenTelemetry export.

The populations run as one. When one fails, or they outlast timeout_s, cancel the others, wait for them to end for at most cancel_grace_s, write why into app/failure.json (and every thread's stack into campaign-stacks.txt on a timeout), fail the run's check every_population_ran with app, and raise. Locally a cancelled population still waits for the simulations it has running, which a thread cannot stop: one still running after cancel_grace_s is listed as abandoned in app/failure.json, and runs on until they end. Under Dragon, RHAPSODY's native backend ends a cancelled population's process.

Returns:

Type Description
list[PopulationResult]

The populations' results, in order; also kept in results.

Raises:

Type Description
RuntimeError

A population failed. Its exception is the cause: the lowest-numbered population's, when several failed.

TimeoutError

The populations outlasted timeout_s.

rows

rows() -> list[dict]

Return every agent's row, population by population; none unless run returned.

check

check() -> bool

Check the run: the application's checks, then the campaign's own.

The application's are definition.verify(rows, store). The campaign's are every_agent_has_a_row, every_done_agent_has_its_result and, without app, population_telemetry_complete. Write them all into app/checks.json, keep them in checks, and emit each as an autonmi.Check event on the engine's telemetry, when it has one. With app, register the run's components and checks with it, so that the run's app.verify() checks the whole run.

Returns:

Type Description
bool

Whether every check passed.

CampaignConfig dataclass

CampaignConfig(
    run_dir: str,
    populations: int = 1,
    population: PopulationConfig = PopulationConfig(),
    mcp_clients: int = 8,
    mcp_per_client: int = 16,
    service_timeout_s: float = 120.0,
    runtime: str = "local",
    mcp_servers: int = 4,
    toolservices: int = 8,
    telemetry: Telemetry | None = Telemetry(),
    timeout_s: float | None = None,
    cancel_grace_s: float = 60.0,
    store_managers: int = 4,
    store_manager_gib: float = 2.0,
    store_timeout_s: float | None = STORE_TIMEOUT_S,
    simulation_gpus: list[int]
    | str
    | dict[str, list[int] | str]
    | None = None,
)

A campaign's settings, recorded in the run's campaign.json.

Attributes:

Name Type Description
run_dir str

The run directory. It must not hold a run. Under Dragon across nodes, it must be on a filesystem every node shares.

populations int

How many populations the agents are split into.

population PopulationConfig

How each population runs. The campaign sets share and host for each population, gpus when simulation_gpus is set, and under Dragon backend and otel.

mcp_clients int

MCP clients per tool service; a service has at least one per MCP server.

mcp_per_client int

Calls in flight on each MCP client.

service_timeout_s float

Seconds the tool services get to report that they are ready (Campaign.start_services), and again that they are done (Campaign.stop_services).

runtime str

Where the store, the tool services and the populations run. "local": the store in memory, the tool services as threads on queue.Queues, the populations as AsyncFlow blocks in the mini-app's process. "dragon": the store on RaDEX, the tool services as Dragon processes on Dragon queues, and each population as an AsyncFlow function task that RHAPSODY's native backend starts as a Dragon process of its own; the mini-app's engine must then run on RHAPSODY's native backend.

mcp_servers int

How many MCP servers the application starts (AgentDefinition.services).

toolservices int

The most tool services: one per population, up to this many. Population i uses service i mod min(toolservices, populations).

telemetry Telemetry | None

Flowgentic's OpenTelemetry export, configured in every process that runs agents. The default keeps a tenth of the agents' spans; Telemetry.every_span() keeps every span, for runs that compare spans with calls. None: the campaign configures none. Locally the script may then configure OpenTelemetry itself; under Dragon the populations export nothing, and the run checks neither the export nor what reads it (the fleets' calls, the tokens).

timeout_s float | None

Seconds the populations get, all together. Past them they are cancelled and Campaign.run raises TimeoutError. None: no limit.

cancel_grace_s float

Seconds cancelled populations get to end, after which the campaign stops waiting for them.

store_managers int

Under Dragon, RaDEX's managers on every node.

store_manager_gib float

Under Dragon, each RaDEX manager's memory in GiB, at most 2.

store_timeout_s float | None

Under Dragon, the store's timeout, Dragon's DDict timeout, in seconds. Each of a RaDEX manager's sends and receives waits at most this long: a manager whose reply waits on a client that stopped reading, as on a slow node, gives up on it and serves its other clients. Keep it below the clients' own timeout, 30 s in Flowgentic's RadexStore, which it does not change, so that a stuck manager frees itself before its other clients give up. Dragon bounds the store's start with it too: give a larger allocation more if its start fails (start_services raises TimeoutError). None: no limit, Dragon's default.

simulation_gpus list[int] | str | dict[str, list[int] | str] | None

The simulations' GPUs on each node, as the job numbers them on that node, shared among the populations on the node. None: CPUs. "all": every GPU the job has on each node, when the model servers run in a job of their own. A list: the same GPUs on every node, those the model servers leave in this job. A dict, from node to "all" or a list: per node, naming every node that runs populations.

PopulationConfig dataclass

PopulationConfig(
    workers: int = 8,
    stagger_batch: int = 100,
    stagger_interval_s: float = 0.5,
    gc_threshold: int = 100000,
    cap_requests: int = 96,
    cap_tokens: int = 235000,
    reply_reserve: int = 64,
    stub_replicas: int = 1,
    share: float = 1.0,
    resource_poll_interval: float = 1.0,
    reuse_event_loop: bool = False,
    backend: Literal["concurrent", "dragon"] = "concurrent",
    executor: str | None = None,
    gpus: list[int] | None = None,
    gpu_slots: int = 1,
    host: str | None = None,
    retries: int = 2,
    max_retries: int | None = None,
    rhapsody_telemetry: bool = True,
    node_samplers: bool | None = None,
    max_live: int | None = None,
    model: ModelSettings | None = None,
    otel: Telemetry | None = None,
)

How each population of a campaign runs (CampaignConfig.population).

The campaign gives each population a copy with share, host and gpus set for it, and under Dragon backend and otel. A setting applies to both backends and to both kinds of agent unless it says otherwise. "Locally" is the Concurrent backend, in the mini-app's process; "under Dragon" is RHAPSODY's native backend, in a Dragon process of the population's own.

Attributes:

Name Type Description
workers int

Simulation workers. Locally, the threads of the default pool, or the argument of executor's factory; not used with gpus. Under Dragon, the native backend's CPU workers on each of its nodes; 0 starts none, for a population whose simulations all run on GPUs.

stagger_batch int

Agents the host starts at once in its first wave, which is up to max_live agents. Later agents start as places free up.

stagger_interval_s float

Seconds between the first wave's batches.

gc_threshold int

The cyclic garbage collector's first threshold while the agents run (Flowgentic's Collector).

cap_requests int

Requests in flight per model replica, split among the populations by share.

cap_tokens int

Tokens of live context in flight per model replica, split among the populations by share. 0: the fleet admits by cap_requests only.

reply_reserve int

Tokens the fleet adds to each call's estimate for its reply, when it admits by tokens.

stub_replicas int

Replicas of the application's stub, definition.stub(r) for each r; without model only.

share float

This population's share of each replica's caps, in (0, 1]. The campaign sets it to 1/n for n populations.

resource_poll_interval float

Seconds between the resource samples of RHAPSODY's telemetry.

reuse_event_loop bool

Locally, one event loop per worker thread for the simulations, instead of one asyncio.run per task. It needs a RHAPSODY whose ConcurrentExecutionBackend takes reuse_event_loop; with another, the population raises TypeError as it starts. Not used under Dragon.

backend Literal['concurrent', 'dragon']

"concurrent", RHAPSODY's Concurrent backend in this process, or "dragon", RHAPSODY's native backend, for a population in a Dragon process of its own.

executor str | None

Locally, "module:function": a function of workers that returns the simulations' executor, such as "autonmi.pools:spawn_pool" for spawned processes that see no GPU. None: a thread pool. Not with gpus; not used under Dragon.

gpus list[int] | None

The population's GPUs, as the job numbers them on its node; each simulation's task runs on one of them. Locally, any number: one pool of gpu_slots spawned workers per GPU (autonmi.pools.GpuPools). Under Dragon, GPUs that Dragon lists on the population's node; a population of tool-calling agents takes one. None: no GPU; where the simulations run in processes of their own (under Dragon, or locally on a process pool), each task hides the GPUs from its worker. The campaign's simulation_gpus splits GPUs among the populations instead.

gpu_slots int

Simulations at once on each GPU; at least 1.

host str | None

Under Dragon on several nodes, the node the population runs on, set by the campaign: its process, its backend's workers and its GPUs are that node's. None: nothing is placed.

retries int

Scripted agents only. Runs again, at most, of a simulation whose worker died (autonmi.pools.lost), with the same call and arguments. A simulation's own errors never run again.

max_retries int | None

Scripted agents only. Runs again, at most, over all the population's agents; past it, a lost simulation gives no value: it fails its agent, or with task_errors="value" its step gets a TaskFailed. None: no cap. A population of tool-calling agents warns and does not use it.

rhapsody_telemetry bool

RHAPSODY's telemetry for the population's engine, its checkpoint (populations/p<index>/rhapsody/) and the population's part of the run's MiniApp. False: none of them, and the run's checks leave the population's checkpoint out.

node_samplers bool | None

Under Dragon, with rhapsody_telemetry: whether RHAPSODY's telemetry samples the nodes' resources, with one sampler process per node of the runtime. False: the checkpoint keeps its tasks' events and no node resources. None: yes without a host, no with one, where the mini-app's own engine samples every node.

max_live int | None

Agents live at once, suspended ones included. None: all of them.

model ModelSettings | None

The model servers (autonmi.models.wait_for_servers). None: the application's stub.

otel Telemetry | None

OpenTelemetry settings: the population configures an export with them in its process, into otel/p<index>/. The campaign sets them under Dragon, where that process is the population's own. None: the population configures none; locally the campaign configures one for its process.

Raises:

Type Description
ValueError

gpu_slots is below 1.

PopulationResult dataclass

PopulationResult(
    index: int,
    agents: int,
    rows: list[dict],
    stats: dict = dict(),
    telemetry: dict = dict(),
)

One population's rows and stats, as run_population wrote them.

Attributes:

Name Type Description
index int

The population's index, as its files' names carry it.

agents int

How many agents it ran, whatever their end.

rows list[dict]

One row per agent, the application's fields and AUTONMI's (autonmi.agent.ROW_FIELDS), as in app/agents-p<index>.jsonl.

stats dict

What populations/p<index>/population.json holds: the agents by how they ended, the host's states and loop lag, the runner's counts, the tasks, the fleet's calls, model outages, tasks lost to dead workers, and the node the population ran on.

telemetry dict

The check of the population's RHAPSODY telemetry, as in stats["telemetry"]: checked, and the report of its MiniApp part or of its checkpoint, or why it was not checked.

ScriptedAgent dataclass

ScriptedAgent(
    start: Callable[[str, Any], dict],
    step: Callable[..., Any],
    simulate: Any,
    lookup: Callable[[str, Any], Awaitable[Any]]
    | None = None,
    remember: Callable[[str, Any], None] | None = None,
    report: Callable[[str, Any], None] | None = None,
    model_calls_limit: int = 100,
    task_errors: Literal["raise", "value"] = "raise",
    order: Any = None,
    on_task: Callable | None = None,
    on_done: Callable | None = None,
    on_call: Callable | None = None,
)

A scripted agent, as an application's build(pop) gives it to its population.

The population calls start once per agent, then step with each event until a step returns Done. Every callback runs in the population's process, on its event loop.

What the application promises, beside the agent definition's (autonmi.agent):

  • The state is plain data that pickles, and changes only through what step returns: when the agent suspends, the next step gets the store's copy, not the object the step returned.
  • step gives the same action for the same state and event (and the same model replies), so that an agent's result does not depend on whether it suspended or on its population.
  • A call_id is used once per agent, and a simulation is safe to run again for the same call.
  • A step never catches asyncio.CancelledError: a cancelled run ends its agents as cancelled.
  • It should keep everything the agent needs to go on in the state or the store, not in the population's memory (closures, pop.state). Not required yet: it will be, once an agent can resume in another process.

Attributes:

Name Type Description
start Callable[[str, Any], dict]

(agent_id, input) -> state: the agent's first state, from its spec's input.

step Callable[..., Any]

(state, event) -> (state, action), or a coroutine function (state, event, ask) -> (state, action) that may call the model with ask (Ask) in the middle of its own code. An object whose __call__ is a coroutine function counts as one. The first step's event is None. A plain function that returns an awaitable fails its agent (TypeError).

simulate Any

The Flowgentic task_tool that Simulate and SimulateAll run on the population's engine.

lookup Callable[[str, Any], Awaitable[Any]] | None

async (agent_id, what) -> result, awaited for each Lookup.

remember Callable[[str, Any], None] | None

(agent_id, value), called for each Remember.

report Callable[[str, Any], None] | None

(agent_id, result), called for each Report.

model_calls_limit int

Model calls per agent, at most, over its whole run, by Model and ask together; one more fails the agent (RuntimeError).

task_errors Literal['raise', 'value']

What a simulation that fails, or is cancelled, gives its agent. "raise": the agent fails (SimulationFailed). "value": the step gets a TaskFailed in the task's place, and decides. Anything else is refused (ValueError) when the population starts.

order Any

The tool runtime's order policy (Flowgentic's TaskOrder), which decides when the population's tasks are submitted. None: at once.

on_task Callable | None

A listener on the record of each of the population's tasks (Flowgentic's TaskRecord), as each ends.

on_done Callable | None

(result, output): called as each agent ends, with Flowgentic's AgentResult and Done's output (None for an agent not done).

on_call Callable | None

(record, reply): called after each model call that completes, with Flowgentic's CallRecord and Reply.

Telemetry dataclass

Telemetry(
    span_ratio: float = 0.1,
    interval_s: float = 10.0,
    span_queue: int = 65536,
    exemplars: bool = False,
)

How a process's OpenTelemetry export is configured (configure).

Attributes:

Name Type Description
span_ratio float

The share of agents whose traces are kept, as ParentBased(TraceIdRatioBased(span_ratio)). 1.0: the SDK's default sampler, every span unless OTEL_TRACES_SAMPLER says otherwise; 0: no tracer provider, metrics only.

interval_s float

Seconds between metric exports.

span_queue int

Spans the span processor's queue holds; the SDK's default, 2,048, drops a burst of them.

exemplars bool

Whether metrics keep exemplars of the values recorded in sampled spans.

Methods:

Name Description
every_span

Return settings that keep every span, with metrics every interval_s seconds.

sampled property

sampled: bool

Whether only some agents' spans are kept: span_ratio strictly between 0 and 1.

every_span classmethod

every_span(interval_s: float = 1.0) -> Telemetry

Return settings that keep every span, with metrics every interval_s seconds.

For runs that compare spans with calls.