agora.fleet.agent_runtime
Per-agent execution loop.
Given a Task and an AgentIdentity, the runtime:
Builds a system prompt from
identity.effective_instructions.Constructs a user message from the task description plus postcondition hints.
Enters a tool-call loop: LLM → tool execution → results fed back, bounded by
max_iterations.Validates postconditions against a result context and returns a
TaskResult.Asks the LLM for a short post-task reflection to extract structured
Learningrecords, then appends them to the agent’s identity room.
The runtime is deliberately storage-agnostic: all Matrix side effects go through
the injected MatrixClientProtocol. All LLM calls go through
LLMProtocol. Tests inject fakes for both.
Functions
|
Render the required-output-path block that prefixes task + stage prompts. |
|
Pure pre-dispatch check: are the call's required arguments present? |
Classes
The per-task tool-calling loop that backs every Agora run. |
|
A tool failure rendered back to the model as actionable correction. |
|
Outcome of a single |
- class agora.fleet.agent_runtime.TaskResult[source]
Bases:
objectOutcome of a single
AgentRuntime.execute_task()call.successis determined by the postconditions, not the LLM’s self-report (seeagora.core.contract.Specification).postcondition_resultslists(predicate_name, passed, reason)triples for every predicate evaluated;artifactsare the file paths written through the inner tools;learningsare the failure traces extracted from this turn for the next agent’s prompt.- __init__(task_id, success, output, artifacts=<factory>, postcondition_results=<factory>, learnings=<factory>, reinforced_ids=<factory>, token_usage=<factory>, iterations=0, stop_reason='', tool_calls_total=0, tool_calls_structured=0, tool_calls_text_fallback=0, turns_with_text_fallback=0, tool_calls_malformed=0, tool_call_unknown_name=0, tools_used=<factory>, first_text_fallback_iteration=None, duration_s=0.0, artifact_capture=None, reviews_used=0, post_review_action=None, nudges_used=0, salvages_used=0, turns_reasoning_only=0, run_check_records=<factory>)
- class agora.fleet.agent_runtime.AgentRuntime[source]
Bases:
objectThe per-task tool-calling loop that backs every Agora run.
Each task goes through one
execute_taskcall: build the system prompt from the agent’s identity (including any active learnings), enter a bounded LLM ↔ tool loop, then evaluate postconditions against the produced artefacts. The runtime is storage-agnostic — Matrix side effects flow through the injectedMatrixClientProtocol, LLM calls throughLLMProtocol, and tools through theToolContext— so it can run end-to-end against fakes in tests.Composition: the orchestrator holds one
AgentRuntimeper agent; staged tasks delegate toagora.fleet.stage_runner.StageRunner, which reuses the same_run_loopinternals with a fresh per-stage message history.- async execute_task(task, identity, max_iterations=20)[source]
Run one task end-to-end against the configured LLM and tools.
Builds the system prompt from
identity.effective_instructions(which folds in any active learnings), enters the tool-call loop bounded bymax_iterations, evaluates postconditions against the result context, then asks the LLM for a short post-task reflection to extract structuredLearningrecords.successon the returnedTaskResultis True iff every postcondition evaluatesTrue— the LLM’smark_completecall is observed but does not determine outcome. On weak models that exit withoutmark_complete, the auto-hooks layer synthesises one from the written files so the predicate has something to observe.
- agora.fleet.agent_runtime.build_output_path_banner(output_path)[source]
Render the required-output-path block that prefixes task + stage prompts.
A structured, high-visibility constant the agent can reliably pattern-match even when the rest of the prompt is long. Weak models get lost when a path is only mentioned once in prose; repeating it in a dedicated block with a
PATH CONSTANT:label anchors the right answer.
- class agora.fleet.agent_runtime.CorrectiveError[source]
Bases:
objectA tool failure rendered back to the model as actionable correction.
Renders to a single tool-result message with three parts: what was wrong, the tool’s expected schema, and an optional hint. Replaces the v2 crash-as-string (a raw
KeyError/traceback), which the autopsy showed weak models could not recover from (they re-emitted the same bad call).- __init__(tool_name, problem, schema, hint='')
- agora.fleet.agent_runtime.validate_call(call, schema)[source]
Pure pre-dispatch check: are the call’s required arguments present?
Returns a
CorrectiveErrorwhen a required key from the tool’s JSON schema is missing, elseNone. Only required-key presence is checked here (the cheap, high-signal case — e.g. mark_complete called with write_file’spath/contentand nosummary); deeper type errors surface as handler exceptions, which the corrective dispatch also renders.