Skip to main content

build

Function build 

Source
pub async fn build(
    home: &AgentHome,
    resolved: &ResolvedModel,
    args: &Args,
    cwd: &Path,
    project_trusted: bool,
) -> Result<(AgentHarness, Receiver<AgentEvent>, ReloadContext), BuildError>
Expand description

Build the AgentHarness from the resolved model + parsed args + cwd.

This is the v1 equivalent of TS createAgentSession. It:

  1. Builds the OsExecutionEnv rooted at cwd.
  2. Constructs the built-in tools (optionally filtered by --tools/ --exclude-tools/--no-tools/--no-builtin-tools).
  3. Resolves the session storage (ephemeral vs fresh JSONL vs restore-error).
  4. Assembles AgentHarnessOptions and calls AgentHarness::create.

Returns the harness plus a broadcast::Receiver<AgentEvent> carrying the live AgentEvent stream from every run (backed by a BroadcastEmitter installed on the harness). Interactive mode drains this to render streaming responses; the non-interactive modes simply drop it. Returns the harness, the live AgentEvent broadcast receiver, and a ReloadContext the interactive TUI holds to drive /reload (and a plugin’s runtime_action(Reload) via the mailbox). Non-interactive modes drop the context (no /reload surface in print/json mode).

home is the one agent-home value for this session: settings/auth/models/ trust, skills/prompts/extensions/SYSTEM.md discovery, resource leases and the native-package artifacts used by extension loading all read from it. CLI callers pass AgentHome::process, which preserves the historical RPI_CODING_AGENT_DIR/~/.rpi/agent behavior; embedding hosts pass an explicit home and can run several sessions with different homes in one process without mutating the process environment.