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): add README files for orchestration and agent policy modules
Steven Enamakel443ca616a83c
diff --git a/crates/openhuman-core/src/agent/orchestration/README.md b/crates/openhuman-core/src/agent/orchestration/README.mdindex 737edad849..d5e981df67 100644--- a/crates/openhuman-core/src/agent/orchestration/README.md+++ b/crates/openhuman-core/src/agent/orchestration/README.md@@ -28,8 +28,8 @@ semantics, compatibility events, and JSON-RPC/tool response formatting.continue/follow-up control verbs (`command_center/`).- Git-worktree isolation so parallel coding workers never clobber the samecheckout (`worktree.rs`, `worktree_schemas.rs`).-- Cancellation of detached (`spawn_async_subagent`) background sub-agents from- the frontend "Cancel" affordance (`subagent_control.rs`).+- User-driven cancel/steer of detached (`spawn_async_subagent`) background+ sub-agents from the frontend background-tasks drawer (`subagent_control.rs`).- Mirroring detached sub-agent lifecycle into a TinyAgents task store, batchingfinished background results back into chat, and settling run-ledger rowsfrom the global bus regardless of the parent turn's lifecycle@@ -53,7 +53,13 @@ semantics, compatibility events, and JSON-RPC/tool response formatting.- `workflow_runs/` — declarative `WorkflowDefinition` phase graphs (issue#3375), the builtin "parallel research with cross-checking" workflow,structural/agent validation, and the live execution engine (`engine.rs`).-- `delegation.rs` — the durable plan→execute⇄review→finalize graph.+- `delegation.rs` — production worker for TinyAgents' durable+ plan→execute⇄review→finalize graph; every stage runs through `run_subagent`.+- `spawn_parallel_graph.rs` (+ `_part_0N.rs`) — the fanout behind+ `spawn_parallel_agents`: request/claim validation, worktree preflight, and the+ bounded `map_reduce` worker run; the tool file only translates `ToolResult`.+- `subagent_events.rs` — the single owner that constructs and publishes+ `DomainEvent::Subagent{Spawned,Completed,Failed,AwaitingUser}`.- `subagent_control.rs` — manual cancel/steer of detached backgroundsub-agents; the manual counterpart to the automatic thread-closecancellation in `crate::threads`.@@ -89,37 +95,51 @@ semantics, compatibility events, and JSON-RPC/tool response formatting.Five controller pairs are registered in `crate::core::all`:-| Namespace | Source |-| --- | --- |-| `agent_team` | `agent_teams::{all_agent_team_controller_schemas, all_agent_team_registered_controllers}` |-| `agent_work` | `command_center::{all_command_center_controller_schemas, all_command_center_registered_controllers}` |-| `workflow_run` | `workflow_runs::{all_workflow_run_controller_schemas, all_workflow_run_registered_controllers}` |-| `worktree` | `worktree_schemas::{all_controller_schemas, all_registered_controllers}` |-| `subagent` | `subagent_control::{all_controller_schemas, all_registered_controllers}` |+| Namespace | Source | Methods |+| --- | --- | --- |+| `agent_team` | `agent_teams::{all_agent_team_controller_schemas, all_agent_team_registered_controllers}` | `create`, `list`, `get`, `assign_task`, `claim_task`, `message_member`, `list_messages`, `complete_task`, `shutdown_member`, `close`, `start_member` |+| `agent_work` | `command_center::{all_command_center_controller_schemas, all_command_center_registered_controllers}` | `list`, `control` |+| `workflow_run` | `workflow_runs::{all_workflow_run_controller_schemas, all_workflow_run_registered_controllers}` | `list_definitions`, `list`, `get`, `start`, `stop`, `resume` |+| `worktree` | `worktree_schemas::{all_controller_schemas, all_registered_controllers}` | `list`, `status`, `diff`, `remove` |+| `subagent` | `subagent_control::{all_controller_schemas, all_registered_controllers}` | `cancel`, `steer` |## Agent tools`tools.rs` declares the `tools/` directory files (via `#[path]`) andre-exports them through `crate::tools` (`tools/mod.rs`:-`pub use crate::agent::orchestration::tools::*`): `agent_prepare_context`,-`archetype_delegation`, `awaiting_user`, `close_subagent`,-`collapsed_delegation`, `continue_subagent`, `delegate_graph`, `dispatch`,-`list_subagents`, `skill_delegation`, `spawn_async_subagent`,-`spawn_parallel_agents`, `spawn_subagent`, `spawn_worker_thread`,-`steer_subagent`, `wait`, `wait_subagent`, `worker_thread`. Execution itself-routes through `agent::harness::run_subagent`.+`pub use crate::agent::orchestration::tools::*`). LLM-callable tools, by wire+name:++- Spawn: `spawn_subagent`, `spawn_async_subagent`, `spawn_parallel_agents`,+ `spawn_worker_thread`.+- Control: `steer_subagent`, `continue_subagent`, `close_subagent`,+ `wait_subagent`, `wait`, `wait_loop`, `list_subagents`.+- Delegation: `DelegateGraphTool` (`delegate_graph.rs`),+ `ArchetypeDelegationTool` and `SkillDelegationTool` (names set per+ instance, e.g. `delegate_to_integrations_agent`), `CollapsedDelegationTool`+ (`delegate_to`), and `agent_prepare_context`.++`dispatch.rs` (`dispatch_subagent`, the shared spawn path every tool above+calls), `awaiting_user.rs` (the awaiting-user envelope), and+`worker_thread.rs` (worker thread creation) are `pub(crate)` helpers, not+tools. Execution itself routes through `agent::harness::run_subagent`.## Persistence-Durable state lives in `tinyagents_session::run_ledger` — the `agent_runs`,-`agent_teams`/`agent_team_members`/`agent_team_tasks`, and `workflow_runs`-tables, plus the shared run-event log for messages — backed by-`{workspace}/session_db/sessions.db` (see `agent/session_db/mod.rs`). Every-spawn path (`spawn_subagent`, `spawn_async_subagent`,-`spawn_parallel_agents`, `continue_subagent`, `dispatch`) writes a `running`-row; `run_ledger_finalize.rs` settles it from the global event bus so-detached runs that outlive their spawning turn are not left `running`-forever.+- `tinyagents_session::run_ledger` — the `agent_runs`,+ `agent_teams`/`agent_team_members`/`agent_team_tasks`, and `workflow_runs`+ tables plus the shared `run_events` log, backed by+ `{workspace}/session_db/sessions.db` (see `agent/session_db/mod.rs`). Every+ spawn path (`spawn_subagent`, `spawn_async_subagent`,+ `spawn_parallel_agents`, `continue_subagent`, `dispatch`) writes a `running`+ `agent_runs` row; `run_ledger_finalize.rs` settles it from the global event+ bus so detached runs that outlive their spawning turn are not left `running`+ forever.+- `subagent_sessions/` — `SubagentSessionStore` writes+ `{workspace}/.openhuman/subagent_sessions.json` (atomic tmp-file rename).+- `delegation.rs` — checkpoints `DelegationState` through+ `tinyagents_graph::SqliteCheckpointer` in `graph_checkpoints.db` under the+ workspace.## Policy inheritance@@ -146,8 +166,8 @@ what the harness exposes to the child.## Used by-- `agent::tools` re-exports every tool in `tools/` for the LLM tool-calling- loop.+- `crate::tools` (`tools/mod.rs`) re-exports every tool in `tools/` for the+ LLM tool-calling loop.- `threads` — the automatic thread-close cancellation counterpart to`subagent_control.rs`'s manual cancel.- `crate::core::all` — registers the five controller pairs above.diff --git a/crates/openhuman-core/src/tools/agent_policy/README.md b/crates/openhuman-core/src/tools/agent_policy/README.mdindex 47984aa4be..2f2bcd6d67 100644--- a/crates/openhuman-core/src/tools/agent_policy/README.md+++ b/crates/openhuman-core/src/tools/agent_policy/README.md@@ -1,13 +1,15 @@-# agent_tool_policy+# agent_policy-Profiles and enforces the tool boundary for a single agent session, keeping the prompt-visible tool set and runtime execution decisions aligned with the channel's configured permission ceiling. Given the active agent, channel, configured per-channel permission map, the available tool registry, and an optional set of explicitly-visible tool names, it produces a deterministic, immutable `ToolPolicySession` snapshot: per-tool decisions (allow / deny / hide), the allowed/blocked/hidden name sets, and a coarse task risk level. It also renders a compact system-prompt section describing the active boundary. This domain is pure logic — no persistence, no RPC, no events.+Profiles and enforces the tool boundary for a single agent session, keeping the prompt-visible tool set and runtime execution decisions aligned with the channel's configured permission ceiling. Given the active agent, channel, the `channel_permissions` map from `AgentConfig`, the session's tool set, and an optional set of explicitly-visible tool names, it produces a deterministic, immutable `ToolPolicySession` snapshot: per-tool decisions (allow / deny / hide), the allowed/blocked/hidden name sets, and a coarse task risk level. It also renders a compact system-prompt section describing the active boundary. Pure logic: no persistence, no RPC, no bus events.++Not to be confused with `crate::agent::tool_policy` (the generic `ToolPolicy` pre-execution hook trait). That module has its own `ToolPolicyDecision` type; the two are unrelated.## Responsibilities-- Resolve a channel's `PermissionLevel` ceiling from a `channel -> permission` string map (`permission_for_channel`), with fallbacks.-- Classify every tool in the registry against that ceiling and the optional visibility set, producing a `ToolPolicyAction` (Allow / RequireApproval / Deny / HideFromPrompt) per tool.-- Build an immutable `ToolPolicySession` snapshot (profile, capabilities, allowed/blocked/hidden tool-name sets, decision map) attached to an agent session.-- Derive a coarse `TaskRiskLevel` (Low/Medium/High/Critical) from the highest allowed permission.+- Resolve a channel's `PermissionLevel` ceiling from the `channel -> permission` string map (`permission_for_channel`), with fallbacks.+- Classify every tool against that ceiling and the optional visibility set, producing a `ToolPolicyAction` (Allow / RequireApproval / Deny / HideFromPrompt) per tool.+- Build an immutable `ToolPolicySession` snapshot (profile, capabilities, allowed/blocked/hidden tool-name sets, decision map).+- Derive a coarse `TaskRiskLevel` (Low/Medium/High/Critical) from the allowed permission.- Render a bounded `## Tool Policy Boundary` system-prompt section listing the active agent/channel/entrypoint, allowed permission, risk, allowed tools, and a restricted-count summary.- Provide a fail-closed default decision (`Deny`) for unknown or unlisted tool names at runtime.@@ -16,39 +18,50 @@ Profiles and enforces the tool boundary for a single agent session, keeping the| File | Role || --- | --- || `crates/openhuman-core/src/tools/agent_policy/mod.rs` | Export-only: module docstring + `mod` decls + `pub use` re-exports of the engine, prompt renderer, and types. |-| `crates/openhuman-core/src/tools/agent_policy/types.rs` | Serde-free domain types: `TaskRiskLevel`, `TaskProfile`, `ToolPolicyAction`, `ToolPolicyDecision`, `ToolCapability`, `ToolPolicySession` (with query helpers). Holds the `NO_TOOLS_ALLOWED_SENTINEL`. |-| `crates/openhuman-core/src/tools/agent_policy/engine.rs` | `ToolPolicyEngine::build_session` — the classification logic; private `permission_for_channel` / `parse_permission_level` helpers. Includes inline `#[cfg(test)]` suite. |-| `crates/openhuman-core/src/tools/agent_policy/prompt.rs` | `render_tool_policy_boundary` + `TOOL_POLICY_BOUNDARY_HEADING`; UTF-8-safe `truncate_utf8`. Includes inline `#[cfg(test)]` suite. |+| `crates/openhuman-core/src/tools/agent_policy/types.rs` | Serde-free domain types: `TaskRiskLevel`, `TaskProfile`, `ToolPolicyAction`, `ToolPolicyDecision`, `ToolCapability`, `ToolPolicySession` (with query helpers). Holds the private `NO_TOOLS_ALLOWED_SENTINEL`. |+| `crates/openhuman-core/src/tools/agent_policy/engine.rs` | `ToolPolicyEngine::build_session` / `build_session_from_refs` — the classification logic; private `permission_for_channel` / `parse_permission_level` helpers. |+| `crates/openhuman-core/src/tools/agent_policy/engine_tests.rs` | Engine tests, attached via `#[path]` from `engine.rs`. |+| `crates/openhuman-core/src/tools/agent_policy/prompt.rs` | `render_tool_policy_boundary` + `TOOL_POLICY_BOUNDARY_HEADING`; private UTF-8-safe `truncate_utf8`. |+| `crates/openhuman-core/src/tools/agent_policy/prompt_tests.rs` | Prompt-rendering tests, attached via `#[path]` from `prompt.rs`. |## Public surfaceRe-exported from `mod.rs`:-- `ToolPolicyEngine` — `build_session(agent_id, channel, entrypoint, channel_permissions: &HashMap<String,String>, tools: &[Box<dyn Tool>], visible_tool_names: &HashSet<String>) -> ToolPolicySession`.+- `ToolPolicyEngine::build_session(agent_id, channel, entrypoint, channel_permissions: &HashMap<String,String>, tools: &[Box<dyn Tool>], visible_tool_names: &HashSet<String>) -> ToolPolicySession`.+- `ToolPolicyEngine::build_session_from_refs(..., tools: &[&dyn Tool], ...)` — same classification over borrowed tools so the harness can classify its durable registry and its synthesized delegate tools together; `build_session` delegates to it.- `render_tool_policy_boundary(session: &ToolPolicySession, max_bytes: usize) -> Option<String>` — `None` when the session has no restrictions; otherwise a truncated prompt section.- Types: `TaskProfile`, `TaskRiskLevel`, `ToolCapability`, `ToolPolicyAction`, `ToolPolicyDecision`, `ToolPolicySession`.-`ToolPolicySession` helpers: `is_allowed(name)`, `has_restrictions()`, `restricted_tool_count()`, `visible_tool_names_for_prompt()`, `decision_for(name)` (defaults to `Deny`). `ToolPolicyDecision::is_denied()` is true for anything other than `Allow`.+`ToolPolicySession` helpers: `is_allowed(name)`, `has_restrictions()`, `restricted_tool_count()`, `visible_tool_names_for_prompt()`, `decision_for(name)` (defaults to `Deny`).++`ToolPolicyDecision` has two predicates that answer different questions:++- `is_denied()` — true for anything other than `Allow`, including `HideFromPrompt`. Right for a direct tool call by name.+- `blocks_execution()` — true for `Deny` / `RequireApproval`, or when `required_permission` exceeds `allowed_permission`. `HideFromPrompt` alone does not block, so withheld packed tools stay reachable through `use_skill`. The permission re-check exists because the classifier tests hidden-ness before the ceiling, so a hidden tool over the ceiling is recorded as `HideFromPrompt` only.## Dependencies-- `crate::tools` — `PermissionLevel` (the ceiling/ordering, parsed and compared) and the `Tool` trait (`name()`, `permission_level()`). The only openhuman/core dependency.-- stdlib `std::collections` (`BTreeSet`/`HashMap`/`HashSet`) and `log` for grep-friendly `[tool-policy]` diagnostics under target `openhuman::tools::agent_policy`.+- `crate::tools` — `PermissionLevel` (ordered, parsed and compared) and the `Tool` trait (`name()`, `permission_level()`). The only in-crate dependency.+- `log` for `[tool-policy]` diagnostics; every call sets `target: "openhuman::tools::agent_policy"` explicitly (the lib crate is named `openhuman`).## Used by-- `crates/openhuman-core/src/agent/harness/session/builder/builder_build.rs` — builds the `ToolPolicySession` via `ToolPolicyEngine::build_session_from_refs`.-- `crates/openhuman-core/src/agent/harness/session/builder/mod.rs` — threads `&ToolPolicySession` through the builder helpers.-- `crates/openhuman-core/src/agent/harness/session/runtime.rs` (via its `runtime_impl_01_part_01.rs` include) — rebuilds the session at runtime with `ToolPolicyEngine::build_session_from_refs`.-- `crates/openhuman-core/src/agent/harness/session/turn/context.rs` — calls `render_tool_policy_boundary` to inject the boundary into the prompt.-- `crates/openhuman-core/src/agent/harness/session/types.rs` — carries `ToolPolicySession` on the session.+- `crates/openhuman-core/src/agent/harness/session/builder/builder_build.rs` — builds two snapshots with `build_session_from_refs`: the session's `tool_policy_session` (with the role visibility filter) and a `channel_policy_session` without it, used to derive the sub-agent tool ceiling.+- `crates/openhuman-core/src/agent/harness/session/builder/mod.rs` — `visible_tool_specs_for_policy` filters prompt-visible specs with `decision_for(name).blocks_execution()`.+- `crates/openhuman-core/src/agent/harness/session/runtime.rs` (via its `runtime_impl_01_part_01.rs` include) — `rebuild_tool_policy_session` re-runs `build_session_from_refs` after `hide_tools`.+- `crates/openhuman-core/src/agent/harness/session/turn/context.rs` — calls `render_tool_policy_boundary(&session, 2048)` and appends the block to the end of the system prompt.+- `crates/openhuman-core/src/agent/harness/session/types.rs` — carries `tool_policy_session` on the session.+- `crates/openhuman-core/src/agent/tinyagents/middleware_part_07.rs` — `ToolPolicyMiddleware` is the runtime enforcement point: `is_denied()` for direct calls, `blocks_execution()` for the `use_skill` route. The snapshot reaches it through `ToolPolicyEnforcement` in `agent/tinyagents/mod_part_01.rs`.+- `crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs` — `SecurityGate::with_tool_policy` accepts an `Arc<ToolPolicySession>` and maps its actions to gate verdicts.+- `crates/openhuman-core/src/config/schema/agent.rs` — the `channel_permissions` field docs describe the engine's fallback semantics.## Notes / gotchas-- **Legacy escape hatch**: an empty `channel_permissions` map yields `PermissionLevel::Dangerous` (fully unrestricted), preserving pre-policy behavior. Once *any* channel policy exists, channels missing from the map (or with an unparseable value) fall back to `PermissionLevel::ReadOnly`, not unrestricted.+- **Legacy escape hatch**: an empty `channel_permissions` map yields `PermissionLevel::Dangerous` (fully unrestricted). `AgentConfig::migrate_channel_permissions_if_legacy` seeds the map on first boot, so this branch is only hit before that migration. Once *any* entry exists, channels missing from the map (or with an unparseable value) fall back to `PermissionLevel::ReadOnly`.- **Permission parsing** (`parse_permission_level`) is lenient: trims, lowercases, strips `-`/`_`, and accepts aliases (`read`/`readonly`, `exec`/`execute`, `danger`/`dangerous`). Unrecognized tokens fall back to read-only.-- **Two independent restriction axes**: a tool can be `Deny`ed (exceeds the permission ceiling → `blocked_tool_names`) or `HideFromPrompt` (not in the non-empty `visible_tool_names` set → `hidden_tool_names`). Hidden takes precedence over deny in the classification order.-- `ToolPolicyAction::RequireApproval` is defined and handled in the match (routed to `blocked_tool_names`) but `build_session` never currently produces it.-- `visible_tool_names_for_prompt()` inserts `NO_TOOLS_ALLOWED_SENTINEL` when restrictions exist but nothing is allowed, so prompt rendering can signal an empty-but-restricted surface rather than an unrestricted one.-- `render_tool_policy_boundary` returns `None` for unrestricted sessions, and `truncate_utf8` guarantees the output stays within `max_bytes` on a char boundary (appending `\n[...truncated]` only when there is room).-- Snapshots are immutable and deterministic per session; there is no mutation API.+- **Two independent restriction axes**: a tool can be `Deny`ed (exceeds the permission ceiling → `blocked_tool_names`) or `HideFromPrompt` (not in the non-empty `visible_tool_names` set → `hidden_tool_names`). Hidden is tested first, so a tool that is both hidden and over the ceiling lands only in `hidden_tool_names`; `blocks_execution()` carries the ceiling check for that case.+- An empty `visible_tool_names` set means "all visible", not "none visible".+- `ToolPolicyAction::RequireApproval` is handled (routed to `blocked_tool_names`) but the engine never produces it.+- `visible_tool_names_for_prompt()` inserts `NO_TOOLS_ALLOWED_SENTINEL` when restrictions exist but nothing is allowed, so callers can distinguish an empty-but-restricted surface from an unrestricted one.+- `truncate_utf8` keeps `render_tool_policy_boundary` output within `max_bytes` on a char boundary, appending `\n[...truncated]` only when there is room.