Skip to content

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

fix(agent): update prompt sections to include missing context

Steven Enamakela4736ae04246
diff --git a/crates/openhuman-core/src/agent/prompts/sections.rs b/crates/openhuman-core/src/agent/prompts/sections.rs
index f540c2bb79..2c5cc2bd09 100644
--- a/crates/openhuman-core/src/agent/prompts/sections.rs
+++ b/crates/openhuman-core/src/agent/prompts/sections.rs
@@ -5,10 +5,7 @@
//! [`super::render_helpers`] for workspace-file injection and
//! sub-agent plumbing.
-use super::render_helpers::{
- inject_snapshot_content, inject_workspace_file, inject_workspace_file_capped,
- sync_workspace_file,
-};
+use super::render_helpers::{inject_workspace_file, sync_workspace_file};
use super::types::*;
use anyhow::Result;
use std::fmt::Write;
@@ -16,7 +13,7 @@ use tinytools::ToolSpec;
use tinytools_agent::dialect::render_pformat_catalogue;
// ─────────────────────────────────────────────────────────────────────────────
-// Special sections (archetype, dynamic, reflection)
+// Special sections (archetype, dynamic)
// ─────────────────────────────────────────────────────────────────────────────
/// Sub-agent role prompt — pre-loaded text from an
@@ -123,61 +120,12 @@ pub struct GroundingSection;
pub struct WorkspaceSection;
pub struct RuntimeSection;
pub struct DateTimeSection;
-pub struct UserMemorySection;
-/// Renders explicit user reflections — a privileged memory class
-/// distinct from generic tree summaries. Rendered above
-/// [`UserMemorySection`] so the orchestrator sees the user's own
-/// intentional self-statements before any broader summary block.
-///
-/// Empty (and skipped) when [`LearnedContextData::reflections`] is
-/// empty — keeps the prompt clean for users who haven't yet expressed
-/// any reflection-style content.
-pub struct UserReflectionsSection;
/// Renders the authenticated user's non-secret identity fields
/// (`id` / `name` / `email`) into the system prompt — see issue #926.
/// Empty when [`PromptContext::user_identity`] is `None` or the identity has no
/// populated fields. Tokens and opaque credentials are forbidden.
pub struct UserIdentitySection;
-/// Injects the user-specific, session-frozen workspace files
-/// (`PROFILE.md` + `MEMORY.md`), each capped at [`USER_FILE_MAX_CHARS`].
-///
-/// Separate from [`IdentitySection`] so agents that strip the project-
-/// context preamble (`omit_identity = true` — welcome, orchestrator,
-/// the trigger pair) still get their user-file injection at runtime via
-/// [`super::builder::SystemPromptBuilder::for_subagent`], which skips
-/// `IdentitySection` entirely when `omit_identity` is on.
-///
-/// Cache-stability: static per session — the whole point of the
-/// 2000-char cap and the load-once rule documented on
-/// [`AgentDefinition::omit_profile`] / `omit_memory_md`.
-pub struct UserFilesSection;
-
-/// Framing preamble emitted immediately before the injected `MEMORY.md`
-/// (and, in the snapshot path, `USER.md`) block.
-///
-/// `MEMORY.md` is durable, cross-session memory — archivist-curated facts
-/// carried over from *past* sessions and previously ingested history. Without
-/// a frame, a relevant curated observation reads to the model as something
-/// already said *in this thread*, so on a brand-new thread it asserts
-/// continuity that isn't there ("already covered this in a previous chat")
-/// and shortcuts its answer (GH-4745). This note scopes the block as
-/// background knowledge and forbids claiming in-thread continuity.
-///
-/// `pub(crate)` so the sub-agent renderer
-/// ([`super::render_helpers::render_subagent_system_prompt_with_format`])
-/// can share the exact same frame — Inline/File sub-agents inject
-/// `MEMORY.md` through their own path and must not drift from this note.
-pub(crate) const MEMORY_MD_FRAMING: &str =
- "### Long-term memory (background — not this conversation)\n\n\
-The block below is your durable, cross-session memory: facts and observations \
-carried over from *past* sessions and previously ingested history. Treat it as \
-background knowledge only — it is **not** part of the current thread. Do not \
-treat it as messages already exchanged here, never claim you \"already covered \
-this in a previous chat\" or otherwise assert continuity that isn't present in \
-the visible messages, and answer each new thread in full even when related \
-prior context appears here.\n\n";
-
/// Renders the personality roster for the master agent's system prompt.
///
/// When [`PromptContext::personality_roster`] is non-empty, emits an
@@ -262,76 +210,10 @@ impl PromptSection for IdentitySection {
inject_workspace_file(&mut prompt, ctx.workspace_dir, file);
}
- // PROFILE.md / MEMORY.md injection lives in the dedicated
- // `UserFilesSection` (below) so agents that strip the identity
- // preamble (`omit_identity = true`) — welcome, orchestrator, the
- // trigger pair — still get their user files at runtime via
- // `SystemPromptBuilder::for_subagent`, which omits
- // `IdentitySection` entirely when `omit_identity` is set.
-
Ok(prompt)
}
}
-impl PromptSection for UserFilesSection {
- fn tier(&self) -> PromptTier {
- // PROFILE.md / MEMORY.md — rewritten by the archivist and by onboarding.
- PromptTier::Volatile
- }
-
- fn name(&self) -> &str {
- "user_files"
- }
-
- fn build(&self, ctx: &PromptContext<'_>) -> Result<String> {
- // Gate on the per-agent flags derived from
- // `AgentDefinition::omit_profile` / `omit_memory_md`. Both files
- // are user-specific, potentially growing, and capped at
- // [`USER_FILE_MAX_CHARS`] (~1000 tokens) so they can't bloat the
- // cached prefix.
- //
- // KV-cache contract: once injected into a session's rendered
- // prompt, the bytes are frozen for the remainder of that
- // session — any mid-session archivist write or enrichment
- // refresh lands on the NEXT session, never the in-flight one.
- let mut out = String::new();
- if ctx.include_profile {
- inject_workspace_file_capped(
- &mut out,
- ctx.workspace_dir,
- "PROFILE.md",
- USER_FILE_MAX_CHARS,
- );
- }
- if ctx.include_memory_md {
- // Prefer the session-frozen curated-memory snapshot, then the
- // workspace file (pure prompt-unit tests and older call sites).
- //
- // Render into a scratch buffer first so the `MEMORY_MD_FRAMING`
- // note is only emitted when the block actually carries content —
- // the inject helpers silently skip empty/missing files, and a
- // dangling frame pointing at nothing would be worse than none.
- let mut mem = String::new();
- if let Some(snap) = &ctx.curated_snapshot {
- inject_snapshot_content(&mut mem, "MEMORY.md", &snap.memory, USER_FILE_MAX_CHARS);
- inject_snapshot_content(&mut mem, "USER.md", &snap.user, USER_FILE_MAX_CHARS);
- } else {
- inject_workspace_file_capped(
- &mut mem,
- ctx.workspace_dir,
- "MEMORY.md",
- USER_FILE_MAX_CHARS,
- );
- }
- if !mem.trim().is_empty() {
- out.push_str(MEMORY_MD_FRAMING);
- out.push_str(&mem);
- }
- }
- Ok(out)
- }
-}
-
impl PromptSection for AgentsInstructionsSection {
fn tier(&self) -> PromptTier {
// AGENTS.md layers: per project and per install, stable within a session.
@@ -555,100 +437,6 @@ impl PromptSection for RuntimeSection {
}
}
-impl PromptSection for UserReflectionsSection {
- fn tier(&self) -> PromptTier {
- // Learned reflections, refreshed by the learning subsystem.
- PromptTier::Volatile
- }
-
- fn name(&self) -> &str {
- "user_reflections"
- }
-
- fn build(&self, ctx: &PromptContext<'_>) -> Result<String> {
- if ctx.learned.reflections.is_empty() {
- return Ok(String::new());
- }
-
- let mut out = String::from("## User Reflections\n\n");
- out.push_str(
- "Explicit reflections the user authored about themselves, their goals, \
- or how they want you to behave going forward. Treat these as \
- higher-priority than the broader user-memory summaries below: \
- they are recent, intentional, identity-relevant signals and \
- should steer your responses ahead of any generic historical \
- context.\n\n",
- );
- for reflection in &ctx.learned.reflections {
- let trimmed = reflection.trim();
- if trimmed.is_empty() {
- continue;
- }
- out.push_str("- ");
- out.push_str(trimmed);
- out.push('\n');
- }
- out.push('\n');
- Ok(out)
- }
-}
-
-impl PromptSection for UserMemorySection {
- fn tier(&self) -> PromptTier {
- // The memory-tree summary, which moves on every memory write.
- PromptTier::Volatile
- }
-
- fn name(&self) -> &str {
- "user_memory"
- }
-
- fn build(&self, ctx: &PromptContext<'_>) -> Result<String> {
- if ctx.learned.tree_root_summaries.is_empty() {
- return Ok(String::new());
- }
-
- let mut out = String::from("## User Memory\n\n");
- out.push_str(
- "Long-term memory distilled by the tree summarizer. \
- Each section is the root summary for a memory namespace, \
- representing everything we've learned about that domain over time. \
- Treat this as durable background context, but NOT as fresh, \
- present-tense fact: each section header shows when that memory \
- was last updated. Compare those dates against the `## Current \
- Date & Time` section below before answering time-sensitive \
- questions (today's briefing, daily summary, reminders, calendar, \
- notifications, \"today/tomorrow/this week\"). If a summary predates \
- the period the user is asking about, treat it as potentially \
- stale — say so explicitly and never present older memory as \
- today's update.\n\n",
- );
-
- for NamespaceSummary {
- namespace,
- body,
- updated_at,
- } in &ctx.learned.tree_root_summaries
- {
- let trimmed = body.trim();
- if trimmed.is_empty() {
- continue;
- }
- // Absolute date (not "N days ago") keeps this front-of-prompt
- // section byte-stable for KV-cache reuse — see `NamespaceSummary`.
- let _ = writeln!(
- out,
- "### {namespace} (last updated {})\n",
- super::render_helpers::memory_date_label(*updated_at)
- );
- out.push_str(trimmed);
- out.push_str("\n\n");
- }
-
- Ok(out)
- }
-}
-
impl PromptSection for DateTimeSection {
fn tier(&self) -> PromptTier {
// The live clock is carried in the user message. This section is static.