The mini-app¶
A mini-app is an AsyncFlow application in the shape Workflow Mini-Apps defines: its script builds the
engine and its telemetry, attaches a MiniApp to them, runs its workflow inside the MiniApp, and
owns the shutdown. AUTONMI does not take over the script. A Campaign adds the application's
populations of agents to the engine's graph, one node each, and registers what the run must check
with the MiniApp.
How a campaign runs¶
The execution model answers what happens, in order, when a campaign runs, and in which process on which node.
- Start. The campaign splits the agents into populations, and adds each one to the mini-app's AsyncFlow engine as a task. Under Dragon, RHAPSODY's native backend starts each population as a Dragon process on its node.
- A model turn. In each population, Flowgentic's agent host starts the agents in waves, and its loop runs each one (a scripted agent runs on AUTONMI's script runner instead). A model call goes through the population's fleet, which admits it within the caps, to a model server.
- A task tool. A task tool, such as a simulation, becomes a task of the population's own AsyncFlow engine, which runs it on a worker process of the node, on its CPUs or a GPU.
- A waiting agent. An agent can suspend while its tasks run: its state goes to the store, and it resumes with its tasks' values.
- An MCP tool. An MCP call goes through a tool service, on the mini-app's node, to the application's MCP servers.
- Rows and stats. Once every agent has ended, each population writes its rows and stats into the
run directory and returns them to the campaign.
check()then verifies the run.
Locally the same parts run in the mini-app's process: each population is an AsyncFlow block of the mini-app's engine, with an engine of its own on RHAPSODY's Concurrent backend; the simulations run on a pool of threads or processes, and the store is a dictionary.
A campaign's life¶
campaign = Campaign(flow, definition, CampaignConfig(run_dir=...), app=app)
await campaign.start_services() # the store, the application's MCP servers, the tool services
results = await campaign.run() # one AsyncFlow node per population; every agent to its end
await campaign.stop_services()
ok = campaign.check() # the application's checks and the campaign's, into the run's report
await campaign.close() # the store, the runtime's processes, the OpenTelemetry export
Campaign(...)refuses a run directory that already holds a run, and an unknown runtime, withValueError. It writescampaign.json(the application, its knobs, the configuration), and gives theMiniAppthe run's parameters. Locally, unlesstelemetry=None, it configures Flowgentic's OpenTelemetry export in this process, intootel/. A process is configured once: when the script or an earlier campaign configured it, the campaign warns and leaves it, and the run checks an export only if the script wrote one intootel/. Under Dragon each population configures its own, in its own process.start_services()first refuses most settings that cannot run (nodes and GPUs, see Placement), so nothing has started when it raises. Then it starts the services, and raisesTimeoutErrorif the tool services are not ready withinservice_timeout_s. A few settings are refused later, in a population's process, once the services and the other populations have started: see Placement.run()splitsdefinition.agents()in order intoCampaignConfig.populationscontiguous parts; the first parts get one agent more when the split is uneven. Each part runs as one population: an AsyncFlow block in this process locally, an AsyncFlow function task in a Dragon process of its own under Dragon. It returns the populations' results, in order. The populations run as one: when one fails,run()raisesRuntimeError, and pasttimeout_sTimeoutError(see Failures).stop_services()stops the tool services, writes their stats into the run'sservices/, then stops the application's MCP servers.check()runs the application'sverifyand the campaign's own checks, writesapp/checks.json, registers the run's components and checks with theMiniApp, and returns whether every check passed.close()stops what is still running, whatever failed before, and shuts down the OpenTelemetry export the campaign configured. Call it in afinally.
Each call's contract, what it raises and what it writes, is in the API reference.
After run() the workflow goes on as any AsyncFlow application: the script below counts the agents
in an ordinary function task of the mini-app's engine.
The script¶
A complete mini-app, with the conformance kit's toy application. It runs on a laptop:
"""The toy application as a mini-app: the script owns the engine, its telemetry and MiniApp.
Run it with a new run directory: `python docs/examples/toy_miniapp.py runs/toy-miniapp`.
"""
import asyncio
import sys
from concurrent.futures import ThreadPoolExecutor
from radical.asyncflow import WorkflowEngine
from rhapsody.backends import ConcurrentExecutionBackend
from wfMiniAPI.api import MiniApp
from autonmi import Campaign, CampaignConfig
from autonmi.assemble import assemble
from autonmi.conformance.toy import Toy
async def workflow(flow, app, run_dir: str) -> bool:
"""Add the populations to the graph, one node each, then an ordinary AsyncFlow task after them."""
campaign = Campaign(flow, Toy(agents=100), CampaignConfig(run_dir=run_dir, populations=2), app=app)
try:
await campaign.start_services() # the store, the application's MCP servers, the tool services
results = await campaign.run() # one AsyncFlow node per population; every agent to its end
await campaign.stop_services()
@flow.function_task
async def count(agents: list[int]) -> int: # an ordinary task of the mini-app's engine
return sum(agents)
print("agents:", await count([r.agents for r in results]))
return campaign.check() # the application's checks and the campaign's, into the run's report
finally:
await campaign.close() # the store, the runtime's processes, the OpenTelemetry export
async def main(run_dir: str) -> int:
"""Run the mini-app into `run_dir`, and return its exit status."""
backend = await ConcurrentExecutionBackend(ThreadPoolExecutor(4))
flow = await WorkflowEngine.create(backend=backend, work_dir=run_dir)
telemetry = await flow.start_telemetry(checkpoint_path=f"{run_dir}/launcher")
app = MiniApp(flow, telemetry)
ok = False
try:
async with app, flow.workflow_scope("toy"):
ok = await workflow(flow, app, run_dir)
finally:
try:
await flow.shutdown()
finally:
await telemetry.stop()
app.verify() # every part, component and check of the run
return 0 if ok and app.report.exit_hint == 0 else 1
if __name__ == "__main__":
run_dir = sys.argv[1]
rc = asyncio.run(main(run_dir))
summary = assemble(run_dir) # writes summary.json
print("checks pass:", summary["ok"])
sys.exit(rc or (0 if summary["ok"] else 1))
app.verify() checks every part, component and check of the run, and assemble writes the
run's summary from the verified report. See Telemetry and checks.
The example mini-app, examples/miniapp.py, has the same shape. It runs any application by its
factory, with options for the runtime, the model servers and the telemetry: see
the command line.
Rules¶
- The script owns the engine. Under Dragon the mini-app's engine runs on RHAPSODY's native Dragon backend, which starts each population as a process of its own.
- A run directory holds one run. Give each run a new one.
appmay be None: the populations then verify their own telemetry, and the campaign adds the checkpopulation_telemetry_complete. Nothing assembles the run.- The tool services and MCP servers are not AsyncFlow services yet: they become services of the graph once a backend implements service readiness.