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
chore: files changed crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs
Steven Enamakel007d662ce775
diff --git a/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs b/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rsindex 86d71f0c83..c357f97c7c 100644--- a/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs+++ b/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs@@ -26,22 +26,15 @@ use std::fmt::Write;const ARCHETYPE: &str = include_str!("prompt.md");pub fn build(ctx: &PromptContext<'_>) -> Result<String> {- let mut out = String::with_capacity(8192);+ use crate::agent::prompts::{PROMPT_TIER_CONTEXT_MARKER, PROMPT_TIER_VOLATILE_MARKER};- // Identity leads the prompt (#5701): SOUL.md is the product persona every- // opted-in agent shares, ROLE.md is this agent's own role brief. Both are- // workspace files, so tuning either is an edit rather than a rebuild.- //- // Rendered here rather than via `IdentitySection` because the orchestrator- // is a `PromptSource::Dynamic` agent: `SystemPromptBuilder::from_dynamic`- // installs only this builder and never consults `omit_identity`, so the- // section chain that would otherwise inject these files does not run for- // us. Same reason `render_user_files` is called by hand just below.- let identity = render_identity(ctx)?;- if !identity.trim().is_empty() {- out.push_str(identity.trim_end());- out.push_str("\n\n");- }+ let mut out = String::with_capacity(8192);+ let mut push = |out: &mut String, part: &str| {+ if !part.trim().is_empty() {+ out.push_str(part.trim_end());+ out.push_str("\n\n");+ }+ };// Resolved once: the same three routes decide both the static rows below// and the generated sections further down, and they must agree (#6302).@@ -49,79 +42,64 @@ pub fn build(ctx: &PromptContext<'_>) -> Result<String> {let skill_install = hand_off_route(ctx, "skill_setup");let mcp_route = hand_off_route(ctx, "mcp_agent");- let archetype = strip_route_lines(- ARCHETYPE,- skill_run.is_some() || skill_install.is_some(),- mcp_route.is_some(),+ // ── Stable tier: identical across sessions for a given build ─────────+ //+ // Identity leads the prompt (#5701): SOUL.md is the product persona every+ // opted-in agent shares, ROLE.md is this agent's own role brief. Rendered+ // here rather than via `IdentitySection` because the orchestrator is a+ // `PromptSource::Dynamic` agent: `SystemPromptBuilder::from_dynamic`+ // installs only this builder, so the section chain never runs for us.+ push(&mut out, &render_identity(ctx)?);+ push(+ &mut out,+ &strip_route_lines(+ ARCHETYPE,+ skill_run.is_some() || skill_install.is_some(),+ mcp_route.is_some(),+ ),);- out.push_str(archetype.trim_end());- out.push_str("\n\n");-- let user_files = render_user_files(ctx)?;- if !user_files.trim().is_empty() {- out.push_str(user_files.trim_end());- out.push_str("\n\n");- }-- let identities = ctx.connected_identities_md.as_str();- if !identities.trim().is_empty() {- out.push_str(identities.trim_end());- out.push_str("\n\n");+ push(&mut out, &render_tools(ctx)?);+ push(&mut out, &render_datetime(ctx)?);++ // ── Context tier: stable for the session, not across installs ────────+ out.push_str(PROMPT_TIER_CONTEXT_MARKER);+ out.push('\n');+ push(&mut out, &render_workspace(ctx)?);+ // Model families that stop after announcing a plan get one short block of+ // execution discipline; the rest (Claude, Gemini) pay nothing. The text+ // and the gate are tinyagents', so every host renders the same words.+ if let Some(guidance) =+ tinyagents_harness::prompt::execution_discipline_for(ctx.model_name)+ {+ tracing::debug!(+ model = ctx.model_name,+ "[orchestrator-prompt] rendering model-gated execution discipline"+ );+ push(&mut out, guidance);}- let skills = render_installed_skills(- ctx.workflows,- skill_run.as_deref(),- skill_install.as_deref(),+ // ── Volatile tier: the user's state, changes between sessions ────────+ out.push_str(PROMPT_TIER_VOLATILE_MARKER);+ out.push('\n');+ push(&mut out, &render_user_files(ctx)?);+ push(&mut out, ctx.connected_identities_md.as_str());+ push(+ &mut out,+ &render_installed_skills(+ ctx.workflows,+ skill_run.as_deref(),+ skill_install.as_deref(),+ ),);- if !skills.trim().is_empty() {- out.push_str(skills.trim_end());- out.push_str("\n\n");- }-- let withheld = render_withheld_specialists(ctx);- if !withheld.trim().is_empty() {- out.push_str(withheld.trim_end());- out.push_str("\n\n");- }-- let integrations = render_delegation_guide(ctx.connected_integrations, ctx.tool_call_format);- if !integrations.trim().is_empty() {- out.push_str(integrations.trim_end());- out.push_str("\n\n");- }-- let mcp_servers = render_connected_mcp_servers(mcp_route.as_deref());- if !mcp_servers.trim().is_empty() {- out.push_str(mcp_servers.trim_end());- out.push_str("\n\n");- }-- let tools = render_tools(ctx)?;- if !tools.trim().is_empty() {- out.push_str(tools.trim_end());- out.push_str("\n\n");- }-- // NOTE: the shared grounding / anti-hallucination contract is appended- // centrally by `SystemPromptBuilder::build` (and the narrow sub-agent- // renderer), so every agent inherits it without each `prompt.rs` having- // to splice it in. Do not render it here, or it will appear twice.-- let datetime = render_datetime(ctx)?;- if !datetime.trim().is_empty() {- out.push_str(datetime.trim_end());- out.push_str("\n\n");- }-- // The Master Agent can execute coding work directly, so it needs the- // canonical action-root instructions before it receives the tool list.- let workspace = render_workspace(ctx)?;- if !workspace.trim().is_empty() {- out.push_str(workspace.trim_end());- out.push_str("\n\n");- }+ push(&mut out, &render_withheld_specialists(ctx));+ push(+ &mut out,+ &render_delegation_guide(ctx.connected_integrations, ctx.tool_call_format),+ );+ push(&mut out, &render_connected_mcp_servers(mcp_route.as_deref()));+ // NOTE: the grounding contract lives in `prompt.md` under the shared+ // heading, so `SystemPromptBuilder::build` skips the global copy.Ok(out)}@@ -210,14 +188,12 @@ fn render_withheld_specialists(ctx: &PromptContext<'_>) -> String {);let mut out = String::from(- "## Capabilities not in your tool list\n\nThese exist but their schemas are not \- loaded. Reach one with `use_skill { \"skill\": \"<skill>\", \"tool\": \"<tool>\", \- \"args\": { … } }`; call `use_skill` with the `skill` alone first to read the \- tool's arguments. Do not tell the user a capability is unavailable because it \- is listed here.\n\n",+ "## Capabilities not in your tool list\n\nReach these with `use_skill` \+ (`skill` alone lists a tool's arguments; `skill` + `tool` + `args` runs it). \+ They are available, not missing.\n\n",);for (tool, intent, pack) in rows {- let _ = writeln!(out, "- {intent} — skill `{pack}`, tool `{tool}`.");+ let _ = writeln!(out, "- `{pack}` / `{tool}`: {intent}");}out}@@ -329,6 +305,10 @@ fn resolve_definition<'r>(/// `when_to_use` is written as a paragraph for the tool description; one/// sentence is the routing signal and the rest is detail the model only needs/// once it has loaded the schema.+/// Longest routing intent a withheld-specialist row carries. One sentence is+/// the signal; the full `when_to_use` is on the tool once it is loaded.+const WITHHELD_INTENT_MAX_CHARS: usize = 90;+fn first_sentence(text: &str) -> String {let text = text.trim();for (idx, _) in text.match_indices(". ") {@@ -342,14 +322,18 @@ fn first_sentence(text: &str) -> String {.next().is_some_and(|c| c.is_uppercase());if !is_abbreviation && starts_new {- return text[..=idx].trim_end().to_string();+ let sentence = text[..=idx].trim_end();+ if sentence.chars().count() <= WITHHELD_INTENT_MAX_CHARS {+ return sentence.to_string();+ }+ break;}}- if text.chars().count() <= 200 {+ if text.chars().count() <= WITHHELD_INTENT_MAX_CHARS {return text.to_string();}- let cut: String = text.chars().take(200).collect();- format!("{}…", cut.trim_end())+ let cut: String = text.chars().take(WITHHELD_INTENT_MAX_CHARS).collect();+ format!("{}...", cut.trim_end())}/// Render the `## Installed Skills` section listing locally installed@@ -376,26 +360,16 @@ fn render_installed_skills(install_route = install.is_some(),"[orchestrator-prompt] rendering installed skills section");- let mut out = String::from(- "## Installed Skills\n\n\- These skills are installed locally, and running one is the point of listing them. ",- );+ let mut out = String::from("## Installed Skills\n\n");if let Some(run) = run {- let _ = write!(- out,- "Run one by handing it to {run} with the skill id and the task. "- );+ let _ = write!(out, "Run one with {run} (skill id + task). ");}if let Some(install) = install {- let _ = write!(- out,- "To find or install a skill that is not listed, hand the request to {install}. "- );+ let _ = write!(out, "Find or install others with {install}. ");}out.push_str(- "A skill runs in an isolated worker and returns only its result, plus a \- `## Handoff Plan` for any step the worker couldn't perform — carry those out \- yourself, under the approval gate.\n\n",+ "A skill runs in an isolated worker and returns its result plus a `## Handoff Plan` \+ for anything it could not do itself.\n\n",);for skill in skills {let id = if skill.dir_name.is_empty() {@@ -411,7 +385,7 @@ fn render_installed_skills(// chars / instruction fences) and cap so a single installed// skill can't bloat the prompt or smuggle routing instructions;// full details stay one `describe_workflow` call away.- crate::util::sanitize::sanitize_for_llm(&skill.description, 240)+ crate::util::sanitize::sanitize_for_llm(&skill.description, 120).replace(['\n', '\t'], " ").trim().to_string()@@ -469,17 +443,14 @@ fn format_connected_mcp_block(Some(route) => {let _ = write!(out,- "IMPORTANT: The user has connected the MCP server(s) below. To act on any request \- a connected server can satisfy, you MUST hand it to {route}. You do NOT have \- direct access to these servers, and you must never claim you can't do something \- a connected server clearly can without handing it off first. {route} routes to \- the MCP agent, which discovers the server's tools and calls the right one. Pass \- a plain-language task; do not pass server ids or tool names yourself.\n\n"+ "Anything one of these servers can satisfy goes to {route} as a plain-language \+ task; you have no direct access to them, so never say you can't before \+ handing off.\n\n");}None => out.push_str(- "The user has connected the MCP server(s) below, but no MCP hand-off is \- available to you in this session, so you cannot use them here.\n\n",+ "Connected, but no MCP hand-off is available to you in this session, so you \+ cannot use them here.\n\n",),}for s in servers {@@ -510,7 +481,7 @@ fn format_connected_mcp_block(let capability = if capability_raw.is_empty() {String::new()} else {- crate::util::sanitize::sanitize_for_llm(capability_raw, 240)+ crate::util::sanitize::sanitize_for_llm(capability_raw, 120).replace(['\n', '\t'], " ").trim().to_string()@@ -573,17 +544,11 @@ fn render_delegation_guide(}let mut out = String::from("## Connected Integrations\n\n\- IMPORTANT: You MUST use the `delegate_to_integrations_agent` tool for any request \- involving connected services. You do NOT have direct access to these services — all \- interaction must go through delegation. Delegate here ONLY when the request actually \- operates on a connected service's data or actions; a connected service is not a reason \- to touch it for general-knowledge, web/news, headline, date/time, or math questions. \- Never claim you cannot access a connected \- service without first attempting delegation.\n\n\- The following services have an active connection. Their tool implementations \- live inside the `integrations_agent` sub-agent — NOT in your own tool list. \- Delegate with `delegate_to_integrations_agent`, passing the toolkit slug as \- `toolkit`:\n\n",+ Their tools live in `integrations_agent`, not in your list: act on them only through \+ `delegate_to_integrations_agent` with the toolkit slug, and only when the request \+ operates on that service's data or actions (a connected service is not a reason to \+ touch it for general-knowledge, web/news, date/time or math questions). Never claim \+ you cannot access one without delegating first.\n\n",);for ci in connected {// Use the same slug canonicalisation as `collect_orchestrator_tools`@@ -635,45 +600,14 @@ fn render_delegation_guide(let _ = write!(out,"\n### Capability questions about connected toolkits\n\n\- Your prior knowledge of \"what a toolkit can do\" is UNRELIABLE — the \- real per-toolkit catalogue is wider than the common-knowledge summary \- (e.g. Gmail exposes bulk delete, batch modify, thread trash, etc.) and \- the user may have enabled scopes that expose further destructive actions. \- Therefore:\n\n\- - If the user asks **\"can you do X with {{toolkit}}?\"** or \"does \- {{toolkit}} support Y?\" for a connected toolkit above, **DO NOT** answer \- from priors. **DELEGATE** to `integrations_agent` first and let it \- inspect its live tool list (including `gated_tools` behind permission \- toggles) before answering.\n\- - If the user requests an **action** on a connected toolkit (delete, \- move, send, modify, label, etc.), **DELEGATE immediately**. Do not \- pre-emptively refuse with \"I can't do that\" — that's a confabulation \- unless `integrations_agent` itself has already reported the action as \- unavailable.\n\- - The only honest \"no\" comes back from a delegation that found the \- action neither in the visible `tools` list nor in the `gated_tools` \- (permission-toggle) list of the sub-agent.\n\- - **Cross-chat context is historical, not authoritative.** If the \- `{cross_chat_header_for_prompt}` block contains a past \"I can / can't \- do X with {{toolkit}}\" statement, treat it as a snapshot from an \- earlier moment. The tool list, connected integrations, and per-toolkit \- scope toggles (read / write / admin) can all change between chats — a \- past refusal may be stale. Verify against the **current** `## Connected \- Integrations` block above and (when in doubt) **DELEGATE** before \- quoting any past capability claim. Never echo a stale \"I can't\" \- without re-checking.\n\n",+ Your prior knowledge of what a toolkit can do is unreliable: the live catalogue and \+ the user's scopes decide. For \"can you do X with {{toolkit}}?\" or any action on a \+ connected toolkit, delegate first and let `integrations_agent` inspect its tools \+ (including `gated_tools`); the only honest \"no\" is one it reported. A past \+ \"I can / can't\" in the `{cross_chat_header_for_prompt}` block is a stale snapshot, \+ never an answer.\n\n",);- // Provider-aware guardrail (#4361). Native-tool-calling providers keep the- // guide byte-identical. Text-protocol providers (PFormat/Json) — the- // dispatcher used when a model forces `native_tool_calling = false`, i.e.- // local runtimes (Ollama / LM Studio / MLX / llama.cpp) — see the whole- // tool catalogue rendered as prose and are steered by the coercive "you- // MUST delegate" wording above. Weaker local models then route obviously- // non-integration requests (greetings, local folder/file actions) into- // `delegate_to_integrations_agent`, which surfaces "Viewing your- // Connections" / calendar mis-maps. Carve those cases out explicitly so a- // small model does not have to infer them from the coercive block alone.if tool_call_format != ToolCallFormat::Native {out.push_str("### When NOT to delegate\n\n\