Skip to content

feat(agent): reduce orchestrator prompt bloat#3367

Merged
senamakel merged 3 commits into
tinyhumansai:mainfrom
senamakel:issue/3332-reduce-agent-prompt-bloat-with-specialis
Jun 4, 2026
Merged

feat(agent): reduce orchestrator prompt bloat#3367
senamakel merged 3 commits into
tinyhumansai:mainfrom
senamakel:issue/3332-reduce-agent-prompt-bloat-with-specialis

Conversation

@senamakel
Copy link
Copy Markdown
Member

@senamakel senamakel commented Jun 4, 2026

Summary

  • Split prompt-heavy scheduling, presentation, and desktop-control behavior out of the orchestrator into narrow built-in specialist agents.
  • Exposed help, scheduler_agent, presentation_agent, and desktop_control_agent through the orchestrator subagent inventory.
  • Narrowed orchestrator direct tool visibility and updated routing/synthesis language around evidence-shaped delegation.
  • Added structured handoff fields to ArchetypeDelegationTool while preserving the existing freeform prompt contract.
  • Extended subagent result contracts so factual workers return answer, evidence, actions, uncertainties, failed calls, and next-step sections.

Problem

  • The front-line orchestrator prompt had accumulated domain-specific policy for scheduling, presentation generation, desktop actions, docs/help, citation behavior, and hallucination warnings.
  • Direct access to specialist-owned tools encouraged the parent agent to carry and apply those rules on every turn.
  • Freeform delegation inputs and freeform subagent outputs made it too easy to dump context into workers and synthesize unsupported claims afterward.

Solution

  • Added three built-in worker agents with dedicated prompts and narrow tool surfaces: scheduler_agent, presentation_agent, and desktop_control_agent.
  • Registered the existing help worker and new specialists in the orchestrator subagent list, loader builtins, and MCP prompt resource catalog.
  • Reduced the orchestrator prompt to routing, minimal handoff, evidence-aware synthesis, memory freshness, and concise response style.
  • Removed specialist-owned direct tools from the orchestrator and verified presentation generation now routes through make_presentation.
  • Added optional structured fields to archetype delegation: objective, evidence, constraints, must_not_assume, expected_output, and citation_requirement.
  • Added focused Rust tests for registry wiring, prompt routing, prompt-resource parity, structured delegation rendering/schema, and subagent result contracts.

Submission Checklist

If a section does not apply to this change, mark the item as N/A with a one-line reason. Do not delete items.

  • Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy
  • Diff coverage ≥ 80% — changed lines (Vitest + cargo-llvm-cov merged via diff-cover) meet the gate enforced by .github/workflows/pr-ci.yml. Local diff-cover was not run; focused Rust tests cover changed prompt/delegation wiring and CI will enforce the gate.
  • Coverage matrix updated — N/A: agent prompt/registry behavior change, no added/removed user-facing feature row.
  • All affected feature IDs from the matrix are listed in the PR description under ## Related — N/A: no matrix feature ID changed.
  • No new external network dependencies introduced (mock backend used per Testing Strategy)
  • Manual smoke checklist updated if this touches release-cut surfaces (docs/RELEASE-MANUAL-SMOKE.md) — N/A: no release-cut smoke surface changed.
  • Linked issue closed via Closes #NNN in the ## Related section

Impact

  • Runtime/platform impact: Rust core agent registry and prompt orchestration only; no frontend, Tauri shell behavior, migration, or RPC surface changes.
  • Security/compatibility: narrows orchestrator tool exposure and keeps existing prompt delegation compatibility.
  • Performance: orchestrator prompt is smaller and should carry less domain policy on normal chat turns.

Related


AI Authored PR Metadata (required for Codex/Linear PRs)

Keep this section for AI-authored PRs. For human-only PRs, mark each field N/A.

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: issue/3332-reduce-agent-prompt-bloat-with-specialis
  • Commit SHA: 4bb91a573f29cf5f0a321f9a3620e15732b890c9

