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
feat(agent): add session import and progress tracing modules
Steven Enamakel6fc303c93ba0
diff --git a/crates/openhuman-core/src/agent/progress_tracing/README.md b/crates/openhuman-core/src/agent/progress_tracing/README.mdnew file mode 100644index 0000000000..c42ac7357a--- /dev/null+++ b/crates/openhuman-core/src/agent/progress_tracing/README.md@@ -0,0 +1,47 @@+# progress_tracing++Turns the agent's real-time [`AgentProgress`](../progress.rs) event stream into+OpenTelemetry/Langfuse-style trace spans (`agent.turn` -> `agent.iteration` ->+`tool.*`/`subagent.*`), correlated by session id, for offline inspection,+regression analysis, and debugging long multi-agent runs (issue #3886). See+the module doc on `agent/progress_tracing.rs` for the full span-tree shape and+the content-capture privacy gate+(`observability.agent_tracing.capture_content`, default off).++## Key files++- `agent/progress_tracing.rs` (parent file, `include!`s+ `progress_tracing_impl_01_part_0{1,2}.rs`) — `SpanCollector` (pure state+ machine: feed it progress events + a timestamp, it accumulates finished+ `TraceSpan`s), `TraceContext`, `SpanKind`/`SpanStatus`, NDJSON serialization+ (`spans_to_ndjson`), local file/log export (`export_spans`), and the two+ run-completion entry points `export_run_trace` /+ `export_run_trace_from_journal`.+- `langfuse.rs` (+ `langfuse_part_01.rs`, `langfuse_part_02.rs`) — Langfuse+ ingestion exporter. POSTs to the backend's `/telemetry/langfuse/ingestion`+ proxy (derived from `effective_backend_api_url`), authenticated with the+ session bearer; the backend injects the real Langfuse project keys and+ forwards to `/api/public/ingestion`. Carries `x-sdk-name` via+ `crate::api::product::product_identity_header` per AGENTS.md. Best-effort:+ failures are logged and swallowed so tracing never breaks a turn.+- `journal_projection.rs` — reconstructs spans from the durable+ `AgentObservation` journal instead of the live `AgentProgress` stream, by+ folding journalled events through the same `SpanCollector`, so a+ UI/supervisor can attach after a run completes. Exhaustive over+ `tinyagents_harness::events::AgentEvent`; documents known parity gaps+ (estimated vs. charged cost, missing subagent prompt/output content).++Test files (`*_tests.rs`, split into `_part_0N_tests.rs` files) are colocated+per source file and carry no additional public surface.++## Called by++- `web_chat/progress_bridge.rs` — the live in-run side-observer; feeds+ `AgentProgress` into `SpanCollector` and calls `export_run_trace[_from_journal]`+ at run completion.+- `flows/tinyflows/langfuse_export.rs` — the flows-runner counterpart, reusing+ `langfuse::push_spans`'s endpoint/auth derivation for flow runs.++## Related docs++- [gitbooks/developing/agent-observability.md](../../../../../gitbooks/developing/agent-observability.md)diff --git a/crates/openhuman-core/src/agent/prompts/README.md b/crates/openhuman-core/src/agent/prompts/README.mdnew file mode 100644index 0000000000..969a1c95f3--- /dev/null+++ b/crates/openhuman-core/src/agent/prompts/README.md@@ -0,0 +1,114 @@+# prompts++Owns the bundled prompt assets and the system-prompt rendering pipeline: the+types every section renders from, the section implementations themselves, the+builder that assembles them in order, and the free `render_*` helpers other+domains use to compose their own prompts.++## Public surface (from `mod.rs`)++- `types::*` — `PromptContext`, `PromptSection` trait, `PromptTier`,+ `PromptTool`, `ToolCallFormat`, `LearnedContextData`, `UserIdentity`,+ `ConnectedIntegration` and friends. Pure data; no rendering logic, so+ editing a type doesn't recompile the whole renderer.+- `render_connected_identities` (`connected_identities.rs`) — best-effort,+ sync render of the `## Connected Identities` block; reads through the bound+ memory driver via `block_in_place`, returns empty on any failure.+- `agents_md::{load_agents_md, load_agents_md_layers, AgentsMdContent, AGENTS_MD_FILENAME}`+ — loads `AGENTS.md` at the global (`workspace_dir`) and local+ (`action_dir`, or a sub-agent's `worktree_action_dir` override) layers.+- `builder::{SystemPromptBuilder, TieredPrompt, GLOBAL_STYLE_SUFFIX}` —+ assembles ordered `PromptSection`s into a final prompt string (or a+ `TieredPrompt` with cache-breakpoint offsets).+- `sections::*` — the concrete `PromptSection` structs (`IdentitySection`,+ `ToolsSection`, `SafetySection`, `UserFilesSection`, `UserMemorySection`,+ `WorkspaceSection`, `DateTimeSection`, `RuntimeSection`,+ `AgentsInstructionsSection`, `PersonalityRosterSection`,+ `ArchetypePromptSection`, `DynamicPromptSection`, …).+- `render_helpers::*` — free `render_*` functions (thin wrappers over the+ section structs) plus workspace-file injection helpers+ (`inject_workspace_file`, `inject_inline_content`, `sync_workspace_file`,+ `default_workspace_file_content`) and the sub-agent renderer+ (`render_subagent_system_prompt[_with_format]`). Lets a caller assemble a+ prompt by calling functions directly instead of going through+ `SystemPromptBuilder`.++## Bundled assets++`IDENTITY.md`, `ROLE.md`, `SOUL.md`, `STYLE.md`, `USER.md` are the seed copies+of the master agent's identity, role, personality, writing-style, and+user-adaptation files. They are pulled in via `include_str!` (`builder.rs`+for `STYLE.md`; `render_helpers_part_02.rs` for `SOUL.md`, `IDENTITY.md`,+`ROLE.md`) and used two ways:++- **Compile-time fallback constant** — e.g. `GLOBAL_STYLE_SUFFIX` — used when+ the workspace copy can't be read.+- **Seed content** — `sync_workspace_file` copies the bundled text into the+ user's workspace (`<workspace_dir>/SOUL.md`, etc.) the first time it's+ missing, so a fresh workspace still gets the rules; a user's on-disk edits+ win from then on. `USER_FILE_MAX_CHARS` and `BOOTSTRAP_MAX_CHARS` (in+ `types.rs`) cap how much of the on-disk copy gets injected.++Editing these files changes the shipped default agent's persona/style; they+are not code and do not need a doc comment, but changes here are product+changes — read `SOUL.md`/`STYLE.md` before touching them.++## Compat shim++`agent::context::prompt` (`agent/context/prompt.rs`) is `pub use+crate::agent::prompts::*` — prompt plumbing used to live there and was moved+here so it sits next to the agents that consume it. The shim is a stable+import path only; do not add logic to it. Both `crate::agent::prompts::*` and+`crate::agent::context::prompt::*` resolve to the same types.++## Extension points (owned elsewhere)++Other domains contribute additional `PromptSection`s that plug into a+`SystemPromptBuilder` built here, rather than living in this directory:++- `agent/learning/prompt_sections.rs` — `LearnedContextSection`,+ `UserProfileSection`, `MemoryAccessSection` (config-gated, appended by the+ session builder when learning is enabled).+- `agent/profiles/prompt_section.rs` — cross-profile workspace notice.+- `tools/agent_policy/prompt.rs` — tool-policy-boundary block.++Built-in archetype system prompts (orchestrator, welcome, integrations_agent,+…) live in `agent/registry/agents/<name>/prompt.rs` and `flows/agents/*/`, not+here — those modules hand-assemble their body via the `render_*` helpers and+feed it into `SystemPromptBuilder::from_dynamic` or `from_final_body`.++## Builder entry points++- `SystemPromptBuilder::with_defaults()` — the primary-agent chain (identity,+ user files, `AGENTS.md`, user memory, tools, safety, workspace, datetime,+ runtime).+- `SystemPromptBuilder::for_subagent(...)` — narrow chain driven by a sub-agent+ definition's `omit_*` flags; deliberately excludes `DateTimeSection` so+ repeat spawns of the same definition stay byte-identical for prefix-cache+ reuse.+- `SystemPromptBuilder::from_dynamic(...)` / `from_final_body(...)` — wrap an+ already-assembled body (the ~26 `agents/<id>/prompt.rs` builders) while+ still injecting the shared `AgentsInstructionsSection` and grounding/style+ suffix.++## KV-cache / prefix stability++The rendered prompt is frozen for the life of a session+(`agent/harness/session/mod.rs`) and reused on every turn so the inference+backend's prefix cache hits. `PromptSection::tier()` (`PromptTier::Stable` /+`Context` / `Volatile`) controls emission order in+`SystemPromptBuilder::build_tiered`: stable bytes (identity, role, safety,+style) first, then per-session-stable context (`AGENTS.md`, workspace), then+per-turn-volatile bytes (memory, profile, connected integrations, the clock)+last — because a prefix is reusable only up to the first differing byte, a+volatile section rendered early invalidates every stable byte behind it.+`NamespaceSummary.updated_at` is rendered as an absolute date rather than a+relative one for the same reason.++## Used by++- `agent/harness/session/turn/context.rs` — loads `AGENTS.md` layers and+ connected identities into `PromptContext` at session start.+- `agent/debug/` — dumps/measures the rendered prompt (`dump_writer.rs`,+ `prompt_size.rs`).+- `agent/context/prompt.rs` — compat re-export shim (see above).diff --git a/crates/openhuman-core/src/agent/session_import/mod.rs b/crates/openhuman-core/src/agent/session_import/mod.rsindex 94a693abca..c400d29666 100644--- a/crates/openhuman-core/src/agent/session_import/mod.rs+++ b/crates/openhuman-core/src/agent/session_import/mod.rs@@ -1,9 +1,9 @@//! One-time import of legacy OpenHuman sessions into TinyAgents stores.//!-//! Implements the P1 migration from `docs/tinyagents-session-migration-design.md`-//! (issue #4249): legacy transcript JSONL (`session_raw/`, flat and-//! `DDMMYYYY` date folders) and legacy Markdown sessions are normalized into-//! TinyAgents `Store`/`AppendStore` records under+//! Implements the P1 migration (issue #4249; see [`README.md`](README.md) for+//! source/destination layout): legacy transcript JSONL (`session_raw/`, flat+//! and `DDMMYYYY` date folders) and legacy Markdown sessions are normalized+//! into TinyAgents `Store`/`AppendStore` records under//! `{workspace}/tinyagents_store/`. Sources are never mutated; the command is//! idempotent (global marker + per-item fingerprint ledger) and exposed as//! `openhuman.session_import_run` (`openhuman-core session-import run`). Itdiff --git a/crates/openhuman-core/src/tools/registry/README.md b/crates/openhuman-core/src/tools/registry/README.mdindex 5b315a5417..00ec1bc8bd 100644--- a/crates/openhuman-core/src/tools/registry/README.md+++ b/crates/openhuman-core/src/tools/registry/README.md@@ -53,7 +53,7 @@ No owned persistence. `diagnostics()` reads (read-only) the `mcp_writes` table v- `crate::core::{ControllerSchema, FieldSchema, TypeSchema}` and `core::all::{ControllerFuture, RegisteredController}` — schema model and controller registration contract.- `crate::config` (`Config`, `config::schema::CapabilityProviderTrustState`) — autonomy posture, MCP client allowlists, capability-provider config.- `crate::mcp::server` (`McpToolSpec`, `tool_specs()`) — MCP stdio tool source for registry entries.-- `crate::mcp::registry::connections` (`all_connected_tools()`) — live MCP client server tools, fetched via `block_in_place` only on the multi-thread runtime.+- `crate::mcp::registry` (`all_connected_tools()`, defined in `mcp/registry/mod.rs`; a no-op stub in `mcp/registry/stub.rs` when the `mcp` feature is disabled) — live MCP client server tools, fetched via `block_in_place` only on the multi-thread runtime.- `tinymemory_core::store::chunks::store` — read-only `mcp_writes` audit query.- `crate::rpc::RpcOutcome` — RPC result envelope.diff --git a/gitbooks/developing/architecture/agent-harness.md b/gitbooks/developing/architecture/agent-harness.mdindex 11f6677f69..f1892dd194 100644--- a/gitbooks/developing/architecture/agent-harness.md+++ b/gitbooks/developing/architecture/agent-harness.md@@ -192,7 +192,7 @@ loop {Every iteration emits a real-time `AgentProgress` event so the UI can render token-by-token streaming, "calling tool X" status, and per-iteration cost updates.-**One engine, three entry points.** The loop lives in one place (the tinyagents `AgentHarness`, entered via `run_turn_via_tinyagents_shared` in `crates/openhuman-core/src/agent/tinyagents/mod.rs`) and every caller drives it: the chat turn (`harness/session/turn/core.rs` → `session/turn/graph.rs`), the channel/CLI bus turn (`harness/graph.rs`), and spawned sub-agents (`harness/subagent_runner/ops/graph.rs`). What varies per caller is supplied through the adapter seam: OpenHuman's provider wrapped as a `ChatModel` (`tinyagents/model.rs`), tools wrapped as tinyagents `Tool`s (`tinyagents/tools.rs`), an event bridge that projects harness `AgentEvent`s into `AgentProgress` + cost telemetry (`tinyagents/observability.rs`), `RunPolicy::unknown_tool` for hallucinated tool recovery, and a named middleware stack (`tinyagents/middleware.rs`) carrying the OpenHuman cross-cuts: approval/security gating (`ApprovalSecurityMiddleware`), tool policy and CLI/RPC-only denial (`ToolPolicyMiddleware`, `CliRpcOnlyMiddleware`), malformed-argument recovery (`ArgRecoveryMiddleware`), cost budget pre-checks (`CostBudgetMiddleware`), the repeated-tool-failure circuit breaker (`RepeatedToolFailureMiddleware`), and context trimming/compression. Policy stop hooks fire through `StopHookMiddleware` (`tinyagents/stop_hooks.rs`). The surviving OpenHuman-owned seams, `CheckpointStrategy` (error vs. summarize at the model-call cap) and `TurnProgress`, live in `harness/engine/`. Because all three entry points assemble the same harness, they can't drift.+**One engine, three entry points.** The loop lives in one place (the tinyagents `AgentHarness`, entered via `run_turn_via_tinyagents_shared` in `crates/openhuman-core/src/agent/tinyagents/mod.rs`) and every caller drives it: the chat turn (`harness/session/turn/core.rs` → `session/turn/graph.rs`), the channel/CLI bus turn (`harness/graph.rs`), and spawned sub-agents (`harness/subagent_runner/ops/graph.rs`). What varies per caller is supplied through the adapter seam: OpenHuman's provider wrapped as a `ChatModel` (`tinyagents/model.rs`), tools wrapped as tinyagents `Tool`s (`tinyagents/tools.rs`), an event bridge that projects harness `AgentEvent`s into `AgentProgress` + cost telemetry (`tinyagents/observability.rs`), `RunPolicy::unknown_tool` for hallucinated tool recovery, and a named middleware stack (`tinyagents/middleware.rs`) carrying the OpenHuman cross-cuts: approval/security gating (`ApprovalSecurityMiddleware`), tool policy and CLI/RPC-only denial (`ToolPolicyMiddleware`, `CliRpcOnlyMiddleware`), malformed-argument recovery (`ArgRecoveryMiddleware`), cost budget pre-checks (`CostBudgetMiddleware`), the repeated-tool-failure circuit breaker (`RepeatedToolFailureMiddleware`), and context trimming/compression. Policy stop hooks fire through `StopHookMiddleware` (`tinyagents/stop_hooks.rs`). The surviving OpenHuman-owned seam, `TurnProgress`, lives in `harness/session/tool_progress.rs`. Because all three entry points assemble the same harness, they can't drift.### Tool dispatch and tool-call dialects@@ -363,7 +363,7 @@ Each `AgentDefinition` carries an `agent_tier` field (`chat` / `reasoning` / `wo**Enforcement.** Two layers:-1. **Loader-time (static).** [`agents::loader::validate_tier_hierarchy`](../../../crates/openhuman-core/src/agent/agents/loader.rs) runs over the merged registry (built-ins + workspace TOMLs) and refuses to boot a registry that lists a same-tier or worker-with-subagents entry. Built-in archetypes are checked at compile-test time; user-shipped TOMLs are checked at workspace load.+1. **Loader-time (static).** [`agents::loader::validate_tier_hierarchy`](../../../crates/openhuman-core/src/agent/registry/agents/loader.rs) runs over the merged registry (built-ins + workspace TOMLs) and refuses to boot a registry that lists a same-tier or worker-with-subagents entry. Built-in archetypes are checked at compile-test time; user-shipped TOMLs are checked at workspace load.2. **Runtime depth gate (dynamic).** Independent of tier, the sub-agent runner caps total spawn chain depth at `MAX_SPAWN_DEPTH = 3` via a task-local counter incremented across `run_subagent`, surfaced as a `SpawnDepthExceeded` agent error. This makes a user-shipped TOML that drops the tier annotation still unable to recurse past three hops.> **Status:** the loader-time tier check, `agent_tier` field, and runtime depth-counter task-local are live. Depth is bounded by both the static loader contract and the runtime `MAX_SPAWN_DEPTH = 3` guard.