Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

docs(agent): add README files for harness, prompts, and channels

Steven Enamakel4887b0b25183
diff --git a/crates/openhuman-core/src/agent/harness/README.md b/crates/openhuman-core/src/agent/harness/README.md
index 2951da887d..5dacbdf461 100644
--- a/crates/openhuman-core/src/agent/harness/README.md
+++ b/crates/openhuman-core/src/agent/harness/README.md
@@ -3,23 +3,26 @@
Product shell around the tinyagents tool loop. The model/tool iteration
itself runs in `crate::agent::tinyagents` (via
`run_turn_via_tinyagents_shared`); this module owns everything OpenHuman
-layers on top: agent-definition/prompt helpers, post-turn
-memory/archival hooks, mid-turn message steering, and oversized-tool-result
-handling.
+layers on top: sub-agent definitions, parent/child context plumbing, post-turn
+memory/archival hooks, and oversized-tool-result handling.
+
+`Agent`, its per-turn lifecycle, and transcript persistence live in
+`../session_host/`, not here; this module supplies the definition/prompt data
+that session host and `../subagent_host/` build turns from.
Cancellation is the tinyagents steering channel (`SteeringCommand` in
`crate::agent::tinyagents`); there is no in-house interrupt fence or
-cancellation token owned here. `run_queue` only queues messages between
-iterations.
+cancellation token owned here. The message queue that lets a caller steer or
+follow up on an in-flight turn is `tinyagents_harness::run_queue::RunQueue`,
+used here (not defined here) by `agent_graph.rs` and `fork_context.rs`.
## Responsibilities
-- Own the `Agent` struct and its per-turn lifecycle: prompt/context assembly,
- tool dispatch, transcript persistence, KV-cache prefix stability
- (`session/`).
-- Supply the product definition/prompt inputs used by `../subagent_host/`.
- That host implements the TinyAgents sub-agent lifecycle traits directly;
- this module does not export a compatibility runner.
+- Define sub-agent archetypes and the definition/prompt inputs consumed by
+ `../session_host/` (which owns the `Agent` struct, turn lifecycle, and
+ KV-cache prefix stability) and `../subagent_host/`, which implements the
+ TinyAgents sub-agent lifecycle traits directly. This module does not export
+ a compatibility runner of its own.
- Define sub-agent archetypes (built-in + workspace TOML) and the task-local
plumbing that lets a spawned tool see its parent's runtime context
(`definition*.rs`, `builtin_definitions.rs`, `fork_context.rs`,
diff --git a/crates/openhuman-core/src/agent/prompts/README.md b/crates/openhuman-core/src/agent/prompts/README.md
index 80fbeb24c3..73f344b159 100644
--- a/crates/openhuman-core/src/agent/prompts/README.md
+++ b/crates/openhuman-core/src/agent/prompts/README.md
@@ -7,24 +7,24 @@ domains use to compose their own prompts.
## Public surface (from `mod.rs`)
-- `types::*` — `PromptContext`, `PromptSection` trait, `PromptTier`,
+- `types::*`: `PromptContext`, `PromptSection` trait, `PromptTier`,
`PromptTool`, `ToolCallFormat`, `LearnedContextData`, `UserIdentity`,
`ConnectedIntegration`, `NamespaceSummary`, `SubagentRenderOptions`. Pure
data, no rendering logic. Also holds the `pub(crate)` caps
`BOOTSTRAP_MAX_CHARS` (20K, for `SOUL.md`/`IDENTITY.md`/`ROLE.md` and each
`AGENTS.md` layer) and `USER_FILE_MAX_CHARS` (2K, for `PROFILE.md`,
`MEMORY.md` and the snapshot `USER.md` block).
-- `render_connected_identities` (`connected_identities.rs`) — best-effort,
- sync render of the `## Connected Identities` block; reads through the bound
- memory driver via `block_in_place`, returns empty when there is no
+- `render_connected_identities` (`connected_identities.rs`): best-effort,
+ sync render of the `## Connected Identities` block. It reads through the
+ bound memory driver via `block_in_place` and returns empty when there is no
multi-thread runtime or the config/driver read fails.
-- `agents_md::{load_agents_md, load_agents_md_layers, AgentsMdContent, AGENTS_MD_FILENAME}`
- — loads `AGENTS.md` at the global (`workspace_dir`) and local
+- `agents_md::{load_agents_md, load_agents_md_layers, AgentsMdContent, AGENTS_MD_FILENAME}`:
+ loads `AGENTS.md` at the global (`workspace_dir`) and local
(`action_dir`, or a sub-agent's `worktree_action_dir` override) layers.
-- `builder::{SystemPromptBuilder, TieredPrompt, GLOBAL_STYLE_SUFFIX}` —
+- `builder::{SystemPromptBuilder, TieredPrompt, GLOBAL_STYLE_SUFFIX}`:
assembles ordered `PromptSection`s into a final prompt string (or a
`TieredPrompt` with cache-breakpoint offsets).
-- `sections::*` — the concrete `PromptSection` structs (`IdentitySection`,
+- `sections::*`: the concrete `PromptSection` structs (`IdentitySection`,
`ToolsSection`, `SafetySection`, `UserFilesSection`, `UserMemorySection`,
`UserReflectionsSection`, `UserIdentitySection`, `WorkspaceSection`,
`DateTimeSection`, `RuntimeSection`, `AgentsInstructionsSection`,
@@ -32,14 +32,14 @@ domains use to compose their own prompts.
`DynamicPromptSection`, `GroundingSection`).
- Named re-exports from `render_helpers` (`render_helpers.rs` plus the
`render_helpers/` submodules `section_renderers.rs`, `subagent.rs`,
- `workspace_files.rs`) — free `render_*` functions
- (thin wrappers over the section structs), the workspace-file helpers
+ `workspace_files.rs`): free `render_*` functions (thin wrappers over the
+ section structs), the workspace-file helpers
(`inject_workspace_file[_capped]`, `inject_inline_content`,
`inject_snapshot_content`, `sync_workspace_file`,
`default_workspace_file_content`), `current_datetime_line`,
`memory_date_label`, and the sub-agent renderer
- (`render_subagent_system_prompt[_with_format]`). Lets a caller assemble a
- prompt by calling functions directly instead of going through
+ (`render_subagent_system_prompt[_with_format]`). These let a caller
+ assemble a prompt by calling functions directly instead of going through
`SystemPromptBuilder`.
## Bundled assets
@@ -48,21 +48,21 @@ domains use to compose their own prompts.
master agent's identity, role brief, personality, and writing style. They are
embedded with `include_str!` in `render_helpers/workspace_files.rs`
(`default_workspace_file_content`) and, for `STYLE.md`, again in `builder.rs`
-as `GLOBAL_STYLE_SUFFIX`. Two uses:
-
-- **Seed and refresh** — `sync_workspace_file(workspace_dir, filename)` writes
- the bundled text to `<workspace_dir>/<filename>` when it is missing and
- records a hash of the bundled content in a `.<filename>.builtin-hash`
- sidecar. On later runs the file is left alone unless the bundled default
- changed (hash mismatch), in which case the disk copy is overwritten. So a
- user edit survives until the next release that touches that asset. Only
- absolute `workspace_dir`s are seeded. `IdentitySection` syncs
+as `GLOBAL_STYLE_SUFFIX`. There are two uses:
+
+- Seed and refresh: `sync_workspace_file(workspace_dir, filename)` writes the
+ bundled text to `<workspace_dir>/<filename>` when it is missing and records
+ a hash of the bundled content in a `.<filename>.builtin-hash` sidecar. On
+ later runs the file is left alone unless the bundled default changed (hash
+ mismatch), in which case the disk copy is overwritten, so a user edit
+ survives until the next release that touches that asset. Only absolute
+ `workspace_dir`s are seeded. `IdentitySection` syncs
`SOUL.md`/`IDENTITY.md`/`ROLE.md` (`ROLE.md` is injected only when
`visible_tool_names` is non-empty, i.e. for the orchestrator); `builder.rs`
syncs `STYLE.md` on every build so agents that set `omit_identity` still get
the style rules.
-- **Compile-time fallback** — `GLOBAL_STYLE_SUFFIX` is used when the
- workspace `STYLE.md` cannot be read.
+- Compile-time fallback: `GLOBAL_STYLE_SUFFIX` is used when the workspace
+ `STYLE.md` cannot be read.
`USER.md` is different: nothing in this module reads it. It is exposed as the
`openhuman://prompts/user` MCP resource by `mcp/server/resources.rs`
@@ -70,8 +70,8 @@ as `GLOBAL_STYLE_SUFFIX`. Two uses:
appears in prompts comes from the curated-memory snapshot
(`CuratedMemoryPromptSnapshot.user`), not from this file.
-Editing these files changes the shipped default agent's persona/style without
-a code change.
+Editing these files changes the shipped default agent's persona and style
+without a code change.
## Canonical module
@@ -83,18 +83,18 @@ module for this API.
Other domains contribute prompt content without living in this directory:
-- `agent/learning/prompt_sections.rs` — `LearnedContextSection`,
+- `agent/learning/prompt_sections.rs`: `LearnedContextSection`,
`UserProfileSection`, `MemoryAccessSection`, `MemoryWriteSection`
(`PromptSection` impls, config-gated; `agent/session_host/builder/factory.rs`
and `.../builder/helpers.rs` append them with `add_section` /
`insert_section_before` when learning or explicit preferences are enabled).
-- `tools/agent_policy/prompt.rs` — `render_tool_policy_boundary` is not a
- section: `agent/session_host/turn/context.rs` string-appends its
+- `tools/agent_policy/prompt.rs`: `render_tool_policy_boundary` is not a
+ section. `agent/session_host/turn/context.rs` string-appends its
`## Tool Policy Boundary` block after the builder output so the
session-scoped bytes land at the tail of the prompt.
Built-in archetype system prompts (orchestrator, welcome, integrations_agent,
-…) live in `agent/registry/agents/<name>/prompt.rs` and
+and so on) live in `agent/registry/agents/<name>/prompt.rs` and
`flows/agents/{flow_discovery,workflow_builder}/prompt.rs`, not here. Each is a
`PromptSource::Dynamic` function that hand-assembles its body via the
`render_*` helpers; `agent/session_host/builder/factory.rs` wraps it with
@@ -102,14 +102,14 @@ Built-in archetype system prompts (orchestrator, welcome, integrations_agent,
## Builder entry points
-- `SystemPromptBuilder::with_defaults()` — the primary-agent chain (identity,
+- `SystemPromptBuilder::with_defaults()`: the primary-agent chain (identity,
user files, `AGENTS.md`, user memory, tools, safety, workspace, datetime,
runtime).
- `SystemPromptBuilder::for_subagent(archetype_prompt_text, omit_identity,
- omit_safety_preamble)` — narrow chain driven by a sub-agent definition's
- `omit_*` flags; deliberately excludes `DateTimeSection` so repeat spawns of
- the same definition stay byte-identical for prefix-cache reuse.
-- `SystemPromptBuilder::from_dynamic(builder)` — wraps a
+ omit_safety_preamble)`: narrow chain driven by a sub-agent definition's
+ `omit_*` flags. It deliberately excludes `DateTimeSection` so repeat spawns
+ of the same definition stay byte-identical for prefix-cache reuse.
+- `SystemPromptBuilder::from_dynamic(builder)`: wraps a
`PromptSource::Dynamic` fn pointer in a `DynamicPromptSection` and still
injects the shared `AgentsInstructionsSection`. `from_final_body(body)`
wraps an already-rendered string the same way; it currently has only test
@@ -119,7 +119,7 @@ Every `build()` appends the grounding contract (unless the body already
carries the `GROUNDING_HEADING`) and the workspace `STYLE.md` block, so all
three chains share the same anti-fabrication floor and style rules.
-## KV-cache / prefix stability
+## KV-cache and prefix stability
The rendered prompt is built once per session and reused on every turn
(`agent/session_host/runtime_session.rs::prepare`) so the inference backend's
@@ -147,18 +147,18 @@ connected service changes the second segment and leaves the first
byte-identical; `PromptCacheSegmentMiddleware` mirrors that split in the
segment ids it declares. A prefix is reusable only up to the first differing
byte, so a volatile section rendered early invalidates every stable byte
-behind it. Two consequences visible in this module: `DateTimeSection` renders
-only the clock *rules* and is `Stable` (the live timestamp rides the user
-message via `current_datetime_line`), and `memory_date_label` renders
+behind it. Two consequences are visible in this module: `DateTimeSection`
+renders only the clock *rules* and is `Stable` (the live timestamp rides the
+user message via `current_datetime_line`), and `memory_date_label` renders
`NamespaceSummary.updated_at` as an absolute date rather than "N days ago".
## Used by
-- `agent/session_host/turn/context.rs` — loads `AGENTS.md` layers and
- connected identities into `PromptContext`, calls the builder, appends the
- tool-policy boundary.
-- `agent/session_host/builder/factory.rs` — picks the entry point per
+- `agent/session_host/turn/context.rs`: loads `AGENTS.md` layers and
+ connected identities into `PromptContext`, calls the builder, and appends
+ the tool-policy boundary.
+- `agent/session_host/builder/factory.rs`: picks the entry point per
`PromptSource` and registers the learning/profile sections.
-- `agent/debug/` — `dump_agent_prompt` / `dump_all_agent_prompts` (`mod.rs`)
+- `agent/debug/`: `dump_agent_prompt` / `dump_all_agent_prompts` (`mod.rs`)
build the same `PromptContext` to render each agent's prompt,
`dump_writer.rs` writes it to disk, `prompt_size.rs` measures it.
diff --git a/crates/openhuman-core/src/channels/README.md b/crates/openhuman-core/src/channels/README.md
index 2491a288ee..dbf580a019 100644
--- a/crates/openhuman-core/src/channels/README.md
+++ b/crates/openhuman-core/src/channels/README.md
@@ -28,29 +28,29 @@ The domain lives behind the `channels` feature (default-ON, #4801), except two d
| `controllers/` | `channels.*` RPC namespace, `OpenHumanChannelBackend`, provider definitions ([README](controllers/README.md)) |
| `tests/` | Cross-channel integration test suite (`#[cfg(all(feature = "channels", test))]`) |
-Flat files: `bus.rs` (`ChannelInboundSubscriber`, handles `DomainEvent::ChannelInboundMessage` published by the socket transport layer in `platform/socket/event_handlers.rs` and replies through the REST API; registered by `register_domain_subscribers` in `core/jsonrpc.rs`, not here), `cli.rs` (ungated `CliChannel`), `commands.rs` (`doctor_channels` and listener health classification), `context.rs` (`ChannelRuntimeContext`, per-sender conversation history, timeouts), `proactive.rs` (`ProactiveMessageSubscriber`, subscribes `DomainEvent::ProactiveMessageRequested` and delivers to the active channel), `relay_runtime.rs` (`relay_runtime_fronts_channel` / `send_outbound_intent` — the process-local relay-websocket transport handle controller sends go through when the relay fronts a channel), `routes.rs` (per-sender route overrides and runtime commands), `system_prompt.rs`, `traits.rs` (ungated `Channel`/`SendMessage` re-export).
+Flat files: `bus.rs` (`ChannelInboundSubscriber`, handles `DomainEvent::ChannelInboundMessage` published by the socket transport layer in `platform/socket/event_handlers.rs` and replies through the REST API; registered by `register_domain_subscribers` in `core/jsonrpc.rs`, not here), `cli.rs` (ungated `CliChannel`), `commands.rs` (`doctor_channels` and listener health classification), `context.rs` (`ChannelRuntimeContext`, per-sender conversation history, timeouts), `proactive.rs` (`ProactiveMessageSubscriber`, subscribes `DomainEvent::ProactiveMessageRequested` and delivers to the active channel), `relay_runtime.rs` (`relay_runtime_fronts_channel` / `send_outbound_intent`, the process-local relay-websocket transport handle controller sends go through when the relay fronts a channel), `routes.rs` (per-sender route overrides and runtime commands), `system_prompt.rs`, `traits.rs` (ungated `Channel`/`SendMessage` re-export).
## Calls into
-- `crates/openhuman-core/src/agent/` — the agent turn is dispatched over `BUS.native()` to the `agent.run_turn` handler registered by `agent::bus::register_agent_handlers`, so `runtime/dispatch/` never imports the harness directly.
-- `crates/openhuman-core/src/agent/context/channels_prompt.rs` — channel system prompt rendering, re-exported as `build_system_prompt`.
-- `crates/openhuman-core/src/security/credentials/` — `AuthService` lookups for connect/disconnect and for secret hydration at startup (email password, Yuanbao app secret).
-- `crates/openhuman-core/src/security/approval/` — `ApprovalGate` for the approval-reply intercept and `ApprovalChatContext` scoping of Telegram turns.
-- `crates/openhuman-core/src/config/` — `Config` / `ChannelsConfig` (schema types come from `tinychannels_bus::config` via `config/schema/channels.rs`).
-- `crates/openhuman-core/src/memory/conversations/` and `memory/guard` — conversation history persistence and the active memory guard.
-- `crates/openhuman-core/src/api/rest.rs` — `BackendOAuthClient` for controller messaging ops and Telegram/Discord link flows.
-- `crates/openhuman-core/src/web_chat/` — web-channel event publishing, session invalidation (`/new`), and the web surface subscribers registered at startup.
-- `crates/openhuman-core/src/voice/` — STT/TTS behind the `host/` adapters.
-- `crates/openhuman-core/src/core/bus.rs` and `core/events.rs` — the process-wide `BUS` and the `DomainEvent::Channel*` variants published from `runtime/dispatch/` and `runtime/supervision.rs`.
-- `vendor/tinychannels/` — provider transports, `tinychannels::build_channels` (provider construction), `ChannelManager`/`ChannelBackend`, and the `tinychannels::host` capability boundary; `vendor/tinychannels/crates/tinychannels-bus` — the transport-free trait/type contract.
+- `crates/openhuman-core/src/agent/`: the agent turn is dispatched over `BUS.native()` to the `agent.run_turn` handler registered by `agent::bus::register_agent_handlers`, so `runtime/dispatch/` never imports the harness directly.
+- `crates/openhuman-core/src/agent/context/channels_prompt.rs`: channel system prompt rendering, re-exported as `build_system_prompt`.
+- `crates/openhuman-core/src/security/credentials/`: `AuthService` lookups for connect/disconnect and for secret hydration at startup (email password, Yuanbao app secret).
+- `crates/openhuman-core/src/security/approval/`: `ApprovalGate` for the approval-reply intercept and `ApprovalChatContext` scoping of Telegram turns.
+- `crates/openhuman-core/src/config/`: `Config` / `ChannelsConfig` (schema types come from `tinychannels_bus::config` via `config/schema/channels.rs`).
+- `crates/openhuman-core/src/memory/conversations/` and `memory/guard`: conversation history persistence and the active memory guard.
+- `crates/openhuman-core/src/api/rest.rs`: `BackendOAuthClient` for controller messaging ops and Telegram/Discord link flows.
+- `crates/openhuman-core/src/web_chat/`: web-channel event publishing, session invalidation (`/new`), and the web surface subscribers registered at startup.
+- `crates/openhuman-core/src/voice/`: STT/TTS behind the `host/` adapters.
+- `crates/openhuman-core/src/core/bus.rs` and `core/events.rs`: the process-wide `BUS` and the `DomainEvent::Channel*` variants published from `runtime/dispatch/` and `runtime/supervision.rs`.
+- `vendor/tinychannels/`: provider transports, `tinychannels::build_channels` (provider construction), `ChannelManager`/`ChannelBackend`, and the `tinychannels::host` capability boundary. `vendor/tinychannels/crates/tinychannels-bus` holds the transport-free trait/type contract.
## Called by
-- `crates/openhuman-core/src/core/all.rs` — registers `controllers::all_channels_registered_controllers()` under the `channels` feature gate.
-- `crates/openhuman-core/src/core/runtime/services.rs` — `spawn_channels_service` calls `channels::start_channels(config)` unless `OPENHUMAN_DISABLE_CHANNEL_LISTENERS` is set or `has_listening_integrations()` is false.
-- `crates/openhuman-core/src/core/jsonrpc.rs` — `bootstrap_core_runtime` subscribes `bus::ChannelInboundSubscriber` and calls `proactive::register_web_only_proactive_subscriber()`.
-- `crates/openhuman-core/src/agent/session_host/` — the interactive loop drives the ungated `CliChannel`.
-- `crates/openhuman-core/src/cron/bus.rs` — `CronDeliverySubscriber` is handed the started channel map by `runtime/startup.rs`; it names channels only through `tinychannels_bus`.
+- `crates/openhuman-core/src/core/all.rs`: registers `controllers::all_channels_registered_controllers()` under the `channels` feature gate.
+- `crates/openhuman-core/src/core/runtime/services.rs`: `spawn_channels_service` calls `channels::start_channels(config)` unless `OPENHUMAN_DISABLE_CHANNEL_LISTENERS` is set or `has_listening_integrations()` is false.
+- `crates/openhuman-core/src/core/jsonrpc.rs`: `bootstrap_core_runtime` subscribes `bus::ChannelInboundSubscriber` and calls `proactive::register_web_only_proactive_subscriber()`.
+- `crates/openhuman-core/src/agent/session_host/`: the interactive loop drives the ungated `CliChannel`.
+- `crates/openhuman-core/src/cron/bus.rs`: `CronDeliverySubscriber` is handed the started channel map by `runtime/startup.rs`; it names channels only through `tinychannels_bus`.
## Tests