Skip to content

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

feat(agent): add planner and critic built-in agents, remove old integration-spawn logic

Steven Enamakelb66e12d50cb6
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent.rs
index ce54db6575..19772d0748 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent.rs
@@ -224,84 +224,6 @@ fn render_worker_thread_result(
)
}
-/// Build the user-facing explanation for an allowlisted-but-not-active
-/// integration during an `integrations_agent` spawn (#2365).
-///
-/// The single message that previously covered every cause ("available
-/// but the user has not authorized it yet") looked confused to users
-/// who had Gmail showing in Settings (because Settings reflects the
-/// FE's optimistic post-OAuth view, while the spawn gate reads the
-/// backend's authoritative status). We now pivot on the upstream
-/// connection status:
-///
-/// - `INITIATED` / `INITIALIZING` / `PENDING` — OAuth in progress;
-/// ask the user to finish the flow in their browser.
-/// - `EXPIRED` — token rolled over; reconnect.
-/// - `FAILED` / `ERROR` — handshake didn't land; reconnect.
-/// - any other non-active status — quote the upstream verbatim.
-/// - `None` — no connection row at all (truly disconnected).
-///
-/// Returns text the model reads literally; the orchestrator paraphrases
-/// it into a user-facing reply. Keep the *intent* stable across
-/// rewordings — the "Connections → {toolkit}" path is
-/// load-bearing for the UI navigation tests.
-pub(crate) fn describe_unconnected_state(toolkit: &str, status: Option<&str>) -> String {
- // Keep the original (trimmed) status separately so the
- // unknown-status branch can quote it verbatim — CodeRabbit
- // review on #2373: matching on the uppercased value AND
- // formatting with that uppercased value broke the
- // "quote upstream status verbatim" contract for mixed/lowercase
- // wire shapes.
- let trimmed = status.map(str::trim).filter(|s| !s.is_empty());
- let upper = trimmed.map(|s| s.to_ascii_uppercase());
- match upper.as_deref() {
- Some("INITIATED") | Some("INITIALIZING") | Some("PENDING") => format!(
- "Integration '{toolkit}' has an OAuth flow in progress but it hasn't reached \
- ACTIVE yet. Do NOT retry this spawn. Tell the user the authorization is \
- pending and ask them to finish the browser OAuth flow (Connections → \
- '{toolkit}') before retrying. If they already closed the \
- browser tab, they can restart the connection from the same Connections page."
- ),
- Some("EXPIRED") => format!(
- "Integration '{toolkit}' is connected but the OAuth token has expired. \
- Do NOT retry this spawn. Tell the user the connection expired and ask \
- them to reconnect '{toolkit}' at Connections → '{toolkit}' \
- before retrying the original request."
- ),
- Some("FAILED") | Some("ERROR") => {
- // Quote the actual upstream label (FAILED / ERROR) instead of
- // hard-coding "FAILED" — triage cross-references backend logs
- // and a misquoted `ERROR` row showing up as "FAILED" wastes
- // their time. graycyrus review on #2373.
- let raw = trimmed.unwrap_or("");
- format!(
- "Integration '{toolkit}' has a previous OAuth attempt in a `{raw}` state. \
- Do NOT retry this spawn. Tell the user the connection failed and ask them \
- to reconnect '{toolkit}' at Connections → '{toolkit}' before \
- retrying the original request."
- )
- }
- Some(_) => {
- // Quote the *original* upstream status, not its uppercased
- // form — preserves "DeauthRequired" / "needs_relink"-style
- // mixed-case wire values for triage.
- let raw = trimmed.unwrap_or("");
- format!(
- "Integration '{toolkit}' has a connection row but its status is `{raw}`, \
- which is not yet usable. Do NOT retry this spawn. Tell the user the \
- connection is in an unusable state and ask them to reconnect '{toolkit}' \
- at Connections → '{toolkit}'."
- )
- }
- _ => format!(
- "Integration '{toolkit}' is available but the user has not authorized it \
- yet. Do NOT retry this spawn. Tell the user the integration is available \
- and ask them to authorize '{toolkit}' in Connections → \
- '{toolkit}' before retrying the original request."
- ),
- }
-}
-
#[cfg(test)]
#[path = "spawn_subagent_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rs
index 6c0a80cce0..7ea7ac5726 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rs
@@ -282,173 +282,3 @@ async fn async_default_self_heals_to_blocking_without_delivery_thread() {
"a raw tool call must reject missing typed authority: {out}"
);
}
-
-#[tokio::test]
-async fn integrations_agent_requires_toolkit_argument() {
- let _ = AgentDefinitionRegistry::init_global_builtins();
- let tool = SpawnSubagentTool;
- let result = tool
- .execute(json!({
- "agent_id": "integrations_agent",
- "prompt": "check gmail",
- }))
- .await
- .unwrap();
- assert!(result.is_error);
- let out = result.output();
- assert!(out.contains("`toolkit` argument is required"));
- assert!(out.contains("currently-connected toolkits"));
-}
-
-#[tokio::test]
-async fn integrations_agent_rejects_toolkit_outside_allowlist() {
- let _ = AgentDefinitionRegistry::init_global_builtins();
- let tool = SpawnSubagentTool;
- let toolkit = "totally_not_a_real_toolkit_slug";
- let result = tool
- .execute(json!({
- "agent_id": "integrations_agent",
- "prompt": "check gmail",
- "toolkit": toolkit,
- }))
- .await
- .unwrap();
- assert!(result.is_error);
- let out = result.output();
- assert!(out.contains(&format!(
- "toolkit '{toolkit}' is not in the backend allowlist"
- )));
- assert!(out.contains("Valid toolkits"));
-}
-
-// ── #2365: describe_unconnected_state per upstream status ───────
-
-#[test]
-fn describe_unconnected_state_initiated_says_oauth_in_progress() {
- let msg = describe_unconnected_state("gmail", Some("INITIATED"));
- assert!(
- msg.contains("OAuth flow in progress"),
- "INITIATED must surface the in-progress wording: {msg}"
- );
- assert!(msg.contains("Connections → 'gmail'"));
- // The legacy "not authorized yet" copy must NOT leak into the
- // pending-OAuth branch — that was the user-perception bug
- // from #2365 (Settings UI showed Gmail connected, agent said
- // "not authorized").
- assert!(
- !msg.contains("has not authorized it yet"),
- "INITIATED must not borrow the truly-disconnected copy: {msg}"
- );
-}
-
-#[test]
-fn describe_unconnected_state_pending_and_initializing_are_aliased() {
- for status in ["PENDING", "INITIALIZING"] {
- let msg = describe_unconnected_state("gmail", Some(status));
- assert!(
- msg.contains("OAuth flow in progress"),
- "{status} must hit the in-progress branch: {msg}"
- );
- }
-}
-
-#[test]
-fn describe_unconnected_state_expired_says_reconnect() {
- let msg = describe_unconnected_state("gmail", Some("EXPIRED"));
- assert!(msg.contains("OAuth token has expired"));
- assert!(msg.contains("reconnect 'gmail'"));
- assert!(msg.contains("Connections → 'gmail'"));
- assert!(!msg.contains("Settings → Connections"));
- assert!(!msg.contains("OAuth flow in progress"));
-}
-
-#[test]
-fn describe_unconnected_state_failed_and_error_route_to_reconnect() {
- for status in ["FAILED", "ERROR"] {
- let msg = describe_unconnected_state("gmail", Some(status));
- let expected = format!("`{status}` state");
- assert!(
- msg.contains(&expected),
- "{status} must be quoted verbatim, not collapsed to a single label: {msg}"
- );
- assert!(msg.contains("reconnect 'gmail'"));
- assert!(msg.contains("Connections → 'gmail'"));
- assert!(!msg.contains("Settings → Connections"));
- }
-}
-
-#[test]
-fn describe_unconnected_state_failed_and_error_preserve_original_casing() {
- // Mixed-case wire values must round-trip through the FAILED /
- // ERROR branch with their original casing intact — that's the
- // whole point of graycyrus' review feedback.
- let lower_failed = describe_unconnected_state("gmail", Some("failed"));
- assert!(
- lower_failed.contains("`failed` state"),
- "lowercase `failed` must be quoted verbatim: {lower_failed}"
- );
- let mixed_error = describe_unconnected_state("gmail", Some("Error"));
- assert!(
- mixed_error.contains("`Error` state"),
- "mixed-case `Error` must be quoted verbatim: {mixed_error}"
- );
-}
-
-#[test]
-fn describe_unconnected_state_quotes_unknown_status_verbatim() {
- // Pin three shapes (uppercase / mixed / snake_case) so the
- // verbatim-quoting contract can't silently drift back to
- // echoing the matched (uppercased) value — that was the
- // CodeRabbit finding on #2373.
- for raw in ["DEAUTH_REQUIRED", "needs_relink", "PartialAuthRequired"] {
- let msg = describe_unconnected_state("gmail", Some(raw));
- let expected = format!("`{raw}`");
- assert!(
- msg.contains(&expected),
- "unknown status `{raw}` must be quoted verbatim (not its uppercased form): {msg}"
- );
- assert!(msg.contains("Connections → 'gmail'"));
- assert!(!msg.contains("Settings → Connections"));
- }
-}
-
-#[test]
-fn describe_unconnected_state_quotes_unknown_status_after_trimming_whitespace() {
- // Whitespace-only / blank statuses must NOT hit the
- // unknown-status branch — they collapse to the
- // truly-disconnected legacy copy via the `filter(|s|
- // !s.is_empty())` guard in `describe_unconnected_state`.
- let blank = describe_unconnected_state("gmail", Some(" "));
- assert!(
- blank.contains("has not authorized it yet"),
- "whitespace-only status must collapse to legacy None branch: {blank}"
- );
- // A real status with surrounding whitespace is quoted with
- // the whitespace trimmed (not preserved verbatim — triage
- // would not want padded backticks).
- let padded = describe_unconnected_state("gmail", Some(" DeauthRequired "));
- assert!(
- padded.contains("`DeauthRequired`"),
- "trimmed status must be quoted in original casing: {padded}"
- );
-}
-
-#[test]
-fn describe_unconnected_state_none_is_truly_disconnected() {
- let msg = describe_unconnected_state("gmail", None);
- assert!(
- msg.contains("has not authorized it yet"),
- "None must hit the legacy never-connected copy: {msg}"
- );
- assert!(msg.contains("Connections → 'gmail'"));
-}
-
-#[test]
-fn describe_unconnected_state_status_match_is_case_insensitive() {
- // The status string flows in from Composio's wire format; we
- // can't assume casing. The classifier must normalise.
- let initiated = describe_unconnected_state("gmail", Some("initiated"));
- assert!(initiated.contains("OAuth flow in progress"));
- let expired = describe_unconnected_state("gmail", Some("Expired"));
- assert!(expired.contains("OAuth token has expired"));
-}
diff --git a/crates/openhuman-core/src/agent/registry/agents/critic/agent.toml b/crates/openhuman-core/src/agent/registry/agents/critic/agent.toml
new file mode 100644
index 0000000000..31b31baf38
--- /dev/null
+++ b/crates/openhuman-core/src/agent/registry/agents/critic/agent.toml
@@ -0,0 +1,21 @@
+id = "critic"
+display_name = "Critic"
+delegate_name = "review_code"
+when_to_use = "Adversarial read-only review of diffs and code: vulnerabilities, regressions, missing tests."
+temperature = 0.4
+max_iterations = 5
+# Bound the review verdict that flows up to the orchestrator verbatim
+# (delegate_critic). 8000 chars (~2000 tokens) matches the normal
+# sub-agent cap (planner) and keeps long diffs from leaking
+# an unbounded critique into the orchestrator's context (#4099).
+max_result_chars = 8000
+sandbox_mode = "read_only"
+omit_identity = true
+omit_memory_context = true
+omit_safety_preamble = true
+
+[model]
+hint = "agentic"
+
+[tools]
+named = ["read_diff", "run_linter", "run_tests", "file_read"]
diff --git a/crates/openhuman-core/src/agent/registry/agents/critic/mod.rs b/crates/openhuman-core/src/agent/registry/agents/critic/mod.rs
new file mode 100644
index 0000000000..8bf84783cb
--- /dev/null
+++ b/crates/openhuman-core/src/agent/registry/agents/critic/mod.rs
@@ -0,0 +1 @@
+pub mod prompt;
diff --git a/crates/openhuman-core/src/agent/registry/agents/critic/prompt.md b/crates/openhuman-core/src/agent/registry/agents/critic/prompt.md
new file mode 100644
index 0000000000..85c678facf
--- /dev/null
+++ b/crates/openhuman-core/src/agent/registry/agents/critic/prompt.md
@@ -0,0 +1,25 @@
+# Critic — Adversarial QA Reviewer
+
+You are the **Critic** agent. Your job is to find problems before they reach production.
+
+## Capabilities
+
+- Read git diffs to review changes
+- Run linters (clippy, eslint) and interpret findings
+- Run test suites and verify correctness
+- Read project files for context
+
+## Review Checklist
+
+1. **Security** — SQL injection, XSS, command injection, hardcoded secrets, OWASP top 10.
+2. **Correctness** — Edge cases, off-by-one errors, null/None handling, race conditions.
+3. **Style** — Naming conventions, code organization, consistency with existing patterns.
+4. **Tests** — Are new paths covered? Do existing tests still pass?
+5. **SOUL.md compliance** — Does the code align with the project's core principles?
+
+## Rules
+
+- **Be specific** — "Line 42: SQL string interpolation is injectable" not "code might have security issues".
+- **Prioritise** — Flag critical issues first (security > correctness > style).
+- **Be constructive** — Suggest fixes, not just complaints.
+- **Read-only** — You review but never modify code. Report findings to the Orchestrator.
diff --git a/crates/openhuman-core/src/agent/registry/agents/critic/prompt.rs b/crates/openhuman-core/src/agent/registry/agents/critic/prompt.rs
new file mode 100644
index 0000000000..0ced0e17e8
--- /dev/null
+++ b/crates/openhuman-core/src/agent/registry/agents/critic/prompt.rs
@@ -0,0 +1,36 @@
+//! System prompt builder for the `critic` built-in agent.
+//!
+//! Returns the final, fully-assembled system prompt — archetype body
+//! (from the sibling `prompt.md`) plus the same section helpers the
+//! runtime uses for every other agent.
+
+use crate::agent::prompts::{render_tools, render_user_files, render_workspace, PromptContext};
+use anyhow::Result;
+
+const ARCHETYPE: &str = include_str!("prompt.md");
+
+pub fn build(ctx: &PromptContext<'_>) -> Result<String> {
+ let mut out = String::with_capacity(4096);
+ 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 tools = render_tools(ctx)?;
+ if !tools.trim().is_empty() {
+ out.push_str(tools.trim_end());
+ out.push_str("\n\n");
+ }
+
+ let workspace = render_workspace(ctx)?;
+ if !workspace.trim().is_empty() {
+ out.push_str(workspace.trim_end());
+ out.push('\n');
+ }
+
+ Ok(out)
+}
diff --git a/crates/openhuman-core/src/agent/registry/agents/planner/agent.toml b/crates/openhuman-core/src/agent/registry/agents/planner/agent.toml
new file mode 100644
index 0000000000..45b915dd31
--- /dev/null
+++ b/crates/openhuman-core/src/agent/registry/agents/planner/agent.toml
@@ -0,0 +1,91 @@
+id = "planner"
+display_name = "Planner"
+delegate_name = "plan"
+when_to_use = "Break a genuinely complex task into a small DAG of subtasks with acceptance criteria, grounded in memory and the web. Read-only; returns JSON, not code."
+temperature = 0.4
+max_iterations = 8
+iteration_policy = "extended"
+max_result_chars = 8000
+sandbox_mode = "read_only"
+omit_identity = true
+omit_memory_context = false
+omit_safety_preamble = true
+# Memory is no longer pre-fetched eagerly before every turn. The planner
+# keeps `omit_memory_context = false`, so it still receives the cheap
+# per-turn memory recall; deep memory-tree walks are the orchestrator's
+# on-demand concern (`delegate_retrieve_memory`), and the orchestrator
+# hands the planner grounded context in the delegation prompt.
+
+# Spawn hierarchy: this is the deep-thinking tier (reasoning model hint).
+# The planner produces a DAG of leaf tasks for downstream workers; it
+# must NOT delegate to another `reasoning` agent. The loader rejects
+# any same-tier entry added to a future `subagents` list.
+agent_tier = "reasoning"
+
+[model]
+hint = "reasoning"
+
+[tools]
+# Read + research only. The planner produces plans — it never mutates
+# the workspace, memory, or state. Any writes the plan requires get
+# executed by downstream agents (code_executor, archivist, …) at the
+# orchestrator's direction.
+#
+# Composio meta-tools are included so the planner can inspect connected
+# integrations, list available actions, and pull data needed to ground
+# a plan. `sandbox_mode = "read_only"` above triggers the agent-level
+# gate in `composio_execute` that rejects Write/Admin-scoped action
+# slugs (#685), so the planner cannot send email / create pages / etc.
+# even though `composio_execute` is on this list. Only `Read`-scoped
+# actions slip past the gate.
+named = [
+ "memory_recall",
+ "file_read",
+ # NOTE: `agent_prepare_context` is intentionally NOT here. When the planner
+ # runs via `delegate_plan` it executes under the orchestrator's
+ # PARENT_CONTEXT (run_subagent filters the child tool surface but does not
+ # install a planner-scoped ParentExecutionContext), so a nested scout would
+ # render the orchestrator's visible catalog/session, not the planner's.
+ # Context scouting is the orchestrator's first-message job; keep it there.
+ # Read-only nav primitives from #1208. `edit`, `apply_patch`, `lsp`
+ # are intentionally NOT included — sandbox_mode = "read_only" above
+ # forbids workspace mutations, and downstream agents do the writing.
+ # `todo` lets the planner emit a structured todo list. (`todowrite` was
+ # a legacy alias that resolved to no registered tool, and `plan_exit`'s
+ # marker had no consumer, so both left.)
+ "grep",
+ "glob",
+ "list",
+ "todo",
+ "web_fetch",
+ "web_search_tool",
+ # Grounded answers + market-data lookups so plans can be anchored in
+ # real numbers (stock/crypto prices) and current web context, not just
+ # whatever the model happens to remember.
+ "web_answer_tool",
+ # Reads up to ten pages per call; with `web_answer_tool` `depth: "deep"`
+ # this is how the planner does its own multi-source research (there is no
+ # research sub-agent to hand it to).
+ "web_contents_tool",
+ "stock_quote",
+ "stock_exchange_rate",
+ "stock_crypto_series",
+ "stock_commodity",
+ "composio_list_toolkits",
+ "composio_list_connections",
+ "composio_list_tools",
+ "composio_execute",
+ # MCP discovery (read-only) so plans can be grounded in the user's
+ # connected MCP servers — what's connected (`mcp_registry_status`),
+ # which servers are installed (`mcp_registry_installed_list`), and what
+ # tools each connected server exposes (`mcp_registry_list_tools`). All
+ # three are `PermissionLevel::ReadOnly` (no side effects), so they fit
+ # the read-only sandbox. `mcp_registry_tool_call` is deliberately NOT
+ # here: unlike `composio_execute` (gated to Read-scoped slugs by the
+ # sandbox), an MCP tool call invokes an arbitrary server tool the core
+ # cannot classify as read vs. write, so there is no safe read-only gate.
+ # Executing connected-MCP tools stays with `mcp_agent` (`use_mcp_server`).
+ "mcp_registry_status",
+ "mcp_registry_installed_list",
+ "mcp_registry_list_tools",
+]
diff --git a/crates/openhuman-core/src/agent/registry/agents/planner/mod.rs b/crates/openhuman-core/src/agent/registry/agents/planner/mod.rs
new file mode 100644
index 0000000000..8bf84783cb
--- /dev/null
+++ b/crates/openhuman-core/src/agent/registry/agents/planner/mod.rs
@@ -0,0 +1 @@
+pub mod prompt;
diff --git a/crates/openhuman-core/src/agent/registry/agents/planner/prompt.md b/crates/openhuman-core/src/agent/registry/agents/planner/prompt.md
new file mode 100644
index 0000000000..c770362bfe
--- /dev/null
+++ b/crates/openhuman-core/src/agent/registry/agents/planner/prompt.md
@@ -0,0 +1,61 @@
+# Planner — Task Architect
+
+You are the **Planner** agent. Your job is to decompose a complex user goal into a **directed acyclic graph (DAG)** of discrete tasks.
+
+Before you plan, **gather context** so the plan is grounded in reality, not guesses:
+
+- Use `memory_recall` to search what we already know — past decisions, user preferences, project context, prior plans. Memory is cheap; planning blind is expensive.
+- Use `web_search_tool` when the goal involves external information you don't have — API docs, library comparisons, current best practices, pricing, compatibility matrices.
+- Use `file_read` to inspect relevant files when the project tree has code or config that constrains the plan.
+
+Only produce the plan JSON **after** you have the context you need. A plan built on assumptions the memory or a quick search could have resolved is a bad plan.
+
+## Output Format
+
+Return **only** valid JSON matching this schema:
+
+```json
+{
+ "root_goal": "the user's original goal",
+ "context_gathered": "Brief summary of what you learned from memory/search that shaped the plan",
+ "nodes": [
+ {
+ "id": "task-1",
+ "description": "Clear, actionable instruction for the sub-agent",
+ "agent_id": "code_executor",
+ "depends_on": [],
+ "acceptance_criteria": "How to verify this task is done correctly"
+ }
+ ]
+}
+```
+
+## Available Agent IDs
+
+- `code_executor` — Writes and runs code. Use for implementation tasks.
+- `tool_maker` — Writes polyfill scripts. Rarely needed in planning.
+- `critic` — Reviews code quality and security. Use after code changes.
+
+Web research is not a worker node: gather it yourself before planning with `web_answer_tool` (`depth: "deep"` for multi-source research, when offered), `web_search_tool` and `web_contents_tool`.
+
+## Rules
+
+0. **You are the reasoning tier.** The chat-tier Orchestrator handed off to you because the task needs sustained thinking. Compose plans for the **worker tier** — `code_executor`, `critic`, `archivist`. Connected-service actions belong to the orchestrator, not a worker. **Never delegate to another reasoning agent** (no planner-spawns-planner, no planner-spawns-orchestrator); the loader rejects this at boot, and the planned runtime depth gate will reject it at spawn time. If a single worker can't cover a node, split the node — don't smuggle a second reasoning hop in.
+1. **Gather before planning** — Search memory and the web first. Don't guess what you can look up.
+2. **Minimise tasks** — Use the fewest nodes needed. Don't over-decompose.
+3. **Dependencies matter** — Use `depends_on` to express ordering. Independent tasks run in parallel.
+4. **Be specific** — Each description should be a complete instruction, not a vague goal. Include relevant context you gathered.
+5. **Include acceptance criteria** — How will we know the task succeeded?
+6. **Simple goals = single node** — If the goal is straightforward, return exactly 1 node.
+7. **No cycles** — The graph must be a DAG (directed acyclic graph).
+8. **Max 8 nodes** — Keep plans manageable. Split larger projects into multiple plans.
+9. **Read-only** — You have no write tools. If a plan depends on saving an insight, facts, or artefacts, capture that as an explicit node (e.g. "archivist: store X") in the DAG so a downstream agent performs the write.
+
+## Long-horizon Artifacts
+
+Plans for long-horizon work should hand data between nodes by **path**, not by pasting it forward.
+
+- When a node produces a large deliverable (a report, a dataset, a generated document), say so in its description and have it written under `outputs/`.
+- Reference that path in the dependent node's description, so the downstream worker reads the file instead of receiving the payload through context.
+- `workspace/` is for per-node scratch that no later node needs.
+- Both directories are relative to the action directory. Plans must never target the core's internal workspace state.
diff --git a/crates/openhuman-core/src/agent/registry/agents/planner/prompt.rs b/crates/openhuman-core/src/agent/registry/agents/planner/prompt.rs
new file mode 100644
index 0000000000..bfff42de1d
--- /dev/null
+++ b/crates/openhuman-core/src/agent/registry/agents/planner/prompt.rs
@@ -0,0 +1,45 @@
+//! System prompt builder for the `planner` built-in agent.
+//!
+//! Returns the fully-assembled system prompt. Each agent's `build()`
+//! composes section helpers from [`crate::agent::prompts`]
+//! in the order it wants — so the output IS what the LLM sees, no
+//! post-processing in the runner.
+
+use crate::agent::prompts::{
+ render_datetime, render_tools, render_user_files, render_workspace, PromptContext,
+};
+use anyhow::Result;
+
+const ARCHETYPE: &str = include_str!("prompt.md");
+
+pub fn build(ctx: &PromptContext<'_>) -> Result<String> {
+ let mut out = String::with_capacity(4096);
+ 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 tools = render_tools(ctx)?;
+ if !tools.trim().is_empty() {
+ out.push_str(tools.trim_end());
+ out.push_str("\n\n");
+ }
+
+ let datetime = render_datetime(ctx)?;
+ if !datetime.trim().is_empty() {
+ out.push_str(datetime.trim_end());
+ out.push_str("\n\n");
+ }
+
+ let workspace = render_workspace(ctx)?;
+ if !workspace.trim().is_empty() {
+ out.push_str(workspace.trim_end());
+ out.push('\n');
+ }
+
+ Ok(out)
+}