Skip to content

feat(prompts): load AGENTS.md project instructions into the system prompt - #5087

Merged
senamakel merged 11 commits into
tinyhumansai:mainfrom
senamakel:feat/agents-md
Jul 21, 2026
Merged

senamakel merged 11 commits into
tinyhumansai:mainfrom
senamakel:feat/agents-md

Conversation

@senamakel

@senamakel senamakel commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

Summary

  • OpenHuman now loads AGENTS.md instruction files and injects them into the agent system prompt, analogous to Claude Code's CLAUDE.md / Codex's AGENTS.md.
  • Two layers: a global <workspace_dir>/AGENTS.md (next to SOUL.md/USER.md) and a local <action_dir>/AGENTS.md from the folder the agent operates in; global renders first, local layered after.
  • Subagent runs honour their per-run working dir (worktree_action_dir override) for the local layer.
  • New agents_md_enabled config gate on AgentConfig (default on); each file capped at 20k chars with a truncation marker; loaded once per prompt build so the frozen system-prompt prefix / KV-cache contract is preserved.

Problem

  • There was no way to give the agent standing, folder-scoped instructions. Users coming from Claude Code / Codex expect a project-level instructions file that the agent picks up automatically when working in that folder, plus a global always-on layer.

Solution

  • New pure loader module src/openhuman/agent/prompts/agents_md.rs (load_agents_md / load_agents_md_layers): silent skip on missing/unreadable/empty, dedupe when global and local dirs canonicalize to the same path, [agents_md] debug logging.
  • New agents_md_global/agents_md_local fields on PromptContext (mirrors the existing personality_soul_md inline-content pattern), rendered by a new AgentsInstructionsSection (## Project instructions (AGENTS.md)) registered in both SystemPromptBuilder::with_defaults() and for_subagent(); a shared write_agents_md_blocks helper keeps the section and the narrow subagent renderer from drifting.
  • Load sites: main agent in session/turn/context.rs::build_system_prompt (global=workspace_dir, local=action_dir); subagent runner threads it through both the Dynamic (PromptContext) and Inline/File render paths, honouring worktree_action_dir.
  • Pre-loaded strings (not paths) keep prompt sections pure and testable, and pin the once-per-build read.

Submission Checklist

  • Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy — loader edge cases (missing/empty/unreadable/dedupe), section rendering + layering order, config gate off, builder registration, subagent paths
  • Diff coverage ≥ 80% — changed Rust lines covered by new unit tests (agent::prompts 66 passed, config::schema::agent 14 passed, subagent_runner 80 passed, about_app 30 passed)
  • N/A: Coverage matrix updated — no feature rows added/removed/renamed in docs/TEST-COVERAGE-MATRIX.md; prompt-assembly behaviour addition covered by unit tests
  • N/A: All affected feature IDs from the matrix are listed under ## Related — no matrix rows affected
  • No new external network dependencies introduced (pure local file reads; no network)
  • N/A: Manual smoke checklist — does not touch release-cut surfaces
  • N/A: Linked issue closed via Closes #NNN — no tracking issue; feature requested directly

Impact

  • Desktop/CLI runtime: system prompts can now include user-authored instructions from AGENTS.md; no behaviour change when the files are absent or agents_md_enabled = false.
  • Prompt size bounded (20k chars per layer, truncation marker). No new RPC surface, no schema/persistence changes beyond the config flag (serde-default, backward compatible).

Related

  • Closes:
  • Follow-up PR(s)/TODOs: optional UI surfacing of the flag in Settings → Agent access

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

Linear Issue

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

Commit & Branch

  • Branch: feat/agents-md
  • Commit SHA: 5f3fb64

Validation Run

  • N/A pnpm --filter openhuman-app format:check — no frontend changes; cargo fmt --check clean
  • N/A pnpm typecheck — no TypeScript changes
  • Focused tests: cargo test --lib agent::prompts (66 passed), config::schema::agent (14 passed), subagent_runner (80 passed), about_app (30 passed)
  • Rust fmt/check (if changed): GGML_NATIVE=OFF cargo check clean, cargo fmt --check clean
  • N/A Tauri fmt/check (if changed): app/src-tauri untouched

Validation Blocked

  • command: N/A
  • error: N/A
  • impact: N/A

Behavior Changes

  • Intended behavior change: system prompt gains a "Project instructions (AGENTS.md)" section sourced from workspace-global and action-dir-local AGENTS.md files
  • User-visible effect: agents follow instructions the user places in AGENTS.md files; nothing changes when no file exists

Parity Contract

  • Legacy behavior preserved: with no AGENTS.md files present (or gate off), prompt output is byte-identical to before
  • Guard/fallback/dispatch parity checks: section registered in both default and subagent builders; subagent Inline/File and Dynamic prompt paths both wired

Duplicate / Superseded PR Handling

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

Summary by CodeRabbit

  • New Features

    • Added support for loading workspace and project instructions from AGENTS.md files into agent prompts.
    • Project-level instructions take precedence and duplicate paths are handled safely.
    • Missing or unreadable files are skipped, and oversized content is capped.
    • Added a configuration option to disable this feature; it is enabled by default.
  • Documentation

    • Documented instruction loading, precedence, limits, and configuration behavior.

Loads configurable instruction text from AGENTS.md files at a global
(<workspace_dir>) and local/project (<action_dir>) layer, with dedupe
when both dirs resolve to the same path. Missing/unreadable/empty files
are silently skipped. Pure functions returning pre-loaded strings so the
prompt sections stay testable and the frozen-prefix contract holds.
Add agents_md_global/agents_md_local to PromptContext, a shared
write_agents_md_blocks helper, the AgentsInstructionsSection (rendered as
'## Project instructions (AGENTS.md)', global then local, each capped at
BOOTSTRAP_MAX_CHARS with a truncation marker), and register it after user
files and before the tool catalogue in both with_defaults() and
for_subagent(). All existing PromptContext literals updated to pass
None/None (feature off until wired at the load sites). Covered by section
+ builder-registration + truncation + ordering tests.
Default-on bool (serde default) that gates AGENTS.md loading/injection.
Off means no AGENTS.md content is loaded. Covered by default + serde
round-trip tests.
Main agent (session/turn/context.rs): load global (<workspace_dir>) +
local (<action_dir>) layers once at build_system_prompt, gated by
agents_md_enabled. Subagent runner: load global + project layers, where
the project layer is the worktree_action_dir override when set else the
config action_dir; thread through both the Dynamic (PromptContext) and
Inline/File (render_subagent_system_prompt_with_format) paths. The narrow
renderer gained agents_md params and emits the shared block after user
files, before the tool catalogue. Covered by subagent-renderer tests.
Add an intelligence.agents_md_instructions capability to the about_app
catalog and an AGENTS.md subsection to the agent-harness architecture doc
covering the global/project layers, dedupe, caps, and the config gate.
Prevent rare temp-dir collisions when the loader tests run in parallel
(same pid + nanosecond timestamp).
@senamakel
senamakel requested a review from a team July 21, 2026 12:22

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f3fb643d8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/openhuman/agent/harness/session/turn/context.rs
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 2 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2aa0217a-3aa6-480d-b744-c65fba174413

📥 Commits

Reviewing files that changed from the base of the PR and between 5f3fb64 and de06909.

📒 Files selected for processing (6)
  • gitbooks/developing/architecture/agent-harness.md
  • src/openhuman/about_app/catalog_data.rs
  • src/openhuman/agent/prompts/agents_md.rs
  • src/openhuman/agent/prompts/builder.rs
  • src/openhuman/agent/prompts/mod_tests.rs
  • src/openhuman/tinyagents/payload_summarizer.rs
📝 Walkthrough

Walkthrough

Adds configurable two-layer AGENTS.md loading for workspace and project instructions, injects the content into primary and sub-agent system prompts, adds truncation and deduplication handling, and updates configuration, capability metadata, documentation, and tests.

Changes

AGENTS.md instruction injection

Layer / File(s) Summary
Loading and configuration
src/openhuman/agent/prompts/agents_md.rs, src/openhuman/config/schema/agent.rs, src/openhuman/about_app/catalog_data.rs, gitbooks/developing/architecture/agent-harness.md
Loads trimmed, non-empty workspace and project AGENTS.md layers, deduplicates identical paths, supports a default-on configuration gate, and documents the capability.
Prompt rendering integration
src/openhuman/agent/prompts/types.rs, src/openhuman/agent/prompts/sections.rs, src/openhuman/agent/prompts/render_helpers.rs, src/openhuman/agent/prompts/builder.rs, src/openhuman/agent/prompts/mod.rs, src/openhuman/agent/prompts/mod_tests.rs
Adds AGENTS.md fields and rendering sections, places global content before local content after user files, caps injected content, and tests empty, ordering, truncation, and builder behavior.
Primary and sub-agent loading
src/openhuman/agent/harness/session/turn/context.rs, src/openhuman/agent/harness/subagent_runner/ops/runner.rs
Loads instruction layers during prompt construction when enabled, populates PromptContext, and passes content through the formatted sub-agent renderer.
PromptContext compatibility updates
src/openhuman/agent/debug/mod.rs, src/openhuman/agent/triage/evaluator.rs, src/openhuman/agent_registry/agents/*, src/openhuman/flows/agents/*, src/openhuman/learning/*, src/openhuman/memory_tools/*, src/openhuman/profiles/*, src/openhuman/tinyagents/*, src/openhuman/tinyplace/*
Updates existing context fixtures and construction sites to initialize the new optional fields.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Agent
  participant AGENTSLoader
  participant PromptContext
  participant PromptRenderer
  Agent->>AGENTSLoader: Load workspace and project AGENTS.md layers
  AGENTSLoader-->>Agent: Return deduplicated optional content
  Agent->>PromptContext: Store global and local instructions
  PromptContext->>PromptRenderer: Render instructions after user files
  PromptRenderer-->>Agent: Produce system prompt before tools
Loading

Suggested labels: feature, rust-core, agent

Suggested reviewers: sanil-23

Poem

A rabbit reads files by moonlit glow,
Global first, then local flow.
Trim the fluff and cap the size,
Place instructions where prompts arise.
“Hop approved!” the rabbit sings,
As tools arrive on orderly wings.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: loading AGENTS.md instructions into the system prompt.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

@coderabbitai coderabbitai Bot added 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. labels Jul 21, 2026

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 4

🤖 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/about_app/catalog_data.rs`:
- Around line 405-423: Update the AGENTS.md capability’s privacy classification
from LOCAL_RAW to the provider-dependent raw-egress classification used for
content included in configured cloud-model prompts. Keep the capability behavior
and description unchanged, and ensure the privacy surface reflects that raw
instructions may leave the device when remote providers are enabled.

In `@src/openhuman/agent/harness/session/turn/context.rs`:
- Around line 291-306: Update the shared load_agents_md loader to cap each
trimmed AGENTS.md layer at 20,000 characters and append the established
truncation marker when content exceeds the cap, before constructing
AgentsMdContent. Apply this root-cause fix for both
src/openhuman/agent/harness/session/turn/context.rs:291-306 and
src/openhuman/agent/harness/subagent_runner/ops/runner.rs:973-1003; keep both
callers unchanged so primary and sub-agent prompts use the bounded loader.

In `@src/openhuman/agent/prompts/agents_md.rs`:
- Around line 53-67: Bound AGENTS.md loading in load_agents_md to the documented
20,000-character limit before allocating the full file, preserving valid UTF-8
and existing empty-content handling. In src/openhuman/agent/prompts/agents_md.rs
lines 53-67, enforce the limit at read time; in
src/openhuman/agent/prompts/mod_tests.rs lines 2035-2050, add an oversized
AGENTS.md fixture and assert load_agents_md returns bounded content before
rendering.

In `@src/openhuman/tinyagents/payload_summarizer.rs`:
- Around line 334-335: Update the SubAgent construction in
build_tinyagents_system_prompt so agents_md_global and agents_md_local receive
the effective AGENTS.md instruction layers, including the worktree action
directory when available, allowing AgentsInstructionsSection to render them. If
this summarizer is intentionally excluded from sub-agent injection, document
that contract and add a regression test instead.
🪄 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: 7951a8d5-2d44-4f8a-b3b8-09b04e354d48

📥 Commits

Reviewing files that changed from the base of the PR and between 49a0d3b and 5f3fb64.

📒 Files selected for processing (50)
  • gitbooks/developing/architecture/agent-harness.md
  • src/openhuman/about_app/catalog_data.rs
  • src/openhuman/agent/debug/mod.rs
  • src/openhuman/agent/harness/session/turn/context.rs
  • src/openhuman/agent/harness/subagent_runner/ops/runner.rs
  • src/openhuman/agent/prompts/agents_md.rs
  • src/openhuman/agent/prompts/builder.rs
  • src/openhuman/agent/prompts/mod.rs
  • src/openhuman/agent/prompts/mod_tests.rs
  • src/openhuman/agent/prompts/render_helpers.rs
  • src/openhuman/agent/prompts/sections.rs
  • src/openhuman/agent/prompts/types.rs
  • src/openhuman/agent/triage/evaluator.rs
  • src/openhuman/agent_registry/agents/archivist/prompt.rs
  • src/openhuman/agent_registry/agents/code_executor/prompt.rs
  • src/openhuman/agent_registry/agents/context_scout/prompt.rs
  • src/openhuman/agent_registry/agents/critic/prompt.rs
  • src/openhuman/agent_registry/agents/crypto_agent/prompt.rs
  • src/openhuman/agent_registry/agents/desktop_control_agent/prompt.rs
  • src/openhuman/agent_registry/agents/goals_agent/prompt.rs
  • src/openhuman/agent_registry/agents/help/prompt.rs
  • src/openhuman/agent_registry/agents/image_agent/prompt.rs
  • src/openhuman/agent_registry/agents/integrations_agent/prompt.rs
  • src/openhuman/agent_registry/agents/loader.rs
  • src/openhuman/agent_registry/agents/markets_agent/prompt.rs
  • src/openhuman/agent_registry/agents/mcp_agent/prompt.rs
  • src/openhuman/agent_registry/agents/mcp_setup/prompt.rs
  • src/openhuman/agent_registry/agents/morning_briefing/prompt.rs
  • src/openhuman/agent_registry/agents/orchestrator/prompt.rs
  • src/openhuman/agent_registry/agents/planner/prompt.rs
  • src/openhuman/agent_registry/agents/presentation_agent/prompt.rs
  • src/openhuman/agent_registry/agents/researcher/prompt.rs
  • src/openhuman/agent_registry/agents/scheduler_agent/prompt.rs
  • src/openhuman/agent_registry/agents/skill_creator/prompt.rs
  • src/openhuman/agent_registry/agents/summarizer/prompt.rs
  • src/openhuman/agent_registry/agents/task_manager_agent/prompt.rs
  • src/openhuman/agent_registry/agents/tool_maker/prompt.rs
  • src/openhuman/agent_registry/agents/tools_agent/prompt.rs
  • src/openhuman/agent_registry/agents/trigger_reactor/prompt.rs
  • src/openhuman/agent_registry/agents/trigger_triage/prompt.rs
  • src/openhuman/agent_registry/agents/video_agent/prompt.rs
  • src/openhuman/agent_registry/agents/vision_agent/prompt.rs
  • src/openhuman/config/schema/agent.rs
  • src/openhuman/flows/agents/flow_discovery/prompt.rs
  • src/openhuman/flows/agents/workflow_builder/prompt.rs
  • src/openhuman/learning/prompt_sections.rs
  • src/openhuman/memory_tools/prompt.rs
  • src/openhuman/profiles/prompt_section.rs
  • src/openhuman/tinyagents/payload_summarizer.rs
  • src/openhuman/tinyplace/agent/prompt.rs

Comment thread src/openhuman/about_app/catalog_data.rs
Comment thread src/openhuman/agent/harness/session/turn/context.rs
Comment thread src/openhuman/agent/prompts/agents_md.rs Outdated
Comment thread src/openhuman/tinyagents/payload_summarizer.rs
Dynamic agents (PromptSource::Dynamic) assemble their own body via render_*
helpers and none call render_agents_md, so the pre-loaded AGENTS.md layers
were silently dropped for the primary/orchestrator (main chat) agent. Inject
AgentsInstructionsSection centrally in from_dynamic — mirroring how build()
appends the grounding contract — so every dynamic agent inherits the same
AGENTS.md injection as the with_defaults / for_subagent chains. Regression
test + doc update.
load_agents_md used read_to_string, slurping an arbitrarily large untrusted
project file whole before the renderer's char cap. Open + take() a byte bound
(BOOTSTRAP_MAX_CHARS*4 + slack) so a pathological multi-MB AGENTS.md can't
stall prompt construction or exhaust memory; render-time cap + truncation
marker still fire unchanged for well-formed files. Adds bounded-read test.
AGENTS.md raw content is injected into the system prompt sent to the configured
inference provider, so it leaves the device when a remote provider is active.
LOCAL_RAW (leaves_device: false) under-reported this; classify as raw egress to
the configured inference provider.
The internal payload summarizer intentionally omits AGENTS.md layers: it does
no project work and builds its prompt directly (outside from_dynamic), so it is
deliberately outside the injection contract. Document the contract in-code.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

PromptSource::Dynamic(build) => {
build(&prompt_ctx).map_err(|e| SubagentRunError::PromptLoad {

P2 Badge Render AGENTS.md for dynamic subagents

When a spawned child uses a built-in dynamic prompt, the new AGENTS.md layers are put on prompt_ctx but never rendered: built-ins are stamped as PromptSource::Dynamic in agent_registry/agents/loader.rs:435, and this branch calls build(&prompt_ctx) directly instead of going through SystemPromptBuilder::from_dynamic or render_subagent_system_prompt_with_format, the only paths that emit AgentsInstructionsSection. Fresh evidence in this revision is that lines 979-986 now load the subagent layers, but this dynamic branch still bypasses both renderers, so delegates like code_executor/researcher ignore project instructions while Inline/File subagents get them.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/openhuman/agent/prompts/agents_md.rs
Comment thread src/openhuman/agent/harness/session/turn/context.rs
@senamakel
senamakel merged commit c7f67b7 into tinyhumansai:main Jul 21, 2026
19 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 22, 2026
12 tasks done
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.

1 participant