Skip to main content

Module agent_session

Module agent_session 

Source
Expand description

AgentSession — the coding-agent product layer over the harness.

Mirrors the role of packages/coding-agent/src/core/agent-session.ts: one object the CLI/TUI holds that unifies prompt/continue, queueing, model/thinking mutation, scoped models, compaction + retry, export, session switching / fork, usage + context stats, and name/label facts.

Design notes (deliberate, vs the TS original):

  • Composition, not inheritance. TS AgentSession is the harness plus a pile of product concerns. Here AgentSession owns an AgentHarness and adds the product surface; the harness stays usable on its own for SDK consumers who do not want the product layer. This keeps the rpi-harness crate free of CLI concerns (provider catalogs, settings paths, export formats).
  • Sync-friendly handles. The TUI key loop is a blocking thread, so the mutating surface that the loop touches (set_thinking_level, scoped_models) works off cached state or spawns onto the runtime; the async surface (prompt, compact, export) is async fn.
  • Retry/compaction policy lives in the harness. The session exposes retry()/compact() as intent, and the harness applies its own RetryPolicy/CompactionSettings. TS keeps the auto-retry driver in the session; we keep it in the harness so non-CLI callers get it for free.

Structs§

AgentSession
The product-level session. Cheap to clone — the harness is behind an Arc.
ScopedModel
One scoped-model entry: the routing id plus its human label.
SessionDescriptor
Where a session content lives — used by export naming and --continue.
SessionUsageStats
A snapshot of usage + context pressure for the footer/status line.

Functions§

assistant_text
The finalized text of an assistant message (text blocks only), joined with blank lines. Mirrors the TS print-mode/export concat.
outcome_is_completed
Whether a run outcome is terminal (i.e. produced a final assistant message).