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 |
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 |
PopulationConfig |
How each population of a campaign runs ( |
PopulationResult |
One population's rows and stats, as |
ScriptedAgent |
A scripted agent, as an application's |
Telemetry |
How a process's OpenTelemetry export is configured ( |
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 |
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 |
stub
¶
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
|
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 |
services
¶
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, |
required |
servers
|
int
|
How many servers to start. |
1
|
Returns:
| Type | Description |
|---|---|
list
|
The servers' processes ( |
list[str]
|
without MCP servers. |
AgentSpec
dataclass
¶
One agent: its id and its first input (a string, or OpenAI-format messages).
Check
dataclass
¶
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 |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Attributes:
| Name | Type | Description |
|---|---|---|
flow |
The mini-app's engine. |
|
app |
The run's |
|
definition |
The application. |
|
config |
The campaign's settings. |
|
run_dir |
|
|
runtime |
The runtime |
|
store |
The campaign's store in this process, a Flowgentic |
|
results |
list[PopulationResult]
|
The populations' results, in order; empty until |
checks |
list[Check]
|
The checks |
failure |
dict | None
|
Why the populations did not all end, as |
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 |
check |
Check the run: the application's checks, then the campaign's own. |
store_spec
property
¶
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 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 |
ValueError
|
The GPU settings ( |
TimeoutError
|
The tool services did not all report ready within |
stop_services
async
¶
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 |
RuntimeError
|
A tool service failed. |
close
async
¶
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 |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
A population failed. Its exception is the cause: the lowest-numbered population's, when several failed. |
TimeoutError
|
The populations outlasted |
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.
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 |
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
( |
runtime |
str
|
Where the store, the tool services and the populations run. |
mcp_servers |
int
|
How many MCP servers the application starts ( |
toolservices |
int
|
The most tool services: one per population, up to this many. Population |
telemetry |
Telemetry | None
|
Flowgentic's OpenTelemetry export, configured in every process that runs agents.
The default keeps a tenth of the agents' spans; |
timeout_s |
float | None
|
Seconds the populations get, all together. Past them they are cancelled and
|
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 |
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. |
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
|
stagger_batch |
int
|
Agents the host starts at once in its first wave, which is up to |
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 |
cap_requests |
int
|
Requests in flight per model replica, split among the populations by |
cap_tokens |
int
|
Tokens of live context in flight per model replica, split among the populations
by |
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, |
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 |
backend |
Literal['concurrent', 'dragon']
|
|
executor |
str | None
|
Locally, |
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 |
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
( |
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
|
rhapsody_telemetry |
bool
|
RHAPSODY's telemetry for the population's engine, its checkpoint
( |
node_samplers |
bool | None
|
Under Dragon, with |
max_live |
int | None
|
Agents live at once, suspended ones included. None: all of them. |
model |
ModelSettings | None
|
The model servers ( |
otel |
Telemetry | None
|
OpenTelemetry settings: the population configures an export with them in its process,
into |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
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 ( |
stats |
dict
|
What |
telemetry |
dict
|
The check of the population's RHAPSODY telemetry, as in |
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
stepreturns: when the agent suspends, the next step gets the store's copy, not the object the step returned. stepgives 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_idis 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]
|
|
step |
Callable[..., Any]
|
|
simulate |
Any
|
The Flowgentic |
lookup |
Callable[[str, Any], Awaitable[Any]] | None
|
|
remember |
Callable[[str, Any], None] | None
|
|
report |
Callable[[str, Any], None] | None
|
|
model_calls_limit |
int
|
Model calls per agent, at most, over its whole run, by |
task_errors |
Literal['raise', 'value']
|
What a simulation that fails, or is cancelled, gives its agent. |
order |
Any
|
The tool runtime's order policy (Flowgentic's |
on_task |
Callable | None
|
A listener on the record of each of the population's tasks (Flowgentic's
|
on_done |
Callable | None
|
|
on_call |
Callable | None
|
|
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
|
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 |
sampled
property
¶
Whether only some agents' spans are kept: span_ratio strictly between 0 and 1.