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

build_matrix_client(cfg)

Log in as the system user and wire the auto-invite shim if observer is set.

build_orchestrator(cfg, client, model, *[, ...])

Construct an Orchestrator with sensible defaults for plan runners.

force_utf8_stdio()

Windows cp1252 cannot encode many characters LLMs produce.

preflight_vram(model, base_url[, ...])

Best-effort VRAM check + warm-up gate.

run_plan_project(cfg, project_name, agents, ...)

End-to-end: preflight → login → orchestrate → run → close client.

seed_workspace(flow, project_name, work_dir_root)

Write framework-owned shared files into the executor's project work_dir.

Classes

HarnessConfig

Everything a plan runner needs to stand up an Orchestrator.

class agora.plan.harness.HarnessConfig[source]

Bases: object

Everything 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 with from_settings() — the single Settings->HarnessConfig mapping point. This module reads no env and never imports agora.config.

homeserver: str
system_password: str
observer_user: str
ollama_base_url: str
server_name: str = 'agora.local'
system_user: str = '@agora:agora.local'
review_timeout_seconds: float = 300.0
max_parallel_agents: int = 2
max_task_retries: int = 2
work_dir: Path
knowledge_cache_dir: Path | None = None
enable_observer: bool = True
enable_web_fetch: bool = False
fetch_max_text_bytes: int = 65536
auto_hooks_enabled: bool = True
skip_vram_check: bool = False
plan_authoring_enabled: bool = False
routed_retry_budget: int = 2
tool_errors: str = 'raw'
nudge_budget: int = 0
review_budget: int = 0
salvage_budget: int = 0
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 neither os nor agora.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=False this returns a NullMatrixClient and 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 Orchestrator with sensible defaults for plan runners.

When profile is supplied, the LLM factory is built via build_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_factory overrides 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=True is load-bearing. A bare TextIOWrapper is BLOCK-buffered whenever stdout is a pipe or a file, so a redirected run emits nothing until the process exits — and it silently defeats python -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 passes Settings.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 in agora.fleet.vram is 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_mib is sourced from profile.vram.safety_margin_mib in the standard call path. The estimation formula itself is unchanged (see agora.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_hint is used for the VRAM preflight; falls back to the first agent’s model (runners usually use a single model). Returns the ProjectResult and prints a one-line summary per task.