The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(prompts): add render helpers for agent prompt sections
Steven Enamakelf4d4e8c69ab1
diff --git a/crates/openhuman-core/src/agent/prompts/mod.rs b/crates/openhuman-core/src/agent/prompts/mod.rsindex ee64def1b7..16a9c6a1ff 100644--- a/crates/openhuman-core/src/agent/prompts/mod.rs+++ b/crates/openhuman-core/src/agent/prompts/mod.rs@@ -19,11 +19,10 @@ pub use sections::*;pub mod render_helpers;pub use render_helpers::{current_datetime_line, default_workspace_file_content, inject_inline_content,- inject_snapshot_content, inject_workspace_file, inject_workspace_file_capped,- memory_date_label, render_ambient_environment, render_datetime, render_identity,- render_runtime, render_safety, render_subagent_system_prompt,- render_subagent_system_prompt_with_format, render_tools, render_user_files,- render_user_identity, render_user_reflections, render_workspace, sync_workspace_file,+ inject_workspace_file, inject_workspace_file_capped, render_ambient_environment,+ render_datetime, render_identity, render_runtime, render_safety,+ render_subagent_system_prompt, render_subagent_system_prompt_with_format, render_tools,+ render_user_identity, render_workspace, sync_workspace_file,};#[cfg(test)]diff --git a/crates/openhuman-core/src/agent/prompts/render_helpers.rs b/crates/openhuman-core/src/agent/prompts/render_helpers.rsindex aad757c777..abc4946745 100644--- a/crates/openhuman-core/src/agent/prompts/render_helpers.rs+++ b/crates/openhuman-core/src/agent/prompts/render_helpers.rs@@ -8,7 +8,7 @@//!//! Split by responsibility://! - [`section_renderers`] — the `render_*` wrappers, per-turn datetime stamp,-//! ambient-environment composer, and memory date label.+//! and ambient-environment composer.//! - [`subagent`] — the narrow KV-cache-stable sub-agent prompt renderer.//! - [`workspace_files`] — workspace-file seeding and prompt injection.@@ -17,14 +17,13 @@ mod subagent;mod workspace_files;pub use section_renderers::{- current_datetime_line, memory_date_label, render_ambient_environment, render_datetime,- render_identity, render_runtime, render_safety, render_tools, render_user_files,- render_user_identity, render_user_reflections, render_workspace,+ current_datetime_line, render_ambient_environment, render_datetime, render_identity,+ render_runtime, render_safety, render_tools, render_user_identity, render_workspace,};pub(crate) use subagent::harness_json_tool_prompt;pub use subagent::{render_subagent_system_prompt, render_subagent_system_prompt_with_format};pub(crate) use workspace_files::write_agents_md_blocks;pub use workspace_files::{- default_workspace_file_content, inject_inline_content, inject_snapshot_content,- inject_workspace_file, inject_workspace_file_capped, sync_workspace_file,+ default_workspace_file_content, inject_inline_content, inject_workspace_file,+ inject_workspace_file_capped, sync_workspace_file,};diff --git a/crates/openhuman-core/src/agent/prompts/render_helpers/section_renderers.rs b/crates/openhuman-core/src/agent/prompts/render_helpers/section_renderers.rsindex a4e60aebd2..bc0e371abe 100644--- a/crates/openhuman-core/src/agent/prompts/render_helpers/section_renderers.rs+++ b/crates/openhuman-core/src/agent/prompts/render_helpers/section_renderers.rs@@ -5,7 +5,6 @@use super::super::sections::*;use super::super::types::*;use anyhow::Result;-use chrono::{DateTime, Utc};use std::sync::OnceLock;// ─────────────────────────────────────────────────────────────────────────────@@ -18,19 +17,6 @@ pub fn render_identity(ctx: &PromptContext<'_>) -> Result<String> {IdentitySection.build(ctx)}-/// Render the `PROFILE.md` + `MEMORY.md` user-file injection.-/// Empty when neither `ctx.include_profile` nor `ctx.include_memory_md`-/// is set.-pub fn render_user_files(ctx: &PromptContext<'_>) -> Result<String> {- UserFilesSection.build(ctx)-}--/// Render the privileged `## User Reflections` block. Empty when the-/// learning subsystem has not captured any reflections yet.-pub fn render_user_reflections(ctx: &PromptContext<'_>) -> Result<String> {- UserReflectionsSection.build(ctx)-}-/// Render the `## Tools` catalogue in the dispatcher's tool-call format.pub fn render_tools(ctx: &PromptContext<'_>) -> Result<String> {ToolsSection.build(ctx)@@ -159,20 +145,6 @@ pub fn render_ambient_environment(ctx: &PromptContext<'_>) -> Result<String> {Ok(out)}-/// Format a memory item's `updated_at` as an absolute UTC date label-/// for prompt injection, e.g. `2026-05-25`.-///-/// Absolute (not relative "N days ago") on purpose: memory sections sit-/// near the front of the KV-cache-stable system prompt, so a label that-/// changes daily would bust the cached prefix for everything after it.-/// An absolute date only changes when the underlying memory does. The-/// model judges staleness by comparing this against the injected current-/// date. Shared by [`UserMemorySection`] and the working-memory block in-/// `agent_memory::memory_loader`. (#2944)-pub fn memory_date_label(updated_at: DateTime<Utc>) -> String {- updated_at.format("%Y-%m-%d").to_string()-}-// ─────────────────────────────────────────────────────────────────────────────// Internal helpers// ─────────────────────────────────────────────────────────────────────────────@@ -197,14 +169,10 @@ fn empty_prompt_context_for_static_sections() -> PromptContext<'static> {tools: EMPTY_TOOLS,workflows: EMPTY_WORKFLOWS,dispatcher_instructions: "",- learned: LearnedContextData::default(),visible_tool_names: visible,tool_call_format: ToolCallFormat::PFormat,connected_integrations: EMPTY_INTEGRATIONS,connected_identities_md: String::new(),- include_profile: false,- include_memory_md: false,- curated_snapshot: None,user_identity: None,personality_roster: vec![],agents_md_global: None,diff --git a/crates/openhuman-core/src/agent/prompts/render_helpers/subagent.rs b/crates/openhuman-core/src/agent/prompts/render_helpers/subagent.rsindex 0391928a3d..6b85cd2396 100644--- a/crates/openhuman-core/src/agent/prompts/render_helpers/subagent.rs+++ b/crates/openhuman-core/src/agent/prompts/render_helpers/subagent.rs@@ -5,11 +5,9 @@//! for callers that only hold indices into the parent's tool vec.use super::super::builder::GLOBAL_STYLE_SUFFIX;-use super::super::sections::{GROUNDING_BODY, MEMORY_MD_FRAMING};+use super::super::sections::GROUNDING_BODY;use super::super::types::*;-use super::workspace_files::{- inject_workspace_file, inject_workspace_file_capped, write_agents_md_blocks,-};+use super::workspace_files::{inject_workspace_file, write_agents_md_blocks};use std::fmt::Write;use std::path::Path;use tinytools_agent::dialect::{CodeDialect, NativeDialect, PFormatDialect, ToolDialect};@@ -88,7 +86,7 @@ pub fn render_subagent_system_prompt(/// `agents_md_global` / `agents_md_local` are the pre-loaded AGENTS.md layers/// (see [`crate::agent::prompts::agents_md::load_agents_md_layers`]); `None`/`None` (the value/// the public wrapper passes) renders no AGENTS.md block. When present they are-/// injected as `## Project instructions (AGENTS.md)` right after the user files+/// injected as `## Project instructions (AGENTS.md)` right after the identity block/// and before the tool catalogue — matching the section order of the default //// sub-agent builders.#[allow(clippy::too_many_arguments)]@@ -131,40 +129,10 @@ pub fn render_subagent_system_prompt_with_format(}}- // 1c. PROFILE.md (onboarding enrichment output) and MEMORY.md- // (archivist-curated long-term memory). Each is gated on its own- // flag and capped at `USER_FILE_MAX_CHARS` (~1000 tokens) so a- // growing on-disk file can't push the system prompt out of the- // cache-friendly prefix range.- //- // KV-cache contract: once these files land in a session's- // rendered prompt the bytes are frozen for the remainder of that- // session. Do not re-read them mid-turn — a byte change breaks- // the backend's automatic prefix cache. Mid-session writes to- // either file are intentionally only visible on the NEXT session.- if options.include_profile {- inject_workspace_file_capped(&mut out, workspace_dir, "PROFILE.md", USER_FILE_MAX_CHARS);- }- if options.include_memory_md {- // Frame MEMORY.md as durable, cross-session background memory —- // byte-identical to `UserFilesSection::build` (GH-4745). Without the- // frame an Inline/File sub-agent on a brand-new thread reads the bare- // `### MEMORY.md` block as prior in-thread conversation and asserts- // continuity that isn't there. Buffer first so the note is emitted- // only when the file actually carries content — a dangling frame- // pointing at nothing would itself imply phantom history.- let mut mem = String::new();- inject_workspace_file_capped(&mut mem, workspace_dir, "MEMORY.md", USER_FILE_MAX_CHARS);- if !mem.trim().is_empty() {- out.push_str(MEMORY_MD_FRAMING);- out.push_str(&mem);- }- }-- // 1d. Project instructions (AGENTS.md), pre-loaded by the caller and shared+ // 1c. Project instructions (AGENTS.md), pre-loaded by the caller and shared// with the section-based builders through `write_agents_md_blocks` so// the byte layout can never drift between the two paths. Placed after- // the user files and before the tool catalogue, matching the default+ // the identity block and before the tool catalogue, matching the default// section order. Skipped entirely when both layers are `None`.write_agents_md_blocks(&mut out, agents_md_global, agents_md_local);diff --git a/crates/openhuman-core/src/agent/prompts/render_helpers/workspace_files.rs b/crates/openhuman-core/src/agent/prompts/render_helpers/workspace_files.rsindex 197ee9e91c..f6babc645c 100644--- a/crates/openhuman-core/src/agent/prompts/render_helpers/workspace_files.rs+++ b/crates/openhuman-core/src/agent/prompts/render_helpers/workspace_files.rs@@ -110,8 +110,8 @@ pub fn inject_workspace_file(prompt: &mut String, workspace_dir: &Path, filename}/// Inject pre-loaded string content into `prompt` under a `### label` heading,-/// capped at `max_chars`. Mirrors the format of [`inject_snapshot_content`]-/// and [`inject_workspace_file_capped`] but takes a `&str` instead of a file+/// capped at `max_chars`. Mirrors the format of+/// [`inject_workspace_file_capped`] but takes a `&str` instead of a file/// path. Used for pre-loaded prompt sections that need the same rendering as/// workspace-file content.///@@ -183,42 +183,9 @@ pub(crate) fn write_agents_md_blocks(out: &mut String, global: Option<&str>, locout.push_str(&body);}-/// for the output header and truncation semantics.-///-/// Empty/whitespace content is silently skipped, mirroring the file-/// loader's "no noisy placeholder" behaviour.-pub fn inject_snapshot_content(prompt: &mut String, label: &str, content: &str, max_chars: usize) {- let trimmed = content.trim();- if trimmed.is_empty() {- return;- }- let _ = writeln!(prompt, "### {label}\n");- let truncated = if trimmed.chars().count() > max_chars {- trimmed- .char_indices()- .nth(max_chars)- .map(|(idx, _)| &trimmed[..idx])- .unwrap_or(trimmed)- } else {- trimmed- };- prompt.push_str(truncated);- if truncated.len() < trimmed.len() {- let _ = writeln!(- prompt,- "\n\n[... truncated at {max_chars} chars — use `read` for full file]\n"- );- } else {- prompt.push_str("\n\n");- }-}-/// Inject `filename` into `prompt` with an explicit character budget.///-/// Used directly by callers that want a tighter cap than-/// [`BOOTSTRAP_MAX_CHARS`] — notably `PROFILE.md` and `MEMORY.md` which-/// are user-specific, potentially growing, and do not warrant a full-/// 20K-char budget (see [`USER_FILE_MAX_CHARS`]).+/// [`inject_workspace_file`] calls this with [`BOOTSTRAP_MAX_CHARS`].////// Missing / empty files are silently skipped so callers can inject/// optional files unconditionally without emitting a noisy placeholder.