Validation Run

  • pnpm --filter openhuman-app format:check — passed via pre-push hook.
  • pnpm typecheck — passed via pre-push hook (pnpm compile).
  • Focused tests:
    • cargo test --manifest-path Cargo.toml orchestrator -- --nocapture
    • cargo test --manifest-path Cargo.toml subagent_role_contract -- --nocapture
    • cargo test --manifest-path Cargo.toml archetype_delegation -- --nocapture
    • cargo test --manifest-path Cargo.toml specialist_agents_are_registered_with_narrow_tools -- --nocapture
    • cargo test --manifest-path Cargo.toml presentation_agent_lists_generate_presentation_and_grounding_tools -- --nocapture
    • cargo test --manifest-path Cargo.toml openhuman::mcp_server::resources::tests -- --nocapture
    • cargo test --manifest-path Cargo.toml openhuman::memory_tree::tree::rpc::tests::pipeline_status_reports_chunk_aggregates_after_ingest -- --nocapture
  • Rust fmt/check (if changed): cargo fmt --manifest-path Cargo.toml; cargo check --manifest-path Cargo.toml; cargo test --manifest-path Cargo.toml ran, but full suite has one pre-existing/order-dependent failure listed below.
  • Tauri fmt/check (if changed): cargo check --manifest-path app/src-tauri/Cargo.toml; also passed via pre-push hook pnpm rust:check.

Validation Blocked

  • command: cargo test --manifest-path Cargo.toml
  • error: full suite fails only openhuman::memory_tree::tree::rpc::tests::pipeline_status_reports_chunk_aggregates_after_ingest with degraded status should explain semantic recall loss: Some("wiki structure incomplete"); the same test passed in isolation after the full-suite failure.
  • impact: unrelated to this branch's agent registry/prompt/delegation changes; focused tests for the touched surfaces pass.

Behavior Changes

  • Intended behavior change: front-line orchestrator delegates scheduling, presentation generation, desktop-control, and product-help questions to specialist workers instead of carrying detailed domain policy and tools directly.
  • User-visible effect: agent routing should be more evidence-oriented and less likely to answer specialist/current-state questions from priors.

Parity Contract

  • Legacy behavior preserved: existing delegate prompt input remains required and compatible; specialist-owned behavior remains available through delegate tools.
  • Guard/fallback/dispatch parity checks: tests verify built-in registration, MCP prompt catalog parity, narrowed presentation tool visibility, structured handoff rendering, and evidence-shaped subagent result contracts.

Duplicate / Superseded PR Handling

  • Duplicate PR(s): N/A
  • Canonical PR: this PR
  • Resolution (closed/superseded/updated): N/A

Summary by CodeRabbit

  • New Features

    • Added three specialist agents: Desktop Control, Presentation, and Scheduler.
    • Structured delegation parameters for sub-agent handoffs (objective, evidence, constraints, must_not_assume, expected_output, citation requirement) and optional per-delegation model override.
  • Improvements

    • Orchestrator delegation refined to route to specialists and favor direct-first handling.
    • Sub-agent result contract and system prompts updated to require compact, evidence-backed result sections and explicit handling for truncated/partial tool output.

@senamakel senamakel requested a review from a team June 4, 2026 12:54
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 91bcdf91-bfcd-4f1d-b142-979c95d913db

📥 Commits

Reviewing files that changed from the base of the PR and between 4bb91a5 and f607621.

📒 Files selected for processing (3)
  • src/openhuman/agent_registry/agents/desktop_control_agent/agent.toml
  • src/openhuman/agent_registry/agents/desktop_control_agent/prompt.md
  • src/openhuman/agent_registry/agents/loader.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openhuman/agent_registry/agents/loader.rs

📝 Walkthrough

Walkthrough

Adds three specialist agents (scheduler, presentation, desktop control), expands ArchetypeDelegationTool to accept structured handoff fields and render compact child prompts, injects a shared Sub-agent Result Contract into subagent role contracts, updates orchestrator routing and tests, and exposes prompts as MCP resources.

Changes

Specialist agent delegation and orchestrator refactor

