Skip to content

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

docs(agent): update context and registry docs after manager removal

Steven Enamakel79aaaabfff30
diff --git a/crates/openhuman-core/src/agent/README.md b/crates/openhuman-core/src/agent/README.md
index 51330b9e8a..7a570cd3d0 100644
--- a/crates/openhuman-core/src/agent/README.md
+++ b/crates/openhuman-core/src/agent/README.md
@@ -96,8 +96,8 @@ In order:
1. The caller builds a session host. `from_config_for_agent` resolves the
`AgentDefinition` for the agent id, picks its model and provider role,
- assembles the tool registry, and wires the `ContextManager`,
- `ToolPolicy`, run queue and progress sender. Web chat caches one host per
+ assembles the tool registry, and wires `ToolPolicy`, the run queue,
+ progress sender, and TinyAgents context middleware settings. Web chat caches one host per
thread ([`web_chat/session.rs`](../web_chat/session.rs)); cron builds one per job.
2. The caller scopes an `AgentTurnOrigin` ([`turn_origin.rs`](./turn_origin.rs)) and calls
`run_single_with_origin`. The origin (`WebChat`, `ExternalChannel`,
@@ -237,8 +237,8 @@ display-safe `AgentDefinitionDisplay` for the UI.
`prompts/` holds the bundled identity files (`SOUL.md`, `IDENTITY.md`,
`ROLE.md`, `STYLE.md`, `USER.md`) and `SystemPromptBuilder`, which selects
OpenHuman product content and delegates tier assembly to TinyAgents,
-optionally returning a `TieredPrompt` with cache breakpoints. `context/` keeps per-session
-`ContextManager` state and the byte-stable channel prompt builder. `debug/`
+optionally returning a `TieredPrompt` with cache breakpoints. `context/` holds
+the shared default for TinyAgents microcompact configuration. `debug/`
renders the exact prompt a live session would send, by building a real
session host and calling `build_system_prompt`.
@@ -306,7 +306,7 @@ Definitions, prompts and context:
| --- | --- |
| [`../agent_registry/`](../agent_registry/) | `agent_registry` RPC; built-in archetypes under [`agents/`](../agent_registry/agents/) ([README](../agent_registry/README.md)) |
| `prompts/` | Bundled identity files, `SystemPromptBuilder`, prompt sections ([README](prompts/README.md)) |
-| `context/` | `ContextManager` per session and the channel prompt builder ([README](context/README.md)) |
+| `context/` | Shared TinyAgents context defaults ([README](context/README.md)) |
| [`context_breakdown.rs`](./context_breakdown.rs) | `agent.context_breakdown`: system/tools/history split of prompt size for the UI |
| `debug/` | Dumps the exact system prompt and prompt-size report for an agent |
| [`../agent_registry/library/`](../agent_registry/library/) | Display-safe projection of definitions (`AgentDefinitionDisplay`) |
diff --git a/crates/openhuman-core/src/agent/context/README.md b/crates/openhuman-core/src/agent/context/README.md
index 2c6abb189b..2644661d86 100644
--- a/crates/openhuman-core/src/agent/context/README.md
+++ b/crates/openhuman-core/src/agent/context/README.md
@@ -1,93 +1,25 @@
-# context
+# Agent context defaults
-Global context management for agent sessions: system-prompt assembly, per-session context bookkeeping (utilisation stats, budget configuration), and the shared microcompact constants. Agents hold one `ContextManager` per session. This is a **pure logic / state-tracking domain**: no RPC controllers, no agent tools, no event-bus subscribers, no persisted store.
+This module exposes the host's default for how many recent tool results the
+TinyAgents microcompact middleware keeps. Prompt composition belongs to
+[`agent::prompts`](../prompts/README.md), configuration is mapped into turn
+middleware in [`agent::tinyagents`](../tinyagents/README.md), and the harness
+owns transcript reduction and middleware execution.
-> **Status (#4249): live history reduction/summarization moved out of this directory.** The in-turn compaction that used to live here (`ContextManager::reduce_before_call`, the `Summarizer` trait, `ProviderSummarizer`, `SegmentRecapSummarizer`, `microcompact.rs`, `pipeline.rs`, `guard.rs`) is gone: see [History](#history-4249). Folding an over-budget transcript into a summary now runs as the vendored `tinyagents_harness::middleware::ContextCompressionMiddleware` (with the seam-owned `ImageAwareMessageTrimMiddleware` as the deterministic backstop) inside `TurnSpec::run` ([`agent/tinyagents/turn_exec.rs`](../tinyagents/turn_exec.rs)), backed by `agent/tinyagents/summarize.rs::ModelSummarizer`. Tool-result body clearing runs in `tinyagents_harness::middleware::MicrocompactMiddleware`. [`stats.rs`](./stats.rs) keeps the data model behind `ContextManager::stats()`.
-
-## Responsibilities
-
-- Maintain prompt-adjacent session state; system-prompt assembly lives in `agent::prompts`, while [`channels_prompt.rs`](./channels_prompt.rs) provides the channel-specific builder.
-- Track context-window utilisation per session (`ContextStatsState`).
-- Expose the configured per-tool-result byte budget and the compaction/microcompact/autocompact toggles the tinyagents turn reads; enforcement lives in [`agent/tinyagents`](../tinyagents/) (`ToolOutputMiddleware`, `MicrocompactMiddleware`, `ContextCompressionMiddleware`) and in [`agent/harness/tool_result_artifacts`](../harness/tool_result_artifacts/).
-- Expose the microcompact placeholder/keep-recent constants consumed by the microcompact middleware.
-
-## Key files
+## Files
| File | Role |
| --- | --- |
-| [`crates/openhuman-core/src/agent/context/mod.rs`](./mod.rs) | Module docstring, `pub mod` decls, `pub use` re-exports, and the three shared constants (`DEFAULT_TOOL_RESULT_BUDGET_BYTES`, `CLEARED_PLACEHOLDER`, `DEFAULT_KEEP_RECENT_TOOL_RESULTS`). No other logic. |
-| [`crates/openhuman-core/src/agent/context/manager.rs`](./manager.rs) | `ContextManager`: per-session handle agents hold. Owns the default prompt builder, `ContextStatsState`, and the `ContextConfig`-derived knobs. Surfaces `build_system_prompt` / `build_system_prompt_tiered`, `stats()`, the getters the tinyagents turn reads (`tool_result_budget_bytes`, `compaction_enabled`, `autocompact_enabled`, `microcompact_keep_recent`, `autocompact_enabled`, `compaction()` (trigger override and strategy), `prefer_markdown_tool_output`), and the session-memory trigger/mark methods. |
-| `crates/openhuman-core/src/agent/context/stats.rs` | `ContextStatsState`: last provider usage, context-window utilisation, and the shared `SessionMemoryHandle` (`Arc<Mutex<SessionMemoryState>>`). Pure state; issues no LLM calls and does not mutate history. |
-| `crates/openhuman-core/src/agent/context/session_memory.rs` | `SessionMemoryState` / `SessionMemoryConfig`: threshold-gated `should_extract` decision (token growth, tool calls, and turns must all cross) and extraction bookkeeping. Holds `ARCHIVIST_EXTRACTION_PROMPT`. State-tracking only; does not spawn the archivist. |
-| `crates/openhuman-core/src/channels/prompt.rs` | Bespoke free functions `build_system_prompt(...)` / `build_system_prompt_with_identity(...)` (plus `PromptIdentityOverride`, `ProjectContextPlacement`, `render_project_context`) for channel runtimes (Discord/Slack/Telegram/…). Byte-stable for prefix-cache hits; injects workspace bootstrap files (`SOUL.md`, `IDENTITY.md`, optional `PROFILE.md`/`MEMORY.md`, with profile overrides for `SOUL.md`/`MEMORY.md`), tools, safety, skills, runtime, and channel-capabilities sections. |
-| [`crates/openhuman-core/src/agent/context/manager_tests.rs`](./manager_tests.rs), [`channels_prompt_tests.rs`](./channels_prompt_tests.rs), `session_memory_tests.rs` | Sibling test files wired via `#[cfg(test)] #[path = "..."] mod tests;` from their source file (the layout check rejects inline test modules). |
-
-## History (#4249)
-
-Live history reduction/summarization moved out of this directory into the tinyagents turn path:
-
-- `pipeline.rs`: removed; live context reduction moved to tinyagents middleware, stats state lives in `stats.rs`.
-- `guard.rs`: removed; the live 0.90 compression threshold is `SUMMARIZE_THRESHOLD_FRACTION` in `agent/tinyagents/summarize.rs`.
-- `microcompact.rs`: removed; live tool-result body clearing is owned by `tinyagents_harness::middleware::MicrocompactMiddleware`, only the shared constants remain in `mod.rs`.
-- `tool_result_budget.rs`: removed; UTF-8-safe per-result truncation moved next to action-workspace artifact preview/fallback handling in `agent/harness/tool_result_artifacts`.
-- `summarizer.rs`: removed; live summarization moved to `agent/tinyagents/summarize.rs` (`ModelSummarizer`, which also carries the summarizer system prompt).
-- `segment_recap_summarizer.rs`: removed; the recap-backed compaction wrapper is gone.
-- `summarizer_tests.rs` / `segment_recap_summarizer_tests.rs`: removed along with the files above.
-
-## Public surface
-
-From `mod.rs` re-exports:
-
-- Manager: `ContextManager`, `ContextStats`.
-- Microcompact config: `CLEARED_PLACEHOLDER`, `DEFAULT_KEEP_RECENT_TOOL_RESULTS`.
-- Prompt: `SystemPromptBuilder`, `PromptContext`, `PromptTool`, `ArchetypePromptSection`, `DateTimeSection`, `IdentitySection`, `LearnedContextData`, `RuntimeSection`, `SafetySection`, `ToolsSection`, and `WorkspaceSection` are imported directly from `agent::prompts`.
-- Tool-result budget: `DEFAULT_TOOL_RESULT_BUDGET_BYTES` config default only; live truncation is owned by `ToolOutputMiddleware` / `tool_result_artifacts`.
-
-`ContextStatsState` is `pub(crate)` and not re-exported.
-
-## RPC / controllers
-
-None. No `schemas.rs`, no `all_controller_schemas`, no `handle_*`. The `ContextStats` doc comment mentions an "optional `context.get_stats` RPC", but no such schema or handler exists anywhere in the crate.
-
-## Agent tools
-
-None. No `tools.rs`.
-
-## Events
-
-None. No `bus.rs`; no `DomainEvent`s published or subscribed.
-
-## Persistence
-
-No `store.rs`. State is per-session and in-memory:
-
-- `ContextStatsState` holds last token counts and the context window.
-
-## Dependencies
-
-- `crate::config`: `ContextConfig` ([`config/schema/context.rs`](../../config/schema/context.rs)): `enabled`, `microcompact_enabled` / `microcompact_keep_recent`, `autocompact_enabled`, `compaction_trigger_tokens` (absolute summarization trigger for benchmarks; env `OPENHUMAN_COMPACTION_TRIGGER_TOKENS`), `compaction_strategy` (env `OPENHUMAN_COMPACTION_STRATEGY`), `compaction_enabled`, `tool_result_budget_bytes`, `prefer_markdown_tool_output`, `summarizer_model`, and the embedded `session_memory: SessionMemoryConfig`.
-- `crate::inference::provider::UsageInfo`: fed into `record_usage`.
-- `crate::agent::prompts`: owns prompt rendering; `channels_prompt.rs` uses `inject_inline_content`.
-- `crate::skills::Workflow`: `channels_prompt.rs` renders the available-skills section from a `&[Workflow]`.
-
-## Used by
-
-- `agent::harness`: the primary consumer: `session/builder/builder_build.rs` constructs the `ContextManager`; `session/turn/core/harness_turn.rs` reads the budget/compaction getters into the tinyagents turn config; `session/turn/session_io/{transcript_persist,background_tasks}.rs` read `stats()`; `fork_context.rs` and [`../subagent_host/`](../subagent_host/) consume prompt types.
-- `agent::tinyagents`: `turn_middleware.rs` reads `CLEARED_PLACEHOLDER` when configuring `MicrocompactMiddleware`; `payload_summarizer.rs` and `host/context_composer.rs` build `PromptContext`s through `agent::prompts`.
-- **`agent_registry::agents/*/prompt.rs`**, `flows/agents/*/prompt.rs`, `skills/*/agent/*/prompt.rs`: archetype prompt modules pull prompt sections/builder through `agent::prompts`.
-- `channels`: [`channels/system_prompt.rs`](../../channels/system_prompt.rs) (`ChannelSystemPrompt`, used by [`channels/runtime/startup/start_channels.rs`](../../channels/runtime/startup/start_channels.rs)) calls `channels_prompt::build_system_prompt_with_identity`; [`channels/mod.rs`](../../channels/mod.rs) re-exports `build_system_prompt`; the `channels/tests/*` prompt/identity tests call it directly.
-- `triage`, `core::agent_cli::debug`, `agent::orchestration::tools` (spawn_subagent and friends), `tools::orchestrator_tools`, `integrations::composio`: consume prompt types (`PromptContext`, `ToolCallFormat`, `ConnectedIntegration`, …) via `agent::prompts`.
-
-## Notes / gotchas
+| [`mod.rs`](./mod.rs) | Module documentation and `DEFAULT_KEEP_RECENT_TOOL_RESULTS`. |
-- **The context stats state issues no LLM calls and does not mutate history.** Live reduction is owned by the tinyagents middleware stack.
-- **Tool-result budgeting is not a context pipeline stage.** The tinyagents path applies per-result budgets in `ToolOutputMiddleware` ([`agent/tinyagents/middleware/tool_output.rs`](../tinyagents/middleware/tool_output.rs)), and artifact-preview fallback truncation lives in `agent/harness/tool_result_artifacts`.
-- **`autocompact_enabled()` is `config.enabled && config.autocompact_enabled`**, and `microcompact_keep_recent()` is `0` when `microcompact_enabled` is off: the manager folds the config gates so the turn reads one value per knob.
-- Prompt rendering does not belong in this module; add it to `agent::prompts`.
-- **`channels_prompt::build_system_prompt` deliberately bypasses `SystemPromptBuilder`** to keep production channel prompt bytes stable for prefix-cache hits; it is a standalone free function despite living under `context/`.
+There is no per-session `ContextManager` here. The former manager, statistics,
+session-memory state, tool-result budget constant, and cleared-placeholder
+constant were removed as their responsibilities moved to the config schema,
+TinyAgents middleware, and `tinyagents-harness`.
-## Further reading
+## Consumers
-- [Parent module README](../README.md)
-- [Agent harness architecture](../../../../../docs/gitbooks/en/developing/architecture/agent-harness.md)
-- [Smart token compression](../../../../../docs/gitbooks/en/features/token-compression.md)
+The TinyAgents host maps configured context options into harness middleware.
+Channel and agent prompts use `agent::prompts`; live transcript compaction and
+tool-result clearing run in TinyAgents. This module owns no persistence,
+controllers, tools, or event subscribers.
diff --git a/crates/openhuman-core/src/agent/context/mod.rs b/crates/openhuman-core/src/agent/context/mod.rs
index dc7a1708f5..d5308358f4 100644
--- a/crates/openhuman-core/src/agent/context/mod.rs
+++ b/crates/openhuman-core/src/agent/context/mod.rs
@@ -1,18 +1,8 @@
-//! Global context management for agent sessions.
+//! Shared defaults for TinyAgents context middleware.
//!
-//! This module is the single home for everything that shapes what an LLM
-//! sees during a conversation:
-//!
-//! 1. **System prompt composition** — OpenHuman selects product content through
-//! [`prompt::SystemPromptBuilder`], while TinyAgents owns portable section
-//! and tier assembly. Main agents, sub-agents, and channels all build their
-//! opening system prompts through this module.
-//!
-//! 2. **Middleware configuration** — `ContextConfig` configures the TinyAgents
-//! turn middleware stack.
-//!
-//! Session hosts hold their prompt builder and context settings directly;
-//! TinyAgents owns live transcript reduction and middleware execution.
+//! Prompt construction lives in [`crate::agent::prompts`], context settings
+//! are mapped from [`crate::config::ContextConfig`] by the TinyAgents host,
+//! and the harness owns transcript reduction and middleware execution.
/// Default number of most-recent tool-result envelopes the TinyAgents
/// microcompact middleware leaves intact.
diff --git a/crates/openhuman-core/src/agent_registry/README.md b/crates/openhuman-core/src/agent_registry/README.md
index 3a13606634..c382f897cb 100644
--- a/crates/openhuman-core/src/agent_registry/README.md
+++ b/crates/openhuman-core/src/agent_registry/README.md
@@ -71,7 +71,7 @@ Every archetype uses the shared sub-agent turn graph.
`load_builtins`, which parses each `agent.toml`, installs
`PromptSource::Dynamic(prompt_fn)`, stamps
`DefinitionSource::Builtin`, checks that the folder id matches the TOML id,
-and then runs `validate_tier_hierarchy`: a `worker` may not list any agent-id
+and then runs `DefinitionSet::validate_tier_hierarchy`: a `worker` may not list any agent-id
subagent, and `chat -> chat` / `reasoning -> reasoning` delegation is
rejected (the pair rule is `validate_tier_transition` in the harness; unknown
subagent ids are tolerated here as a separate integrity concern).
@@ -82,7 +82,7 @@ other domains: `skill_setup`
Workspace-level overrides (`<workspace_dir>/agents/*.toml`, with a
`~/.openhuman/agents/` fallback) are loaded separately by
`tinyagents_definition::DefinitionSet::load_dirs` and replace built-ins on id collision;
-`AgentDefinitionRegistry::load` re-runs `validate_tier_hierarchy` after that
+`AgentDefinitionRegistry::load` re-runs the owner validation after that
merge.
The 12 archetypes in this directory:
diff --git a/crates/openhuman-core/src/agent_registry/agents/loader.rs b/crates/openhuman-core/src/agent_registry/agents/loader.rs
index 23a58de19e..eb3966d497 100644
--- a/crates/openhuman-core/src/agent_registry/agents/loader.rs
+++ b/crates/openhuman-core/src/agent_registry/agents/loader.rs
@@ -189,25 +189,9 @@ fn builtin_enabled(_b: &BuiltinAgent) -> bool {
true
}
-/// Validate the cross-agent spawn-hierarchy contract documented on
-/// [`AgentTier`].
-///
-/// Rules enforced here:
-///
-/// * `Chat` agents MUST NOT list another `Chat` agent in `subagents`.
-/// * `Reasoning` agents MUST NOT list another `Reasoning` agent in
-/// `subagents`.
-/// * `Worker` agents MUST NOT list any [`SubagentEntry::AgentId`]
-/// entries. (Skills wildcards are allowed: they expand to the connected
-/// integrations' actions as searchable tools on the agent's own belt,
-/// not to a spawn.)
-///
-/// Skills-wildcard entries (`{ skills = "*" }`) are intentionally
-/// untouched: they name no agent, so there is no tier pair to check.
-///
-/// Called from [`load_builtins`] for the bundled archetype set and from
-/// [`crate::agent_registry::host_definition::AgentDefinitionRegistry::load`]
-/// after workspace-local TOML overrides are merged, so custom user
+/// `load_builtins` parses and validates the bundled archetypes using the
+/// owning `tinyagents_definition::DefinitionSet`. Workspace definitions are
+/// validated by `AgentDefinitionRegistry::load` after overrides are merged.
/// agents that violate the contract fail the boot rather than crashing
/// at spawn time.
/// Parse a single [`BuiltinAgent`] triple into a finished [`AgentDefinition`].
diff --git a/crates/openhuman-core/src/agent_registry/agents/mod.rs b/crates/openhuman-core/src/agent_registry/agents/mod.rs
index 4ce69fdf12..6abb7c96a6 100644
--- a/crates/openhuman-core/src/agent_registry/agents/mod.rs
+++ b/crates/openhuman-core/src/agent_registry/agents/mod.rs
@@ -16,8 +16,8 @@
//! [`BUILTINS`] installs it as `PromptSource::Dynamic` on the parsed
//! definition. Most archetypes keep a `prompt_tests.rs` beside it.
//!
-//! `loader.rs` holds [`BUILTINS`], [`load_builtins`] and
-//! [`validate_tier_hierarchy`]. The slice also registers archetypes that
+//! `loader.rs` holds [`BUILTINS`] and [`load_builtins`]. It delegates tier
+//! validation to `tinyagents_definition::DefinitionSet`. The slice also registers archetypes that
//! live with other domains (`skills/*/agent/`,
//! `flows/agents/`), so this directory is not the full built-in set. The
//! package `README.md` one level up describes what each archetype does.