agora.plan.harness
Reusable orchestrator harness for plan runners.
Every runner script in scripts/ opens a Matrix client, logs in, optionally
invites an observer user to auto-created rooms, builds an Orchestrator,
runs a project, and prints a summary. That boilerplate is ~80 lines of mostly
identical setup. This module factors it out so a plan runner (and the
plan-builder runner) don’t have to duplicate it.
The harness does not hold any CLI-parsing or per-project task authoring —
callers pass the (agents, tasks, staged_tasks) triple that
agora.plan.loader.instantiate_plan() produces.
Functions
|
Log in as the system user and wire the auto-invite shim if observer is set. |
|
Construct an |
Windows cp1252 cannot encode many characters LLMs produce. |
|
|
Best-effort VRAM check + warm-up gate. |
|
End-to-end: preflight → login → orchestrate → run → close client. |
|
Write framework-owned shared files into the executor's project work_dir. |
Classes
Everything a plan runner needs to stand up an Orchestrator. |
- class agora.plan.harness.HarnessConfig[source]
Bases:
objectEverything a plan runner needs to stand up an Orchestrator.
The config-shaped fields (endpoints + credentials) are REQUIRED (owner ruling 2B.2 / Q3): their only default lives in
agora.config.Settings. Build one withfrom_settings()— the single Settings->HarnessConfig mapping point. This module reads no env and never importsagora.config.- classmethod from_settings(settings, work_dir='workspace')[source]
Build from a Settings-like object (the composition root passes
agora.config.get_settings()). Duck-typed on purpose: this module imports neitherosnoragora.config— env is read only in config.py. Campaign params override the behavioural knobs downstream (2B.iii precedence).
- __init__(homeserver, system_password, observer_user, ollama_base_url, server_name='agora.local', system_user='@agora:agora.local', review_timeout_seconds=300.0, max_parallel_agents=2, max_task_retries=2, work_dir=<factory>, knowledge_cache_dir=None, enable_observer=True, enable_web_fetch=False, fetch_max_text_bytes=65536, auto_hooks_enabled=True, skip_vram_check=False, plan_authoring_enabled=False, routed_retry_budget=2, tool_errors='raw', nudge_budget=0, review_budget=0, salvage_budget=0)
- async agora.plan.harness.build_matrix_client(cfg)[source]
Log in as the system user and wire the auto-invite shim if observer is set.
With
enable_observer=Falsethis returns aNullMatrixClientand never touches the network: an unobserved run has no reason to require a homeserver, a password, or rooms nobody opens. Provenance is unaffected — JSONL + run.log are written unconditionally (F3); only the live room view goes away. That makes Python + Ollama the whole dependency set for a phased run, with Conduit an opt-in observation surface.
- agora.plan.harness.build_orchestrator(cfg, client, model, *, profile=None, observer=None, llm_factory=None)[source]
Construct an
Orchestratorwith sensible defaults for plan runners.When
profileis supplied, the LLM factory is built viabuild_llm_factory()so all inference params (num_ctx, max_tokens, keep_alive, base_url, num_parallel) flow from the profile. When it’s None, the legacy env-driven closure is kept verbatim for back-compat.llm_factoryoverrides the factory entirely (e.g. a strategy-wrapped one from a runner). When None the factory is built as described above — the default path is unchanged.
- agora.plan.harness.force_utf8_stdio()[source]
Windows cp1252 cannot encode many characters LLMs produce. Force UTF-8.
Call from a runner’s top-level before any logging is configured.
line_buffering=Trueis load-bearing. A bareTextIOWrapperis BLOCK-buffered whenever stdout is a pipe or a file, so a redirected run emits nothing until the process exits — and it silently defeatspython -u, because that flag configures the original stdout, not the wrapper installed over it. Without this, run_phased … –auto > run.txt shows an empty file for the whole run and is indistinguishable from a hang (observed 2026-07-15: multi-minute runs written off as dead purely because nothing streamed). Progress output is a diagnostic surface; buffering it away costs real debugging time.
- async agora.plan.harness.preflight_vram(model, base_url, safety_margin_mib=512, *, skip=False)[source]
Best-effort VRAM check + warm-up gate. Prints the reason line, raises on hard fail.
skip(the composition root passesSettings.skip_vram_check) bypasses the check entirely — the escape hatch for when the pre-flight is wrong and you know it. This is the policy layer; the math inagora.fleet.vramis unaware of it.Skipped for non-Ollama models — there’s no local GPU memory to budget against (Ollama is the only backend today, so this is effectively always active).
safety_margin_mibis sourced fromprofile.vram.safety_margin_mibin the standard call path. The estimation formula itself is unchanged (seeagora.fleet.vram.check_model_fits()).
- async agora.plan.harness.run_plan_project(cfg, project_name, agents, tasks, staged_tasks=None, model_hint=None, max_loopbacks=2)[source]
End-to-end: preflight → login → orchestrate → run → close client.
model_hintis used for the VRAM preflight; falls back to the first agent’s model (runners usually use a single model). Returns theProjectResultand prints a one-line summary per task.