Layer / File(s) Summary
Sub-agent result contract foundation
src/openhuman/agent/harness/subagent_runner/ops.rs, src/openhuman/agent/harness/subagent_runner/ops_tests.rs
The injected role contract now includes a “Sub-agent Result Contract” block with required headings (Answer, Evidence used, Actions taken, Open uncertainties, Failed tool calls, Recommended next step) and constraints on Answer (only supported facts; handle truncated/partial/oversized tool outputs). Tests assert presence of these strings.
Structured delegation capability
src/openhuman/agent_orchestration/tools/archetype_delegation.rs
ArchetypeDelegationTool parameters_schema expanded to accept optional structured fields (objective, evidence, constraints, must_not_assume, expected_output, citation_requirement) plus optional model. Adds render_structured_handoff and helpers; execute renders structured handoff and dispatches subagent. Tests validate schema and rendering.
Specialist agents and prompt builders
src/openhuman/agent_registry/agents/scheduler_agent/*, presentation_agent/*, desktop_control_agent/*, src/openhuman/agent_registry/agents/mod.rs, src/openhuman/agent_registry/agents/loader.rs
Introduces three specialist agents with agent.toml, prompt.md, prompt.rs builder, and mod.rs exports. Registers them in BUILTINS and adds tests ensuring ToolScope::Named with required named tools and expected prompt contract substrings.
Orchestrator routing and evidence-aware synthesis
src/openhuman/agent_registry/agents/orchestrator/agent.toml, src/openhuman/agent_registry/agents/orchestrator/prompt.md, src/openhuman/agent_registry/agents/orchestrator/prompt.rs
Orchestrator now lists new subagents and removes specialist-owned direct tools (e.g., generate_presentation, run_skill, certain UI/tools). Prompt decision tree updated with structured handoff guidance and an “Evidence-aware synthesis” section requiring evidence-backed claims and handling truncated/partial tool outputs. Tests updated to assert routing and contract inclusion.
Agent registry wiring and MCP resources
src/openhuman/agent_registry/agents/loader.rs, src/openhuman/agent_registry/agents/mod.rs, src/openhuman/mcp_server/resources.rs, tests/orchestrator_presentation_wiring.rs
Registers specialist agents with agent.toml includes and prompt builders, exposes modules publicly, and adds three openhuman://prompts/agents/* PromptResource entries. Wiring tests check orchestrator/presentation wiring invariants (orchestrator exposes presentation_agent, presentation_agent lists generate_presentation and grounding tools).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • tinyhumansai/openhuman#2745: Extends the MCP prompt resource catalog with new subagent prompt URIs, related to the added PromptResource entries in resources.rs.
  • tinyhumansai/openhuman#3214: Overlaps on repo/task routing and "don't stall after reading" guidance that this PR tightens in orchestrator routing.
  • tinyhumansai/openhuman#3016: Related to presentation tooling placement; this PR moves generate_presentation out of orchestrator and into a dedicated presentation agent, which interacts with the concerns in that PR.

Suggested reviewers

  • graycyrus

🐰 I stitched the prompts and built the crate,
Three tiny agents, ready and straight,
Orchestrator delegates, contracts hold tight,
Evidence-first answers shine in the light,
Handoff neat—now onward, iterate!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.69% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat(agent): reduce orchestrator prompt bloat' directly summarizes the main change: orchestrator prompt reduction by extracting domain-specific logic into specialist agents.
Linked Issues check ✅ Passed The PR substantially implements issue #3332 requirements: creates specialist agents (scheduler_agent, presentation_agent, desktop_control_agent), narrows orchestrator tools, extends ArchetypeDelegationTool with structured fields, adds result contracts, and includes comprehensive tests.
Out of Scope Changes check ✅ Passed All changes align with issue #3332 scope: specialist agent creation, orchestrator refactoring, ArchetypeDelegationTool extension, result contract updates, and test coverage. No unrelated changes detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot added feature Net-new user-facing capability or product behavior. rust-core Core Rust runtime in src/: CLI, core_server, shared infrastructure. agent Built-in agents, prompts, orchestration, and agent runtime in src/openhuman/agent/. labels Jun 4, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/openhuman/agent_orchestration/tools/archetype_delegation.rs (1)

77-106: ⚡ Quick win

Add debug-level delegation-path logs with stable fields.

Please add tracing::debug! at structured handoff build/dispatch points (e.g., tool_name, agent_id, presence/count of structured fields, model_override presence) so delegation decisions are grep-friendly during incident/debug flows.

As per coding guidelines: “Add substantial debug-level logs while implementing features or fixes in Rust using log / tracing crate with stable prefixes and correlation fields (request IDs, method names, entity IDs) for grep-friendly tracing”.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openhuman/agent_orchestration/tools/archetype_delegation.rs` around lines
77 - 106, Add structured debug logging around the handoff build and dispatch in
archetype_delegation.rs: after computing raw_prompt/prompt (from
render_structured_handoff) and before calling super::dispatch_subagent, emit a
tracing::debug! with stable fields: tool_name (self.tool_name), agent_id
(self.agent_id), structured_fields_count (e.g., args.len() or count of
structured entries), prompt_empty (bool) or prompt_length, and
model_override_present (bool) / model_override value if present; ensure the logs
use stable keys (e.g., "tool_name", "agent_id", "fields_count",
"model_override") so grep-friendly and correlate with dispatch_subagent
invocation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/openhuman/agent_registry/agents/desktop_control_agent/prompt.rs`:
- Around line 10-34: Add tracing/debug instrumentation to the prompt assembly in
build: emit a stable-prefix entry log when entering build (include
ctx.agent_id), call and instrument each render helper (render_user_files,
render_tools, render_workspace) with trace logs showing start, end,
success/error and the trimmed length or empty/skipped decision, and log branch
decisions (e.g., "INCLUDE_SECTION" vs "SKIP_SECTION") with a section name field
and agent_id; also emit an exit log with final output length or error. Use the
project's tracing/log crate conventions and stable grep-friendly prefixes (e.g.,
"PROMPT_BUILD:ENTRY", "PROMPT_BUILD:SECTION", "PROMPT_BUILD:EXIT") and attach
correlation fields like agent_id and section names to each event.

In `@src/openhuman/agent_registry/agents/presentation_agent/prompt.rs`:
- Around line 10-34: Add debug/trace-level logs to the build function to record
entry/exit and branch decisions: at function entry log a stable prefix and the
agent id from PromptContext (e.g., "prompt.build"), then after each call to
render_user_files, render_tools, and render_workspace log whether the section
was appended and its trimmed length (use section.trim().is_empty() and
section.trim_end().len()), and before returning Ok(out) log exit with final
prompt length and which sections were included; use the project's tracing/log
crate at debug or trace level and reference symbols build, PromptContext,
ARCHETYPE, render_user_files, render_tools, and render_workspace in the log
messages.

In `@tests/orchestrator_presentation_wiring.rs`:
- Around line 59-60: Replace the weak substring check
PRESENTATION_AGENT_TOML.contains("delegate_name = \"make_presentation\"") with
the same trimmed-line equality helper used elsewhere in these tests to assert an
exact line match for the delegate_name entry; locate the helper used in this
test file (the trimmed-line equality/assertion function) and call it to compare
a trimmed line exactly to 'delegate_name = "make_presentation"' so incidental
matches are prevented.

---

Nitpick comments:
In `@src/openhuman/agent_orchestration/tools/archetype_delegation.rs`:
- Around line 77-106: Add structured debug logging around the handoff build and
dispatch in archetype_delegation.rs: after computing raw_prompt/prompt (from
render_structured_handoff) and before calling super::dispatch_subagent, emit a
tracing::debug! with stable fields: tool_name (self.tool_name), agent_id
(self.agent_id), structured_fields_count (e.g., args.len() or count of
structured entries), prompt_empty (bool) or prompt_length, and
model_override_present (bool) / model_override value if present; ensure the logs
use stable keys (e.g., "tool_name", "agent_id", "fields_count",
"model_override") so grep-friendly and correlate with dispatch_subagent
invocation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ffdd1afe-7752-4067-9096-2a5df6bfaa92

📥 Commits

Reviewing files that changed from the base of the PR and between 7c08704 and 4bb91a5.

📒 Files selected for processing (22)
  • src/openhuman/agent/harness/subagent_runner/ops.rs
  • src/openhuman/agent/harness/subagent_runner/ops_tests.rs
  • src/openhuman/agent_orchestration/tools/archetype_delegation.rs
  • src/openhuman/agent_registry/agents/desktop_control_agent/agent.toml
  • src/openhuman/agent_registry/agents/desktop_control_agent/mod.rs
  • src/openhuman/agent_registry/agents/desktop_control_agent/prompt.md
  • src/openhuman/agent_registry/agents/desktop_control_agent/prompt.rs
  • src/openhuman/agent_registry/agents/loader.rs
  • src/openhuman/agent_registry/agents/mod.rs
  • src/openhuman/agent_registry/agents/orchestrator/agent.toml
  • src/openhuman/agent_registry/agents/orchestrator/prompt.md
  • src/openhuman/agent_registry/agents/orchestrator/prompt.rs
  • src/openhuman/agent_registry/agents/presentation_agent/agent.toml
  • src/openhuman/agent_registry/agents/presentation_agent/mod.rs
  • src/openhuman/agent_registry/agents/presentation_agent/prompt.md
  • src/openhuman/agent_registry/agents/presentation_agent/prompt.rs
  • src/openhuman/agent_registry/agents/scheduler_agent/agent.toml
  • src/openhuman/agent_registry/agents/scheduler_agent/mod.rs
  • src/openhuman/agent_registry/agents/scheduler_agent/prompt.md
  • src/openhuman/agent_registry/agents/scheduler_agent/prompt.rs
  • src/openhuman/mcp_server/resources.rs
  • tests/orchestrator_presentation_wiring.rs

Comment on lines +10 to +34
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)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add required debug/trace instrumentation in prompt assembly flow.

build performs multiple rendering calls and branch decisions, but currently emits no diagnostic logs. Please add stable-prefix debug/trace logs for function entry/exit, per-section render outcome, and included/skipped branches (with correlation fields like agent_id and section names).

Proposed patch
 use anyhow::Result;
+use tracing::{debug, trace};

 const ARCHETYPE: &str = include_str!("prompt.md");

 pub fn build(ctx: &PromptContext<'_>) -> Result<String> {
+    debug!(
+        agent_id = %ctx.agent_id,
+        "[desktop_control_agent::prompt] build start"
+    );
     let mut out = String::with_capacity(4096);
     out.push_str(ARCHETYPE.trim_end());
     out.push_str("\n\n");

+    trace!(agent_id = %ctx.agent_id, section = "user_files", "[desktop_control_agent::prompt] rendering section");
     let user_files = render_user_files(ctx)?;
     if !user_files.trim().is_empty() {
+        debug!(agent_id = %ctx.agent_id, section = "user_files", "[desktop_control_agent::prompt] section included");
         out.push_str(user_files.trim_end());
         out.push_str("\n\n");
+    } else {
+        trace!(agent_id = %ctx.agent_id, section = "user_files", "[desktop_control_agent::prompt] section skipped_empty");
     }

+    trace!(agent_id = %ctx.agent_id, section = "tools", "[desktop_control_agent::prompt] rendering section");
     let tools = render_tools(ctx)?;
     if !tools.trim().is_empty() {
+        debug!(agent_id = %ctx.agent_id, section = "tools", "[desktop_control_agent::prompt] section included");
         out.push_str(tools.trim_end());
         out.push_str("\n\n");
+    } else {
+        trace!(agent_id = %ctx.agent_id, section = "tools", "[desktop_control_agent::prompt] section skipped_empty");
     }

+    trace!(agent_id = %ctx.agent_id, section = "workspace", "[desktop_control_agent::prompt] rendering section");
     let workspace = render_workspace(ctx)?;
     if !workspace.trim().is_empty() {
+        debug!(agent_id = %ctx.agent_id, section = "workspace", "[desktop_control_agent::prompt] section included");
         out.push_str(workspace.trim_end());
         out.push('\n');
+    } else {
+        trace!(agent_id = %ctx.agent_id, section = "workspace", "[desktop_control_agent::prompt] section skipped_empty");
     }

+    debug!(
+        agent_id = %ctx.agent_id,
+        final_chars = out.chars().count(),
+        "[desktop_control_agent::prompt] build done"
+    );
     Ok(out)
 }

As per coding guidelines: “Log entry/exit, branches, external calls, retries/timeouts, state transitions, and errors with stable grep-friendly prefixes” and “Add substantial debug-level logs while implementing features or fixes in Rust using log / tracing crate.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openhuman/agent_registry/agents/desktop_control_agent/prompt.rs` around
lines 10 - 34, Add tracing/debug instrumentation to the prompt assembly in
build: emit a stable-prefix entry log when entering build (include
ctx.agent_id), call and instrument each render helper (render_user_files,
render_tools, render_workspace) with trace logs showing start, end,
success/error and the trimmed length or empty/skipped decision, and log branch
decisions (e.g., "INCLUDE_SECTION" vs "SKIP_SECTION") with a section name field
and agent_id; also emit an exit log with final output length or error. Use the
project's tracing/log crate conventions and stable grep-friendly prefixes (e.g.,
"PROMPT_BUILD:ENTRY", "PROMPT_BUILD:SECTION", "PROMPT_BUILD:EXIT") and attach
correlation fields like agent_id and section names to each event.

Comment on lines +10 to +34
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)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add debug-level tracing to the prompt assembly path.

build now owns branching prompt composition, but it emits no debug/trace logs for entry/section inclusion/exit. Please add stable-prefixed tracing with key correlation fields (e.g., agent_id, section lengths, and which sections were appended) so routing/prompt-shape regressions are diagnosable.

Proposed diff
 use crate::openhuman::context::prompt::{
     render_tools, render_user_files, render_workspace, PromptContext,
 };
 use anyhow::Result;
@@
 pub fn build(ctx: &PromptContext<'_>) -> Result<String> {
+    tracing::debug!(
+        target: "agent_prompt",
+        agent_id = %ctx.agent_id,
+        model_name = %ctx.model_name,
+        "[presentation_agent_prompt] building system prompt"
+    );
     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() {
+        tracing::debug!(
+            target: "agent_prompt",
+            agent_id = %ctx.agent_id,
+            section = "user_files",
+            chars = user_files.len(),
+            "[presentation_agent_prompt] appending section"
+        );
         out.push_str(user_files.trim_end());
         out.push_str("\n\n");
     }
@@
     let tools = render_tools(ctx)?;
     if !tools.trim().is_empty() {
+        tracing::debug!(
+            target: "agent_prompt",
+            agent_id = %ctx.agent_id,
+            section = "tools",
+            chars = tools.len(),
+            "[presentation_agent_prompt] appending section"
+        );
         out.push_str(tools.trim_end());
         out.push_str("\n\n");
     }
@@
     let workspace = render_workspace(ctx)?;
     if !workspace.trim().is_empty() {
+        tracing::debug!(
+            target: "agent_prompt",
+            agent_id = %ctx.agent_id,
+            section = "workspace",
+            chars = workspace.len(),
+            "[presentation_agent_prompt] appending section"
+        );
         out.push_str(workspace.trim_end());
         out.push('\n');
     }
 
+    tracing::debug!(
+        target: "agent_prompt",
+        agent_id = %ctx.agent_id,
+        final_chars = out.len(),
+        "[presentation_agent_prompt] build complete"
+    );
     Ok(out)
 }
As per coding guidelines: “In Rust, use `log` / `tracing` at `debug` or `trace` level for development-oriented logs at entry/exit points, branch decisions, external calls, retries/timeouts, state transitions, and error handling paths.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openhuman/agent_registry/agents/presentation_agent/prompt.rs` around
lines 10 - 34, Add debug/trace-level logs to the build function to record
entry/exit and branch decisions: at function entry log a stable prefix and the
agent id from PromptContext (e.g., "prompt.build"), then after each call to
render_user_files, render_tools, and render_workspace log whether the section
was appended and its trimmed length (use section.trim().is_empty() and
section.trim_end().len()), and before returning Ok(out) log exit with final
prompt length and which sections were included; use the project's tracing/log
crate at debug or trace level and reference symbols build, PromptContext,
ARCHETYPE, render_user_files, render_tools, and render_workspace in the log
messages.

Comment on lines +59 to +60
PRESENTATION_AGENT_TOML.contains("delegate_name = \"make_presentation\""),
"presentation_agent must expose the make_presentation delegate tool"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Harden delegate_name assertion to exact-line matching.

PRESENTATION_AGENT_TOML.contains("delegate_name = \"make_presentation\"") is weaker than the exact-line checks used elsewhere and can pass on incidental text. Use a trimmed line-equality helper for this key too.

Suggested test hardening
 fn lists_named_tool(toml: &str, name: &str) -> bool {
     let bare = format!("\"{name}\"");
     let trailing = format!("\"{name}\",");
     toml.lines()
         .map(str::trim)
         .any(|line| line == bare || line == trailing)
 }
+
+fn has_delegate_name(toml: &str, delegate_name: &str) -> bool {
+    let expected = format!("delegate_name = \"{delegate_name}\"");
+    toml.lines().map(str::trim).any(|line| line == expected)
+}
@@
-    assert!(
-        PRESENTATION_AGENT_TOML.contains("delegate_name = \"make_presentation\""),
-        "presentation_agent must expose the make_presentation delegate tool"
-    );
+    assert!(
+        has_delegate_name(PRESENTATION_AGENT_TOML, "make_presentation"),
+        "presentation_agent must expose the make_presentation delegate tool"
+    );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
PRESENTATION_AGENT_TOML.contains("delegate_name = \"make_presentation\""),
"presentation_agent must expose the make_presentation delegate tool"
fn lists_named_tool(toml: &str, name: &str) -> bool {
let bare = format!("\"{name}\"");
let trailing = format!("\"{name}\",");
toml.lines()
.map(str::trim)
.any(|line| line == bare || line == trailing)
}
fn has_delegate_name(toml: &str, delegate_name: &str) -> bool {
let expected = format!("delegate_name = \"{delegate_name}\"");
toml.lines().map(str::trim).any(|line| line == expected)
}
// ... in test function:
assert!(
has_delegate_name(PRESENTATION_AGENT_TOML, "make_presentation"),
"presentation_agent must expose the make_presentation delegate tool"
);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/orchestrator_presentation_wiring.rs` around lines 59 - 60, Replace the
weak substring check PRESENTATION_AGENT_TOML.contains("delegate_name =
\"make_presentation\"") with the same trimmed-line equality helper used
elsewhere in these tests to assert an exact line match for the delegate_name
entry; locate the helper used in this test file (the trimmed-line
equality/assertion function) and call it to compare a trimmed line exactly to
'delegate_name = "make_presentation"' so incidental matches are prevented.

Copy link
Copy Markdown
Contributor

@M3gA-Mind M3gA-Mind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well-structured, well-tested refactor that meaningfully shrinks the orchestrator prompt and pins the new routing with good negative assertions (delegate-name parity, exact-line matching, narrow tool scopes all verified). Two substantive items to resolve before merge plus a couple of minor notes inline.

@@ -108,37 +121,12 @@ hint = "chat"
# / composio_execute directly.
named = [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orchestrator silently loses memory-write + skill-run with no replacement route. This block drops memory_store, save_preference, memory_forget, and run_skill, but the decision tree adds no delegation line for "remember this / save my preference / forget that / run a skill," and none of the three new specialists own those tools — the orchestrator keeps only query_memory (read) and memory_tree. So "remember that I prefer dark mode" now has no tool path on the front-line agent. The PR description only documents removing scheduling/presentation/desktop tools, so this looks undocumented. If it's intended (route to delegate_archivist / hand back to Core), please add the decision-tree line + a test; otherwise it's a capability regression.

@@ -175,42 +132,7 @@ User: what time is it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale ## Response Style examples now contradict the refactor. The examples just above this line still ship User: what time is it? → 7:31pm and User: remind me to stretch in 10 min → got it / reminder set for 7:42pm. With current_time and cron_* removed from the orchestrator, these model the agent answering the clock and confirming a reminder directly from priors — fabricating both the time value and the "reminder set" outcome — which is exactly what scheduler_agent and the new evidence-grounding contract exist to prevent. Please update them to show an ack + delegation to schedule_task, or the prompt will actively coach the wrong behavior.

}
}

fn render_structured_handoff(prompt: &str, args: &Value) -> String {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor / parity note: render_structured_handoff reshapes every archetype delegation, not just the new specialists. ArchetypeDelegationTool backs all delegates (crypto, integrations, etc.), so every child prompt is now wrapped in Task:\n… even when no structured fields are passed. It's additive and well-tested, but the "existing prompt delegation remains compatible" parity claim is a bit stronger than reality — the literal child-prompt string changes for all delegates. Worth a one-line note in the parity section, and consider skipping the Task:\n wrapper when no structured fields are present to keep the legacy path byte-identical.

@@ -1,14 +1,14 @@
# Orchestrator Staff Engineer
# Orchestrator - Staff Engineer
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this changes the H1 from an em-dash (Orchestrator — Staff Engineer) to a hyphen, which is unrelated churn for this PR. Arguably consistent with the prompt's own "avoid em dashes" guidance, but it's a heading (not model output), so either keep it intentional or revert to keep the diff focused on the refactor.

senamakel-droid
senamakel-droid previously approved these changes Jun 4, 2026
senamakel added 2 commits June 4, 2026 09:47
…gent-prompt-bloat-with-specialis

# Conflicts:
#	src/openhuman/agent_registry/agents/orchestrator/agent.toml
@senamakel senamakel merged commit 7af7283 into tinyhumansai:main Jun 4, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Built-in agents, prompts, orchestration, and agent runtime in src/openhuman/agent/. feature Net-new user-facing capability or product behavior. rust-core Core Rust runtime in src/: CLI, core_server, shared infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce agent prompt bloat with specialist subagents and grounding contracts

3 participants