The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
docs(agent, cron): add README files for context and scheduler_gate modules
Steven Enamakele2eaf44f5180
diff --git a/crates/openhuman-core/src/agent/context/README.md b/crates/openhuman-core/src/agent/context/README.mdindex 4f64e57016..f09ddc0756 100644--- a/crates/openhuman-core/src/agent/context/README.md+++ b/crates/openhuman-core/src/agent/context/README.md@@ -1,8 +1,8 @@# context-Global context management for agent sessions: system-prompt assembly, per-session context bookkeeping (utilisation stats, budget configuration, session-memory triggers), 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.+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.-> **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 `run_turn_via_tinyagents_shared` (`agent/tinyagents/turn_runner.rs`), backed by `agent/tinyagents/summarize.rs::ModelSummarizer`. Tool-result body clearing runs in `tinyagents_harness::middleware::MicrocompactMiddleware`. `stats.rs` keeps the data model behind `ContextManager::stats()` and session-memory bookkeeping.+> **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 `run_turn_via_tinyagents_shared` (`agent/tinyagents/turn_runner.rs`), backed by `agent/tinyagents/summarize.rs::ModelSummarizer`. Tool-result body clearing runs in `tinyagents_harness::middleware::MicrocompactMiddleware`. `stats.rs` keeps the data model behind `ContextManager::stats()`.## Responsibilities@@ -10,29 +10,27 @@ Global context management for agent sessions: system-prompt assembly, per-sessio- 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` (`ToolOutputMiddleware`, `MicrocompactMiddleware`, `ContextCompressionMiddleware`) and in `agent/harness/tool_result_artifacts`.- Expose the microcompact placeholder/keep-recent constants consumed by the microcompact middleware.-- Track session-memory extraction thresholds (token growth, tool calls, turns) and report when a background archivist extraction should fire: without spawning it itself (`session_memory.rs`).## Key files| File | Role || --- | --- || `crates/openhuman-core/src/agent/context/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` | `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`, `microcompact_keep_recent`, `autocompact_enabled`, `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/agent/context/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`, `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). |+| `crates/openhuman-core/src/agent/context/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`, `microcompact_keep_recent`, `autocompact_enabled`, `prefer_markdown_tool_output`). |+| `crates/openhuman-core/src/agent/context/stats.rs` | `ContextStatsState`: last provider usage, context-window utilisation,. Pure state; issues no LLM calls and does not mutate history. |+| `crates/openhuman-core/src/agent/context/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`, with profile overrides for `SOUL.md`), tools, safety, skills, runtime, and channel-capabilities sections. |+| `crates/openhuman-core/src/agent/context/manager_tests.rs`, `channels_prompt_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/session-memory state lives in `stats.rs`.+- `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 archivist-recap-backed compaction wrapper is gone, the archivist still produces durable segment recaps on its own post-turn path.+- `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@@ -42,10 +40,9 @@ From `mod.rs` re-exports:- Manager: `ContextManager`, `ContextStats`.- Microcompact config: `CLEARED_PLACEHOLDER`, `DEFAULT_KEEP_RECENT_TOOL_RESULTS`.- Prompt: `SystemPromptBuilder`, `PromptSection`, `PromptContext`, `PromptTool`, `ArchetypePromptSection`, `DateTimeSection`, `IdentitySection`, `LearnedContextData`, `RuntimeSection`, `SafetySection`, `ToolsSection`, and `WorkspaceSection` are imported directly from `agent::prompts`.-- Session memory: `SessionMemoryConfig`, `SessionMemoryState`, `ARCHIVIST_EXTRACTION_PROMPT`, `DEFAULT_MIN_TOKEN_GROWTH`, `DEFAULT_MIN_TOOL_CALLS`, `DEFAULT_MIN_TURNS_BETWEEN`.- Tool-result budget: `DEFAULT_TOOL_RESULT_BUDGET_BYTES` config default only; live truncation is owned by `ToolOutputMiddleware` / `tool_result_artifacts`.-`ContextStatsState` and `SessionMemoryHandle` are `pub(crate)` and not re-exported.+`ContextStatsState` is `pub(crate)` and not re-exported.## RPC / controllers@@ -53,7 +50,7 @@ None. No `schemas.rs`, no `all_controller_schemas`, no `handle_*`. The `ContextS## Agent tools-None. No `tools.rs`. `ARCHIVIST_EXTRACTION_PROMPT` tells the spawned archivist to use the `update_memory_md` tool, which is owned elsewhere; this module only references it in prompt text.+None. No `tools.rs`.## Events@@ -63,10 +60,7 @@ None. No `bus.rs`; no `DomainEvent`s published or subscribed.No `store.rs`. State is per-session and in-memory:-- `ContextStatsState` holds last token counts, context window, and the shared `SessionMemoryHandle`.-- `SessionMemoryState` (behind the `Arc<Mutex<…>>` `SessionMemoryHandle`) tracks cumulative tokens / tool calls / turn counters and the extraction-in-progress flag; it resets naturally when a session ends.--The durable substrate session-memory targets is the workspace `MEMORY.md` file, written by the spawned archivist sub-agent (owned by the agent harness), not by this module.+- `ContextStatsState` holds last token counts and the context window.## Dependencies@@ -77,18 +71,16 @@ The durable substrate session-memory targets is the workspace `MEMORY.md` file,## Used by-- `agent::harness`: the primary consumer: `session/builder/builder_build.rs` constructs the `ContextManager`; `session/turn/core_turn.rs` drives the session-memory counters and spawns the archivist extraction when `should_extract_session_memory` says so; `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/` consume prompt types.+- `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/` consume prompt types.- `agent::tinyagents`: `harness_assembly.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`, `memory/agent/agent/prompt.rs`, `skills/*/agent/*/prompt.rs`: archetype prompt modules pull prompt sections/builder 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` (`ChannelSystemPrompt`, used by `channels/runtime/startup/start_channels.rs`) calls `channels_prompt::build_system_prompt_with_identity`; `channels/mod.rs` re-exports `build_system_prompt`; the `channels/tests/*` prompt/identity tests call it directly.-- `agent::triage`, `agent::debug`, `agent::orchestration::tools` (spawn_subagent and friends), `agent::learning::prompt_sections`, `memory::tool_memory::prompt`, `tools::orchestrator_tools`, `integrations::composio`: consume prompt types (`PromptContext`, `PromptSection`, `ToolCallFormat`, `ConnectedIntegration`, …) via `agent::prompts`.-- `config::schema`: `context.rs` embeds `SessionMemoryConfig`.+- `agent::triage`, `agent::debug`, `agent::orchestration::tools` (spawn_subagent and friends), `tools::orchestrator_tools`, `integrations::composio`: consume prompt types (`PromptContext`, `PromptSection`, `ToolCallFormat`, `ConnectedIntegration`, …) via `agent::prompts`.## Notes / gotchas- **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`), 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.-- Session memory is separate from compaction: it does not mutate in-flight history; it gates a *persistent* `MEMORY.md` extraction. All three thresholds (token growth, tool calls, turns) must be crossed and no extraction may be in flight. `mark_extraction_failed` keeps deltas so the next turn retries; `mark_extraction_complete` resets them. The handle is `Arc`-cloned so a detached background task can flip completion state after the synchronous borrow is released.- 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/`.diff --git a/crates/openhuman-core/src/cron/scheduler_gate/README.md b/crates/openhuman-core/src/cron/scheduler_gate/README.mdindex 1fdea4b34e..ac6a65e911 100644--- a/crates/openhuman-core/src/cron/scheduler_gate/README.md+++ b/crates/openhuman-core/src/cron/scheduler_gate/README.md@@ -58,7 +58,7 @@ No dependency on any other `openhuman` domain or on `crate::core::*`.Consumed in-process across the codebase (discoverable via `grep scheduler_gate`):-- Background workers / pipelines: `memory/sources/sync.rs`, `memory/context.rs`, `autocomplete/core/engine.rs`, `task_sources/route.rs`, `agent/triage/evaluator.rs`.+- Background workers / pipelines: `autocomplete/core/engine.rs`, `task_sources/route.rs`, `agent/triage/evaluator.rs`.- Inference layer: `inference/provider/openhuman_backend.rs`, `inference/provider/factory.rs`, `inference/local/service/{vision_embed.rs,public_infer.rs}`, `inference/voice/postprocess.rs`.- Credentials lifecycle (signed-out kill switch): `credentials/ops.rs`, `credentials/bus.rs`.- Bootstrap / transport: `core/runtime/subscribers.rs` (calls `init_global` during server bootstrap), `core/observability.rs`, plus the domain wiring in `openhuman/mod.rs` and config schema in `config/schema/scheduler_gate.rs`.