Skip to content

Agent definitions

An application gives AUTONMI an agent definition: an object that says what its agents are, how they decide, what they record, and how the run checks them. The protocol is autonmi.agent.AgentDefinition (API). The contract numbers what each side guarantees.

Members

Member Called Returns
name, knobs when the campaign is made the application's name; its settings, recorded with the run
agents() at run(), and again at check() every agent as an AgentSpec(id, input), in order
services(run_dir, servers) at start_services(), with run_dir the run's services/ the MCP servers it started: (processes, urls); ([], []) for none
build(pop) once in each population's process, before any agent starts the population's agent: a ToolAgent or a ScriptedAgent
stub(replica) for each stub replica, in the population's process a stub model, as a Flowgentic transport
rows(pop) once every agent of the population has ended one row per agent
verify(rows, store) at check() the application's checks, a list of Check(name, ok, detail)

pop is a PopulationContext: the population's index, its agent ids, the store and its spec, the run directory, the knobs, and state, a dictionary for the application's own per-population state.

Two kinds of agents

Who picks each step decides the kind. Roles, such as a screener or a planner, are the application's: prompts, tools and a place in its workflow, on either kind.

A tool-calling agent (autonmi.agent.ToolAgent): the model picks each step. Flowgentic's LoopRunner runs it on OpenAI-format messages. It has a system prompt, tools (Flowgentic task_tool and mcp_tool declarations, and inline functions) and a limit of model calls (25 by default). A task tool runs as a task on the population's engine, an MCP tool through the tool service, an inline function in the agent's process. A failed task's error goes back to the model, which may call again. nudge, if given, may send an agent that ended without a tool call one more message, once.

A scripted agent (autonmi.scripted.ScriptedAgent): the application's code picks each step, and the model is one of its services. It is a step function over a state that pickles:

state = agent.start(agent_id, input)
state, action = agent.step(state, event)  # event: the result of the previous action
state, action = await agent.step(state, event, ask)  # or a coroutine, which may call the model
Action What it does The next event
Model(messages) a model call through the fleet the reply's text
Simulate(args, call_id) a task of the simulate tool on the population's engine; the agent suspends while it runs if the tool says so the task's value
SimulateAll(calls) several tasks at once, a fan-out with a barrier their values, in order
Lookup(what) the agent's lookup callback, inline its result
Remember(value), Report(result) the remember and report callbacks None
Done(output) the agent ends

A step that is a coroutine gets ask(messages, **kwargs), the fleet bound to its agent, and can call the model in the middle of its own code. Only simulations need to be actions: they are where an agent suspends. A simulation that fails or is cancelled fails its agent (task_errors="raise", the default); with task_errors="value" the step gets a TaskFailed in the value's place and decides.

The contract

Each clause has a number. The conformance kit prints it, with the clause's text, beside each failure that breaks the clause. A clause keeps its number when its words change, a new clause takes the next number, and a number is never reused.

The definition

  • C1. The definition has name, knobs, agents(), build(pop), rows(pop), verify(rows, store), stub(replica) and services(run_dir, servers).
  • C2. build(pop) returns a ToolAgent (the model picks each step) or a ScriptedAgent (the application's code does).
  • C3. The definition, its factory, its task functions and what it hands to a task live at a module's top level and pickle: under Dragon each population's process receives the definition pickled.
  • C4. agents() gives the same agents, with unique string ids, in the same order, every time it is called, and their inputs pickle.
  • C5. build(pop) only sets up; per-population state goes in pop.state.
  • C6. stub(replica) returns a Flowgentic transport that answers from the agent and its messages only, never from timing or from the agent's population.

Agents, tasks and the store

  • C7. A task's function is safe to run again for the same call: AUTONMI may run it again, as after a worker dies.
  • C8. A scripted agent's state is plain data that pickles and changes only through what step returns, and an agent's end and result do not depend on whether it suspended.
  • C9. A scripted agent uses each call_id once.
  • C10. Callbacks (on_call, on_task, on_done, and a scripted agent's lookup, remember and report) are quick and never block the event loop, and no code catches asyncio.CancelledError.
  • C11. The store's keys under script/ and loop/ are AUTONMI's: they hold suspended agents' state.
  • C12. An agent should keep what it needs to go on in its saved state and the store, so that it can resume in another process; not required until a population's agents can resume elsewhere.

Rows and checks

  • C13. rows(pop) returns one row per id in pop.agent_ids, whatever the agent's end.
  • C14. Every row has agent_id (a string) and finished (a bool, true only when the agent's status is done), and rows serialise to JSON.
  • C15. A row's simulations, if it has one, counts its agent's tasks that completed, a failed agent's included.
  • C16. No row sets a field AUTONMI adds: status, error, t_start, t_end, suspensions, model_calls, model_wait_s, model_service_s, tasks_ok, tasks_failed, tasks_cancelled, tasks_refused.
  • C17. verify(rows, store) returns the application's checks and does not raise; under the stub they pass.
  • C18. Under the stub, every agent ends done and finished.

finished says whether the agent delivered its result; AUTONMI's status says how it ended. The run checks simulations against AUTONMI's count, agent by agent. A row holds anything else the application keeps.

What AUTONMI guarantees

  • C19. Every agent runs once, to an end: done, failed, cancelled or interrupted. One agent's failure never stops another.
  • C20. Agents start in agents() order, at most max_live live at once, suspended ones included.
  • C21. An agent that suspends is saved to the store and resumed in the same process once every task it named has ended; no task is submitted again, and nothing of the agent is left in the store once it ends.
  • C22. Every task an agent asks for is a task of its population's engine.
  • C23. Every model call goes through the population's fleet, and is counted once, in its agent's row.
  • C24. AUTONMI counts each agent's tasks by how they ended, from the tool runtime's records, and adds the counts to its row.
  • C25. AUTONMI writes each population's rows to <run>/app/agents-p<index>.jsonl, with its fields added.
  • C26. The run's report counts the agents by how they ended, and the campaign's check every_done_agent_has_its_result fails a run in which an agent ended done without its result.
  • C27. Each component's telemetry is complete, and the run's MiniApp report says so.

The kit checks every clause but C5, C9, C10, C11, C20 and C25, and reports C12 as not checked until it is required.