agora.fleet.agent_runtime

Per-agent execution loop.

Given a Task and an AgentIdentity, the runtime:

  1. Builds a system prompt from identity.effective_instructions.

  2. Constructs a user message from the task description plus postcondition hints.

  3. Enters a tool-call loop: LLM → tool execution → results fed back, bounded by max_iterations.

  4. Validates postconditions against a result context and returns a TaskResult.

  5. Asks the LLM for a short post-task reflection to extract structured Learning records, 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

build_output_path_banner(output_path)

Render the required-output-path block that prefixes task + stage prompts.

validate_call(call, schema)

Pure pre-dispatch check: are the call's required arguments present?

Classes

AgentRuntime

The per-task tool-calling loop that backs every Agora run.

CorrectiveError

A tool failure rendered back to the model as actionable correction.

TaskResult

Outcome of a single AgentRuntime.execute_task() call.

class agora.fleet.agent_runtime.TaskResult[source]

Bases: object

Outcome of a single AgentRuntime.execute_task() call.

success is determined by the postconditions, not the LLM’s self-report (see agora.core.contract.Specification). postcondition_results lists (predicate_name, passed, reason) triples for every predicate evaluated; artifacts are the file paths written through the inner tools; learnings are the failure traces extracted from this turn for the next agent’s prompt.

task_id: str
success: bool
output: str
artifacts: list[str]
postcondition_results: list[tuple[str, bool, str]]
learnings: list[Learning]
reinforced_ids: list[str]
token_usage: dict[str, int]
iterations: int = 0
stop_reason: str = ''
tool_calls_total: int = 0
tool_calls_structured: int = 0
tool_calls_text_fallback: int = 0
turns_with_text_fallback: int = 0
tool_calls_malformed: int = 0
tool_call_unknown_name: int = 0
tools_used: list[str]
first_text_fallback_iteration: int | None = None
duration_s: float = 0.0
artifact_capture: dict[str, Any] | None = None
reviews_used: int = 0
post_review_action: str | None = None
nudges_used: int = 0
salvages_used: int = 0
turns_reasoning_only: int = 0
run_check_records: list[dict[str, Any]]
__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: object

The per-task tool-calling loop that backs every Agora run.

Each task goes through one execute_task call: 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 injected MatrixClientProtocol, LLM calls through LLMProtocol, and tools through the ToolContext — so it can run end-to-end against fakes in tests.

Composition: the orchestrator holds one AgentRuntime per agent; staged tasks delegate to agora.fleet.stage_runner.StageRunner, which reuses the same _run_loop internals with a fresh per-stage message history.

__init__(llm, matrix_client, tool_context)[source]
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 by max_iterations, evaluates postconditions against the result context, then asks the LLM for a short post-task reflection to extract structured Learning records.

success on the returned TaskResult is True iff every postcondition evaluates True — the LLM’s mark_complete call is observed but does not determine outcome. On weak models that exit without mark_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: object

A 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).

tool_name: str
problem: str
schema: dict[str, Any]
hint: str = ''
render()[source]
__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 CorrectiveError when a required key from the tool’s JSON schema is missing, else None. Only required-key presence is checked here (the cheap, high-signal case — e.g. mark_complete called with write_file’s path/content and no summary); deeper type errors surface as handler exceptions, which the corrective dispatch also renders.