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 for agent prompts directory

Steven Enamakel1adb799066fc
diff --git a/crates/openhuman-core/src/agent/prompts/README.md b/crates/openhuman-core/src/agent/prompts/README.md
index 969a1c95f3..aa444f6723 100644
--- a/crates/openhuman-core/src/agent/prompts/README.md
+++ b/crates/openhuman-core/src/agent/prompts/README.md
@@ -2,18 +2,22 @@
Owns the bundled prompt assets and the system-prompt rendering pipeline: the
types every section renders from, the section implementations themselves, the
-builder that assembles them in order, and the free `render_*` helpers other
+builder that assembles them in tier order, and the free `render_*` helpers other
domains use to compose their own prompts.
## Public surface (from `mod.rs`)
- `types::*` — `PromptContext`, `PromptSection` trait, `PromptTier`,
`PromptTool`, `ToolCallFormat`, `LearnedContextData`, `UserIdentity`,
- `ConnectedIntegration` and friends. Pure data; no rendering logic, so
- editing a type doesn't recompile the whole renderer.
+ `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 on any failure.
+ memory driver via `block_in_place`, 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
(`action_dir`, or a sub-agent's `worktree_action_dir` override) layers.
@@ -22,93 +26,126 @@ domains use to compose their own prompts.
`TieredPrompt` with cache-breakpoint offsets).
- `sections::*` — the concrete `PromptSection` structs (`IdentitySection`,
`ToolsSection`, `SafetySection`, `UserFilesSection`, `UserMemorySection`,
- `WorkspaceSection`, `DateTimeSection`, `RuntimeSection`,
- `AgentsInstructionsSection`, `PersonalityRosterSection`,
- `ArchetypePromptSection`, `DynamicPromptSection`, …).
-- `render_helpers::*` — free `render_*` functions (thin wrappers over the
- section structs) plus workspace-file injection helpers
- (`inject_workspace_file`, `inject_inline_content`, `sync_workspace_file`,
- `default_workspace_file_content`) and the sub-agent renderer
+ `UserReflectionsSection`, `UserIdentitySection`, `WorkspaceSection`,
+ `DateTimeSection`, `RuntimeSection`, `AgentsInstructionsSection`,
+ `PersonalityRosterSection`, `ArchetypePromptSection`,
+ `DynamicPromptSection`, `GroundingSection`).
+- Named re-exports from `render_helpers` (`render_helpers.rs` `include!`s
+ `render_helpers_part_01.rs` / `_part_02.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
`SystemPromptBuilder`.
## Bundled assets
-`IDENTITY.md`, `ROLE.md`, `SOUL.md`, `STYLE.md`, `USER.md` are the seed copies
-of the master agent's identity, role, personality, writing-style, and
-user-adaptation files. They are pulled in via `include_str!` (`builder.rs`
-for `STYLE.md`; `render_helpers_part_02.rs` for `SOUL.md`, `IDENTITY.md`,
-`ROLE.md`) and used two ways:
-
-- **Compile-time fallback constant** — e.g. `GLOBAL_STYLE_SUFFIX` — used when
- the workspace copy can't be read.
-- **Seed content** — `sync_workspace_file` copies the bundled text into the
- user's workspace (`<workspace_dir>/SOUL.md`, etc.) the first time it's
- missing, so a fresh workspace still gets the rules; a user's on-disk edits
- win from then on. `USER_FILE_MAX_CHARS` and `BOOTSTRAP_MAX_CHARS` (in
- `types.rs`) cap how much of the on-disk copy gets injected.
-
-Editing these files changes the shipped default agent's persona/style; they
-are not code and do not need a doc comment, but changes here are product
-changes — read `SOUL.md`/`STYLE.md` before touching them.
+`IDENTITY.md`, `ROLE.md`, `SOUL.md`, `STYLE.md` are the bundled copies of the
+master agent's identity, role brief, personality, and writing style. They are
+embedded with `include_str!` in `render_helpers_part_02.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
+ `SOUL.md`/`IDENTITY.md`/`ROLE.md` (`ROLE.md` is injected only 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.
+
+`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`
+(`include_str!("../../agent/prompts/USER.md")`). The `USER.md` block that
+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.
## Compat shim
`agent::context::prompt` (`agent/context/prompt.rs`) is `pub use
crate::agent::prompts::*` — prompt plumbing used to live there and was moved
here so it sits next to the agents that consume it. The shim is a stable
-import path only; do not add logic to it. Both `crate::agent::prompts::*` and
-`crate::agent::context::prompt::*` resolve to the same types.
+import path only; do not add logic to it.
## Extension points (owned elsewhere)
-Other domains contribute additional `PromptSection`s that plug into a
-`SystemPromptBuilder` built here, rather than living in this directory:
+Other domains contribute prompt content without living in this directory:
- `agent/learning/prompt_sections.rs` — `LearnedContextSection`,
- `UserProfileSection`, `MemoryAccessSection` (config-gated, appended by the
- session builder when learning is enabled).
-- `agent/profiles/prompt_section.rs` — cross-profile workspace notice.
-- `tools/agent_policy/prompt.rs` — tool-policy-boundary block.
+ `UserProfileSection`, `MemoryAccessSection`, `MemoryWriteSection`
+ (`PromptSection` impls, config-gated; `session/builder/factory.rs` and
+ `session/builder/helpers.rs` append them with `add_section` /
+ `insert_section_before` when learning or explicit preferences are enabled).
+- `agent/profiles/prompt_section.rs` — `AgentProfilePromptSection`, the
+ `## Agent profile` persona body plus the optional cross-profile workspace
+ notice; added by `session/builder/factory.rs`.
+- `tools/agent_policy/prompt.rs` — `render_tool_policy_boundary` is not a
+ section: `session/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 `flows/agents/*/`, not
-here — those modules hand-assemble their body via the `render_*` helpers and
-feed it into `SystemPromptBuilder::from_dynamic` or `from_final_body`.
+…) 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; `session/builder/factory.rs` wraps it with
+`SystemPromptBuilder::from_dynamic`.
## Builder entry points
- `SystemPromptBuilder::with_defaults()` — the primary-agent chain (identity,
user files, `AGENTS.md`, user memory, tools, safety, workspace, datetime,
runtime).
-- `SystemPromptBuilder::for_subagent(...)` — 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(...)` / `from_final_body(...)` — wrap an
- already-assembled body (the ~26 `agents/<id>/prompt.rs` builders) while
- still injecting the shared `AgentsInstructionsSection` and grounding/style
- suffix.
+- `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
+ `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
+ callers.
+
+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
-The rendered prompt is frozen for the life of a session
-(`agent/harness/session/mod.rs`) and reused on every turn so the inference
-backend's prefix cache hits. `PromptSection::tier()` (`PromptTier::Stable` /
-`Context` / `Volatile`) controls emission order in
-`SystemPromptBuilder::build_tiered`: stable bytes (identity, role, safety,
-style) first, then per-session-stable context (`AGENTS.md`, workspace), then
-per-turn-volatile bytes (memory, profile, connected integrations, the clock)
-last — because a prefix is reusable only up to the first differing byte, a
-volatile section rendered early invalidates every stable byte behind it.
-`NamespaceSummary.updated_at` is rendered as an absolute date rather than a
-relative one for the same reason.
+The rendered prompt is built once per session and reused on every turn
+(`agent/harness/session/turn/context.rs`) so the inference backend's prefix
+cache hits. `PromptSection::tier()` (`PromptTier::Stable` / `Context` /
+`Volatile`, default `Stable`) controls emission order in
+`SystemPromptBuilder::build_tiered`: stable bytes (identity, tools, safety,
+datetime rules) first, then per-session context (`AGENTS.md`, workspace,
+runtime), then volatile bytes (user files, memory, reflections, signed-in
+identity, personality roster, the dynamic archetype body) last, with a
+breakpoint offset recorded after each non-empty tier. 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 `NamespaceSummary.updated_at` as an absolute date
+rather than "N days ago".
## Used by
- `agent/harness/session/turn/context.rs` — loads `AGENTS.md` layers and
- connected identities into `PromptContext` at session start.
-- `agent/debug/` — dumps/measures the rendered prompt (`dump_writer.rs`,
- `prompt_size.rs`).
+ connected identities into `PromptContext`, calls the builder, appends the
+ tool-policy boundary.
+- `agent/harness/session/builder/factory.rs` — picks the entry point per
+ `PromptSource` and registers the learning/profile sections.
+- `agent/debug/` — `mod.rs` builds the same `PromptContext` to dump every
+ agent's prompt (`dump_writer.rs`), `prompt_size.rs` measures it.
- `agent/context/prompt.rs` — compat re-export shim (see above).