Skip to content

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

docs(openhuman-embed): add crate README

Steven Enamakelcf3e88c3e82a
diff --git a/crates/openhuman-embed/README.md b/crates/openhuman-embed/README.md
index 88c9597b0d..9195fe3d90 100644
--- a/crates/openhuman-embed/README.md
+++ b/crates/openhuman-embed/README.md
@@ -1,71 +1,102 @@
-# `openhuman-embed`
+# openhuman-embed
-`openhuman-embed` is the host-facing library package for products that run the
-OpenHuman core in-process, including OpenCompany. It re-exports the
-runtime builder from `openhuman-core` and owns the typed embedding facade. See
-[`gitbooks/developing/embedding.md`](../../gitbooks/developing/embedding.md)
-for the narrative walkthrough this README's reference material supports.
+`openhuman-embed` is the library crate a product depends on to run the
+OpenHuman core inside its own process. It turns the core's JSON controllers
+and ambient task-locals into ordinary Rust types: build one `Runtime`, put any
+number of `Agent`s on it, and run turns that return a typed `TurnOutcome`.
+OpenCompany and other embedding products use it directly, and
+`openhuman-tinyhumans` wraps it to add the hosted TinyHumans backend. The
+narrative walkthrough is
+[`gitbooks/developing/embedding.md`](../../gitbooks/developing/embedding.md).
-Use the default contributor feature set:
+## How it works
-```toml
-[dependencies]
-openhuman-embed = { git = "https://github.com/tinyhumansai/openhuman", package = "openhuman-embed" }
-```
+The crate has two entry points, and they sit at different heights over the
+core.
-Or select a narrow host build:
-
-```toml
-[dependencies]
-openhuman-embed = { git = "https://github.com/tinyhumansai/openhuman", package = "openhuman-embed", default-features = false, features = ["inference", "mcp"] }
+```text
+ host product
+ |
+ | Runtime::builder() ... build() Core::from_runtime(rt)
+ v |
+ +-----------+ agent(spec) +---------+ |
+ | Runtime | --------------> | Agent | (n per |
+ +-----------+ +---------+ runtime) |
+ | | |
+ | CoreBuilder::build | Turn::send | Config / Auth /
+ v v | CoreAgent
+ +----------------------------------------------+ |
+ | openhuman-core (package `openhuman`) | <---+
+ | CoreRuntime, CoreContext, controller registry|
+ +----------------------------------------------+
```
-```rust,no_run
-use std::sync::Arc;
+The library API is `Runtime` then `Agent`. `RuntimeBuilder::build` claims the
+process slot, resolves a workspace on disk, assembles one base `Config`,
+writes the TinyHumans API key into the credential store (when given), and
+hands everything to the core's `CoreBuilder`. The result is one booted
+`CoreRuntime` wrapped in a `Runtime`.
-use openhuman_embed::{Core, CoreBuilder, DomainSet, HostKind, ServiceSet};
+`Runtime::agent(spec)` then turns an `AgentSpec` into an `Agent`. Nothing runs
+and no RPC is made. `agent::build::instantiate` validates the id, clones the
+runtime's base config, and applies the spec on top in a fixed order: access,
+provider model, MCP servers, Composio credential, memory binding, then the
+`config` escape hatch. It creates the agent's directories, copies its skills,
+builds its `AgentDefinition`, checks that the agent only narrows the runtime's
+`DomainSet` and `ToolGroups`, and finally derives a per-agent `CoreContext`
+with `CoreContext::derive_with`.
-# async fn run() -> Result<(), Box<dyn std::error::Error>> {
-let runtime = CoreBuilder::new(HostKind::Library)
- .domains(DomainSet::embedded())
- .services(ServiceSet::none())
- .build()
- .await?;
-let core = Core::from_runtime(Arc::new(runtime));
-let flags = core.config().runtime_flags().await?;
-println!("log_prompts={}", flags.log_prompts);
-# Ok(())
-# }
+A turn on that agent goes through `Turn::send`:
+
+```text
+ agent.turn("msg").session(id).send()
+ |
+ |- mint a session id ("embed-<uuid>") if none was given
+ |- refuse a half route, or a bearer sent to a non-https endpoint
+ |- enter the origin and progress task-local scopes, if set
+ |- runtime.run_in(agent ctx, ...)
+ | agent_chat_for(config, AgentChatTarget::Definition { .. }, ...)
+ | (inference::host_runtime::ops, native, no JSON)
+ v
+ TurnOutcome { reply, session_id, usage }
```
-Embedding products should set their product identity once during startup,
-before constructing backend clients:
+Because the turn runs under the agent's own context, the core's config
+loader, `DomainSet` gate, tool-group filter and skill discovery all read that
+agent's settings. Two agents on one runtime never see each other's provider,
+access tier, MCP servers or skills. Conversations are keyed by thread id and
+agent id, so a turn only resumes its own agent's thread.
-```rust
-use openhuman_tinyhumans::{set_product_identity, ProductIdentity};
+The second entry point is `Core`, for a host that built a `CoreRuntime` with
+`CoreBuilder` itself. `Core::from_runtime` wraps it and exposes typed
+sub-facades (`config()`, `auth()`, `agent()`). These go through
+`CoreRuntime::invoke` (the private `call` helper in `src/call.rs`), so they
+honour `DomainSet` gating and absorb the variable `{result, logs}` envelope
+that controllers emit. `CoreAgent` runs the runtime's orchestrator over the
+`inference.agent_chat` RPC. `Core::raw()` is the escape hatch for a call the
+facade does not model yet; a raw call that keeps coming back is a candidate
+for a typed method here.
-if let Some(identity) = ProductIdentity::new("opencompany") {
- set_product_identity(identity);
-}
-```
+## Using it
+
+Add the dependency with the default contributor features, or pick a narrow
+host build:
-Use `Core::raw()` only as a temporary escape hatch when the typed facade does
-not yet model a required call. A repeated raw call is a candidate for a typed
-embedding method in `openhuman-embed`.
+```toml
+[dependencies]
+openhuman-embed = { git = "https://github.com/tinyhumansai/openhuman", package = "openhuman-embed" }
-## Two steps: a `Runtime`, then any number of `Agent`s
+# or
+openhuman-embed = { git = "https://github.com/tinyhumansai/openhuman", package = "openhuman-embed", default-features = false, features = ["inference", "mcp"] }
+```
-The library API. Initialize one runtime (features, services, backend URL,
-the TinyHumans API key), then instantiate agents on it, each fully described
-and independent of the others:
+### A runtime and several agents
-For hosted TinyHumans inference and services, use
-[`openhuman_tinyhumans::RuntimeBuilder`](../openhuman-tinyhumans/README.md),
-which binds the backend transport during startup. The
-[minimal library recipe](../../docs/library-minimal-recipe.md) covers the
-dependency and feature selection. The plain embed builder supports standalone
-hosts with their own providers; hosted requests require an installed transport
-and otherwise return `BACKEND_UNAVAILABLE:`.
+For hosted TinyHumans inference and services, build the runtime with
+[`openhuman_tinyhumans::RuntimeBuilder`](../openhuman-tinyhumans/README.md).
+It mirrors this crate's builder and installs the SDK-backed backend transport
+on `build()`. The plain `openhuman_embed::RuntimeBuilder` suits standalone
+hosts that bring their own providers.
```rust,no_run
use openhuman_tinyhumans::{
@@ -76,7 +107,7 @@ use openhuman_tinyhumans::{
# async fn demo() -> Result<(), Box<dyn std::error::Error>> {
let runtime = RuntimeBuilder::new()
.workspace(Workspace::dir("/var/lib/my-product/openhuman"))
- .api_key("th_live_…") // the only credential in library mode
+ .api_key("th_live_...") // the only credential in library mode
.build()
.await?;
@@ -84,13 +115,13 @@ let reviewer = runtime.agent(
AgentSpec::new("reviewer")
.system_prompt("You review pull requests and never edit files.")
.access(Access::readonly())
- .skills_dir("./skills/review") // copied into this agent's own skills root
+ .skills_dir("./skills/review") // copied into this agent's skills root
.action_dir("/srv/checkouts/pr-42"),
)?;
let fixer = runtime.agent(
AgentSpec::new("fixer")
- .provider(Provider::openai_compatible("https://api.example/v1", "sk-…").model("gpt-5"))
+ .provider(Provider::openai_compatible("https://api.example/v1", "sk-...").model("gpt-5"))
.access(Access::full())
.mcp(McpServer::stdio("github", "gh-mcp", ["stdio"]))
.action_dir("/srv/checkouts/pr-42"),
@@ -101,96 +132,40 @@ let fix = fixer
.turn(format!("Address these findings:\n{}", review.reply))
.send()
.await?;
-println!("{}", fix.reply);
-// Continue a conversation with the same agent.
+// Continue the same conversation with the same agent.
let again = fixer.turn("Now run the tests.").session(&fix.session_id).send().await?;
println!("{}", again.reply);
# Ok(())
# }
```
-What each agent owns: its provider route and model, its access tier and
-turn origin, its `action_dir`, its MCP servers, its skills root
-(`<workspace>/agents/<id>/skills/`), its system prompt, tool scope and
-sandbox mode (`AgentDefinitionSpec`), and a narrowed `DomainSet` /
-`ToolGroups`. Every turn is
-dispatched under the agent's own `CoreContext`, so the core's config loader,
-domain gate, tool-group filter and skill discovery all read that agent's
-settings and never another's. Transcripts are keyed by agent id and a turn
-resumes only its own thread.
-
-What the runtime owns: the workspace and credential store, the event bus,
-the keyring, the background `ServiceSet`, the registered `DomainSet` (agents
-can only narrow it, so enable `mcp` / `skills` at runtime build time if any
-agent will use them; the default does), and the API key.
+`McpServer` and `AgentSpec::mcp` need the `mcp` feature; `skills_dir` needs
+`skills`. `Agent::run` always starts a new conversation. To continue one, pass
+the returned `session_id` to `Turn::session`.
-Layout under a runtime-owned root:
+A `Turn` has more knobs than the example shows: `model` and `temperature`
+for one turn, `cwd` to root the file and shell tools somewhere else (use
+`openhuman_embed::absolute` for a relative path, since the core resolves a
+relative `cwd` against `action_dir`), `route` for a one-off endpoint,
+`origin` for the authority the turn claims, `on_progress` for live
+`AgentProgress` events, `meter` for usage that is reported even when the turn
+fails, and `seed` to replace the session's history with rows the host
+supplies.
-```text
-<root>/config.toml, auth-profiles.json, core.token
-<root>/workspace/session_db/, session_raw/<ts>_<agent>.jsonl, agents/<agent>/skills/
-<root>/agents/<agent>/action/ default action_dir
-```
+### Harness: the one-agent shorthand
-### Backend connection
-
-The core knows the hosted TinyHumans backend only through
-`BackendTransport` (re-exported here). `openhuman-embed` alone installs
-none: agents, memory, skills, tools and RPC run without any TinyHumans
-connection, and calls to hosted-backend surfaces answer with a typed
-`BACKEND_UNAVAILABLE:` error. This includes managed inference, billing,
-`/agent-integrations/*` tools, cloud voice, and session-bound surfaces such as
-channel relay. Use `openhuman-tinyhumans`, whose
-`RuntimeBuilder` mirrors this one and installs the SDK-backed transport on
-`build()`, or pass your own to `RuntimeBuilder::backend_transport`. See
-[`gitbooks/developing/tinyhumans-api-key.md`](../../gitbooks/developing/tinyhumans-api-key.md)
-for what that one key then unlocks.
-
-### Authentication
-
-Library mode has no user login. `RuntimeBuilder::api_key` installs a
-TinyHumans API key into the runtime's credential store before the core boots;
-managed inference then sends it as `Authorization: Bearer <key>` to the
-TinyHumans OpenAI-compatible endpoint, backend REST calls send it as
-`x-api-key`, and the scheduler gate treats the runtime as signed in. No
-`/auth/me` round trip, no session JWT, nothing to expire. An agent that names
-its own `Provider` (BYOK) never touches the key.
-
-The key covers every hosted feature the core reaches: managed inference, cloud
-embeddings, voice (STT and TTS), web search, media generation, the Jev ranker,
-Composio and the other `/agent-integrations/*` tools, referral, and webhooks.
-The realtime voice agent and Socket.IO relay require a signed-in user session. Callers that
-can only send a bearer (the vendored STT and embedding clients, the connector
-module's proxy route, the memory engine's sync) send the key as
-`Authorization: Bearer`, which the backend accepts because it recognises the
-`tiny_live_` / `tiny_test_` prefix. What a key may reach is decided by its
-scopes on the backend: `inference`, `voice`, `search`, `media`, `storage`,
-`account` and `connections` (Composio). A key minted through the grant flow
-omits `connections` unless it is asked for; a missing scope answers `403`.
-The session-bound `/auth/*` flows (OAuth connect, channel link tokens, login
-tokens), the realtime voice agent, and the Socket.IO relay still need a
-signed-in user.
-
-`HarnessBuilder::session`
-remains for hosts that drive backend features on behalf of a signed-in user;
-the core stores that session as handed over (`auth.set_credential`) and never
-validates it: obtaining and validating a JWT is the host's job (see
-`openhuman_tinyhumans::session`).
-
-### `Harness`: the one-agent shorthand
-
-`Harness` is a `Runtime` plus exactly one `Agent` (id `harness`), built from
-one set of inputs. Existing callers keep working; `harness.runtime()` and
-`harness.agent()` hand out the two halves, so a host that outgrows one agent
-creates more on the same runtime.
+`Harness` is a `Runtime` plus exactly one `Agent` with the id `harness`,
+built from one set of inputs. `harness.runtime()` and `harness.agent()` hand
+out the two halves, so a host that outgrows one agent adds more on the same
+runtime instead of building a second harness.
```rust,no_run
use openhuman_embed::{Access, Harness, Provider, Workspace};
# async fn demo() -> Result<(), Box<dyn std::error::Error>> {
let harness = Harness::builder()
- .provider(Provider::openai_compatible("https://api.example/v1", "sk-…").model("gpt-5"))
+ .provider(Provider::openai_compatible("https://api.example/v1", "sk-...").model("gpt-5"))
.workspace(Workspace::Ephemeral)
.access(Access::readonly())
.build()
@@ -207,53 +182,166 @@ println!("{}", second.reply);
# }
```
-`Core` is the typed facade shown at the top: a host that already built a
-`CoreRuntime` wraps it with `Core::from_runtime` and reaches sub-facades
-through it: `config()`, `auth()`, and `agent()` (a `CoreAgent` running the
-orchestrator).
+A harness keeps a few older defaults. Its agent's `action_dir` is the
+workspace's own `action/` directory, its skills are copied into the shared
+`<workspace>/skills` root, and it only turns on the `mcp` and `skills` domain
+families when servers or a skills directory were supplied. See
+[`src/harness/README.md`](src/harness/README.md).
+
+### The typed core facade
+
+```rust,no_run
+use std::sync::Arc;
+
+use openhuman_embed::{Core, CoreBuilder, DomainSet, HostKind, ServiceSet};
+
+# async fn run() -> Result<(), Box<dyn std::error::Error>> {
+let runtime = CoreBuilder::new(HostKind::Library)
+ .domains(DomainSet::embedded())
+ .services(ServiceSet::none())
+ .build()
+ .await?;
+let core = Core::from_runtime(Arc::new(runtime));
+let flags = core.config().runtime_flags().await?;
+println!("log_prompts={}", flags.log_prompts);
+# Ok(())
+# }
+```
-### One runtime per process
+`Core::agent()` needs the `inference` domain family at runtime. Note that
+`DomainSet::harness()` leaves `inference` off despite its name; use
+`DomainSet::embedded()`.
-The keyring master key, the RPC bearer, the global event bus and the
-`Once`-guarded domain subscribers are process-scoped
-(`openhuman_core::core::runtime::context::CoreContext::init` runs that
-sequence), so a second runtime would silently share them while believing it
-had a separate workspace. `RuntimeBuilder::build` returns
-`RuntimeError::AlreadyRunning` instead; agents are the unit of multiplicity.
-`Core::from_runtime` is not guarded (it only wraps a runtime the host
-already built), but the same constraint applies to the `CoreRuntime` beneath
-it.
+### Product identity
-Build the tokio runtime yourself. A turn is a large async state machine that
-overflows tokio's default 2 MiB worker stack once a sub-agent nests inside it,
-so use `AGENT_WORKER_STACK_BYTES` and `MAX_BLOCKING_THREADS` from
-[`openhuman_core::core::runtime`](../openhuman-core/src/core/runtime/README.md):
+An embedding product sets its identity once at startup, before any backend
+client is built. It becomes the `x-sdk-name` header on TinyHumans requests.
```rust,no_run
-use openhuman_core::core::runtime::{AGENT_WORKER_STACK_BYTES, MAX_BLOCKING_THREADS};
+use openhuman_tinyhumans::{set_product_identity, ProductIdentity};
-let runtime = tokio::runtime::Builder::new_multi_thread()
- .enable_all()
- .thread_stack_size(AGENT_WORKER_STACK_BYTES)
- .max_blocking_threads(MAX_BLOCKING_THREADS)
- .build()
- .expect("tokio runtime");
+if let Some(identity) = ProductIdentity::new("opencompany") {
+ set_product_identity(identity);
+}
+```
+
+`openhuman_tinyhumans::RuntimeBuilder::product_identity` does the same as
+part of the build.
+
+## What the runtime owns and what an agent owns
+
+The runtime owns everything that is process-scoped in the core: the
+workspace and credential store, the event bus, the keyring, the RPC bearer,
+the background `ServiceSet`, the registered `DomainSet` and the API key.
+Agents can only narrow the domain set, so a runtime has to register `mcp` and
+`skills` if any agent will use them. The default runtime does when those
+features are compiled in.
+
+Each agent owns its provider route and model, its access tier and turn
+origin, its `action_dir`, its MCP servers, its skills root, its
+`AgentDefinitionSpec` (system prompt, tool scope, sandbox mode, iteration cap,
+temperature), its narrowed `DomainSet` and `ToolGroups`, its memory binding
+and an optional host tool factory.
+
+The on-disk layout under a runtime-owned root:
+
+```text
+<root>/
+ config.toml, auth-profiles.json, core.token runtime-wide
+ workspace/
+ session_db/sessions.db runtime-wide run ledger
+ session_raw/ transcripts, one per thread+agent
+ agents/<id>/skills/ each agent's skills root
+ agents/<id>/action/ default action_dir per agent
```
-### Memory per tenant
+The default `action_dir` sits beside the workspace, never inside it, because
+the core refuses agent writes beneath the workspace. An inherited workspace
+uses `<action_dir>/agents/<id>` instead.
-Bind each agent with `AgentSpec::memory(MemoryBinding::new(agent_id).root("team:acme"))`
-and its turns run TinyMemory's lifecycle under `team:acme/agent:<agent_id>`.
-`Runtime::memory("team:acme")` is the operator's view of that tenant: its
-agents, items, learnings and brain. Every call stays inside the root's subtree.
-`RuntimeBuilder::memory_engine` installs a host-supplied engine in place of the
-configured one. See `docs/specs/memory-v2.md`.
+### Settings that are still runtime-wide
-### Conversations in a host store
+Every agent reads these from the runtime's boot config today. Each is a
+candidate follow-up in the core.
+
+- `autonomy.auto_approve` and `auto_approve_all`, and the memory guard's
+ autonomy tier, come from the boot config (`security::live_policy`). Path
+ and command policy do use the agent's own tier.
+- The approval gate is on or off for the whole process, and parked approvals
+ are not labelled with an agent id. For an agent that never waits on
+ approval, use `Access::full()`, whose `TrustedAutomation` origin the gate
+ honours per turn.
+- The sub-agent catalogue is runtime-wide (built-ins plus
+ `<workspace>/agents/*.toml`). Embedded agents cannot be `delegate_*`
+ targets of each other. Do not reuse built-in ids such as `orchestrator` or
+ `summarizer` for your agents.
+- Sub-agents an agent spawns, and the experience store, read the runtime's
+ on-disk config rather than the agent's overlay.
+- Sub-agent run-ledger rows, cron jobs and the cost log stay in the
+ workspace even with a host session store.
+- Agents on one workspace share the dynamic `mcp_registry_*` MCP registry.
+ Servers declared through `AgentSpec::mcp` are per agent. The host-seeded
+ documentation server is visible to every agent.
+- `install_skill` and `create_skill` still write to `~/.openhuman`. With
+ `include_user_skills(false)` (the default) an agent does not discover the
+ operator's skills, but an install it performs lands there.
+- One API key (or session) is shared by every agent.
+
+## Authentication and the backend
+
+Library mode has no user login. `RuntimeBuilder::api_key` stores a
+TinyHumans API key in the runtime's credential store before the core boots.
+Managed inference then sends it as `Authorization: Bearer <key>`, backend
+REST calls send it as `x-api-key`, and the scheduler gate treats the runtime
+as signed in. There is no `/auth/me` round trip and no session to expire. An
+agent that names its own `Provider` never uses the key for inference.
+
+The key covers the hosted features the core reaches: managed inference,
+cloud embeddings, voice (STT and TTS), web search, media generation, the Jev
+ranker, Composio and the other `/agent-integrations/*` tools, referral and
+webhooks. Callers that can only send a bearer (the vendored STT and embedding
+clients, the connector module's proxy route, the memory engine's sync) send
+the key as `Authorization: Bearer`, which the backend accepts by its
+`tiny_live_` / `tiny_test_` prefix. What a key may reach is decided by its
+scopes on the backend (`inference`, `voice`, `search`, `media`, `storage`,
+`account`, `connections`); a missing scope answers `403`, and a key minted
+through the grant flow omits `connections` unless it was asked for. The
+session-bound `/auth/*` flows (OAuth connect, channel link tokens, login
+tokens), the realtime voice agent and the Socket.IO relay still need a
+signed-in user. See
+[`gitbooks/developing/tinyhumans-api-key.md`](../../gitbooks/developing/tinyhumans-api-key.md).
+
+A host that drives backend features for a signed-in user passes a `Session`
+to `RuntimeBuilder::session` (or `HarnessBuilder::session`, or later
+`Auth::store`). The core stores it through `openhuman.auth_set_credential`
+and never validates it. Obtaining and checking the JWT is the host's job,
+which `openhuman_tinyhumans::session` does for the desktop app and TUI.
+`Session::local` builds the offline `.local` token form, which authorizes
+nothing at the backend.
+
+The core reaches the hosted backend only through a `BackendTransport`
+(re-exported here). This crate installs none. Without one, agents, memory,
+skills, tools and RPC still work, and hosted surfaces (managed inference,
+billing, integrations tools, cloud voice, channel relay) answer with a typed
+`BACKEND_UNAVAILABLE:` error. `openhuman_tinyhumans::RuntimeBuilder` installs
+the SDK transport for you; `RuntimeBuilder::backend_transport` takes your own.
+
+## Memory per tenant
+
+Bind an agent with
+`AgentSpec::memory(MemoryBinding::new(agent_id).root("team:acme"))` and its
+turns run TinyMemory's lifecycle under `team:acme/agent:<agent_id>`.
+`Runtime::memory("team:acme")` returns a `memory::Memory`, the operator's view
+of that tenant: its agents, items, learnings and brain documents, with every
+call confined to the root's subtree. `RuntimeBuilder::memory_engine` installs
+a host-supplied engine in place of the configured one. See
+[`docs/specs/memory-v2.md`](../../docs/specs/memory-v2.md).
+
+## Conversations in a host store
By default an agent's transcripts, turn journal, run status, goals and todos
-are files under the runtime's workspace. A host serving many users from one
-process keeps them in its own database instead:
+are files under the workspace. A host serving many users from one process
+keeps them in its own database instead:
```rust,ignore
let runtime = Runtime::builder()
@@ -263,148 +351,161 @@ let runtime = Runtime::builder()
.await?;
```
-The runtime asks the provider (`session_store::SessionStoreProvider`) for
-each agent's stores by agent id, so a provider over a shared database scopes
-every query by agent and one agent can never reach another's conversation. A
-reopened agent resumes its thread from the store, in any process.
-`InMemorySessionStores` keeps everything in memory; the conformance suites in
-`session_store` are what a host's provider is held to.
-`Workspace::stateless()` refuses to build without a store, and a private
-scratch directory, removed with the runtime, still holds process-local
-caches (cost log, prompt templates, migration markers). The desktop app, CLI
-and TUI install `openhuman_rpc::session_store`, the classic on-disk layout behind
-the same port. See `tests/session_store.rs`.
-
-### Still runtime-wide
-
-These are read from the runtime's boot config by every agent today. They
-are documented rather than hidden; each is a candidate follow-up in the core.
-
-- `autonomy.auto_approve` / `auto_approve_all` and the memory guard's
- autonomy tier come from the runtime's boot config (`security::live_policy`),
- not the agent's. Path and command policy _do_ use the agent's own tier.
-- The approval gate is on or off process-wide; parked approvals are not
- labelled with the agent id. A per-agent "no approvals" is `Access::full()`,
- whose `TrustedAutomation` origin the gate honours per turn.
-- The sub-agent catalogue is runtime-wide (built-ins plus
- `<workspace>/agents/*.toml`). Embedded agents cannot be `delegate_*`
- targets of one another. Do not reuse built-in ids (`orchestrator`,
- `summarizer`, …) for your agents.
-- Sub-agents an agent spawns and the experience store re-read the runtime's
- on-disk config rather than the agent's overlay. (The turn journal goes to
- the agent's own stores under a host session store; without one it uses the
- process-default workspace.)
-- Sub-agent run-ledger rows, cron jobs and the cost log stay in the
- workspace even with a host session store.
-- Agents sharing a workspace share the dynamic (`mcp_registry_*`) MCP
- registry; `[[mcp_client.servers]]` declared through `AgentSpec::mcp` are
- per agent. The host-seeded documentation server is visible to every agent.
-- `install_skill` / `create_skill` still write to `~/.openhuman`. With
- `include_user_skills(false)` (the default) an agent does not _discover_ the
- operator's skills, but an install by the agent lands there.
-- One API key (or session) is shared by all agents.
-- `IntegrationClient` (backend-proxied Composio/search/media tools) accepts
- the runtime's TinyHumans API key or an app-session JWT through
- `security::credentials::session_support::resolve_backend_credential`.
- API keys use `x-api-key`; session JWTs use `Authorization: Bearer`.
- With the backend transport installed and the integration feature and runtime
- gates enabled, an API-key-only runtime can register integration tools.
-
-Other invariants worth knowing before wiring any entry point:
-
-- When building a `CoreRuntime` yourself, set `config_path` together with
- `workspace_dir` (`CoreBuilder::workspace(dir)` does both). Credentials,
- auth profiles and the keyring file resolve beside `config_path`, so a
- workspace-only override reads the operator's real credentials. `Runtime`
- and `Harness` set both for `Workspace::Ephemeral` and `Workspace::Dir`.
-- A turn runs under the access tier _and_ the turn origin. `Access::full()`
- sets both (`AutonomyLevel::Full` plus a `TrustedAutomation` origin);
- `Access::readonly()` and `Access::supervised()` set no origin and leave the
- approval gate on.
-- Supply skills through `AgentSpec::skills_dir` / `HarnessBuilder::skills_dir`,
- which copy the bundles. Skill discovery rejects symlinked bundles, so
- linking them in does not work.
+The runtime asks the provider (`session_store::SessionStoreProvider`) for each
+agent's stores by agent id, so a provider over a shared database scopes every
+query by agent. A reopened agent resumes its thread from the store, in any
+process. `InMemorySessionStores` keeps everything in memory, and the
+conformance suites re-exported from `session_store` are what a host's
+provider is held to. `Workspace::stateless()` refuses to build without a
+store (`RuntimeError::NoSessionStore`); a private scratch directory, removed
+with the runtime, still holds process-local caches. The desktop app, CLI and
+TUI install `openhuman_rpc::session_store`, the classic on-disk layout behind
+the same port.
+
+## Tools on an agent
+
+`AgentSpec::tools` gives an agent the host's own in-process tools, each with
+its own schema on the wire. The factory runs once per session build, which
+in practice is once per turn, and receives a `TurnContext` naming the agent
+and the session. `Agent::attach_tools` adds a permanent named tool source to
+an agent that already exists, which is how one library hands a configured
+agent to another. See [`src/agent/README.md`](src/agent/README.md).
+
+## Layout
+
+| Path | What it does |
+| --- | --- |
+| `src/lib.rs` | Re-exports (core runtime types, `Tool`, `ToolGroups`, the backend port, `session_store`, `agent_progress`) and `Core`, the typed facade over a caller-built `CoreRuntime`. |
+| [`src/runtime/`](src/runtime/README.md) | `Runtime`, `RuntimeBuilder`, `ApiKey`, and the `CoreGuard` that owns process-scoped state until the last handle drops. |
+| [`src/agent/`](src/agent/README.md) | `Agent`, `AgentSpec`, `AgentDefinitionSpec`, `AgentLayout`, `MemoryBinding`, the build step, and permanent tool attachments. |
+| [`src/harness/`](src/harness/README.md) | `Harness` and `HarnessBuilder`, plus the shared input types: `Access`, `Provider`, `Workspace`, `McpServer`, skill copying, `HarnessError`. |
+| `src/turn.rs` | `Turn`, `TurnRequest`, `TurnOutcome`, `Route`: one turn, its ambient scopes, and its dispatch to an agent or to the orchestrator. |
+| `src/call.rs` | The private typed dispatch helper over `CoreRuntime::invoke` that every facade method uses. |
+| `src/config.rs`, `src/auth.rs`, `src/core_agent.rs` | The `Core` sub-facades: runtime flags, credentials (`Session`, `AuthState`), and the orchestrator turn. |
+| `src/memory.rs` | `Memory`, the per-tenant memory facade returned by `Runtime::memory`. |
+| `src/error.rs` | `CoreError`, the error every facade call returns (`Domain`, `Unavailable`, `Rpc`, route refusals). |
+| [`examples/`](examples/README.md) | Runnable programs: one turn on a harness, and two agents on one runtime. |
+| [`tests/`](tests/README.md) | End-to-end suites against `wiremock` providers. |
+
+## Key types and entry points
+
+- `Runtime` and `RuntimeBuilder` (`src/runtime/`): build once per process,
+ then call `Runtime::agent`. `Runtime::core()` gives non-turn access
+ (config, auth) without exposing a way to start a turn.
+- `AgentSpec` (`src/agent/spec.rs`): the pure-data description of an agent.
+ Ids must match `^[a-z0-9][a-z0-9_-]{0,63}$`.
+- `Agent` (`src/agent/mod.rs`): a cheap clone handle. `run`, `turn`,
+ `attach_tools`, and path accessors (`action_dir`, `home_dir`,
+ `skills_dir`, `transcripts_dir`).
+- `Turn` and `TurnOutcome` (`src/turn.rs`): configure, then `send`.
+- `Access` (`src/harness/access.rs`): the autonomy tier and turn origin,
+ always set together. Presets are `readonly`, `supervised` (the default)
+ and `full`.
+- `Provider` (`src/harness/provider.rs`): `openai_compatible(base_url, key)`
+ plus `model`, or `inherit()` for the machine's configured inference.
+- `Workspace` (`src/harness/workspace.rs`): `Ephemeral` (default), `Dir`,
+ `Stateless`, or `Inherit`.
+- `Harness` (`src/harness/mod.rs`): one runtime, one agent.
+- `Core` (`src/lib.rs`): the typed facade over a caller-built runtime.
## Feature flags
-Every feature on this crate is a pass-through to the same-named feature on
-`openhuman-core` (package `openhuman`): `default`, `http-server`,
-`inference`, `documents`, `hosting`, `modules`, `voice`, `web3`,
-`runtime-node`, `contacts`, `media`, `flows`, `skills`, `mcp`,
-`crash-reporting`, `channels`,
-`sandbox-bubblewrap`, `browser-native`, `whatsapp-web`,
-`file-logging`, `scheduler-gate`.
-
-Two of them also gate items on this crate's own public surface:
+Every feature is a pass-through to the same-named feature on
+`openhuman-core` (package `openhuman`): `default`, `http-server`, `inference`,
+`documents`, `hosting`, `modules`, `voice`, `web3`, `runtime-node`, `media`,
+`flows`, `skills`, `mcp`, `crash-reporting`, `channels`, `whatsapp-web`,
+`file-logging` and `scheduler-gate`. A gate added to the core has to be
+forwarded here (and then by `openhuman-tinyhumans` and `openhuman-cli`);
+`scripts/ci/check-feature-forwarding.mjs` checks the chain.
-- `mcp`: `HttpHeader`, `McpAuthConfig`, `McpServer`, `AgentSpec::mcp` and
- `HarnessBuilder::mcp`.
-- `skills`: `AgentSpec::skills_dir` and `HarnessBuilder::skills_dir`.
+Two features also gate this crate's own surface. `mcp` adds `HttpHeader`,
+`McpAuthConfig`, `McpServer`, `AgentSpec::mcp` and `HarnessBuilder::mcp`.
+`skills` adds `AgentSpec::skills_dir` and `HarnessBuilder::skills_dir`.
-See [`docs/library-minimal-recipe.md`](../../docs/library-minimal-recipe.md)
-for a measured minimal-footprint feature set, and
+[`docs/library-minimal-recipe.md`](../../docs/library-minimal-recipe.md) has a
+measured minimal feature set, and
[`gitbooks/developing/performance.md`](../../gitbooks/developing/performance.md)
-for the resulting binary sizes and per-agent memory numbers.
-
-## Examples and tests
-
-```bash
-# Against any OpenAI-compatible endpoint:
-OPENHUMAN_EXAMPLE_BASE_URL=https://api.openai.com/v1 \
-OPENHUMAN_EXAMPLE_API_KEY=sk-… \
-OPENHUMAN_EXAMPLE_MODEL=gpt-5 \
- cargo run -p openhuman-embed --example run_turn -- "What can you see in this directory?"
-
-# Or against the machine's own configured inference, in its real workspace:
-OPENHUMAN_EXAMPLE_INHERIT=1 cargo run -p openhuman-embed --example run_turn -- "Hello."
-```
-
-Optional: `OPENHUMAN_EXAMPLE_BACKEND_URL` points non-inference backend calls
-somewhere specific, and `OPENHUMAN_EXAMPLE_SKILLS_DIR` supplies skill bundles.
-
-Two agents on one runtime, either BYOK with the same variables as above, or
-managed inference with `OPENHUMAN_EXAMPLE_TINYHUMANS_API_KEY`:
+has the resulting binary sizes and per-agent memory.
+
+## Boundaries
+
+- The only in-repo dependency is `openhuman-core` with
+ `default-features = false`. Every capability comes from a forwarded
+ feature.
+- No JSON-RPC here. This crate does not depend on `openhuman-rpc`; `Outcome`
+ and `StructuredRpcError` are core types. `openhuman-app` and
+ `openhuman-tui` use `openhuman-rpc` and the core directly and do not use
+ this crate.
+- No backend client. The hosted transport, product identity, login-token
+ exchange and `/auth/me` live in `openhuman-tinyhumans`.
+- The agent loop, transcripts, session identity and tool-call parsing belong
+ to `vendor/tinyagents` (repo `tinyhumansai/tinyagents`); the `Tool` trait
+ belongs to its nested `tinytools`. Use the `Tool` re-exported here: a
+ separately added `tinytools` builds an incompatible type.
+- Memory contracts come from `vendor/tinymemory` (`tinymemory-api`).
+
+## Gotchas
+
+- One runtime per process. The keyring master key, the RPC bearer, the
+ event bus and the `Once`-guarded domain subscribers are process-scoped
+ (`CoreContext::init`). A second `RuntimeBuilder::build` returns
+ `RuntimeError::AlreadyRunning`; a second harness returns
+ `HarnessError::AlreadyRunning`. `Core::from_runtime` is not guarded, but
+ the same rule applies to the `CoreRuntime` beneath it. The slot is
+ released only when the `Runtime` and every `Agent` built on it are
+ dropped.
+- Build the tokio runtime yourself. A turn is a deep async state machine,
+ and a nested sub-agent overflows tokio's default 2 MiB worker stack, so
+ `#[tokio::main]` is not enough. The constants live in the core crate, so
+ the host needs the `openhuman` package as a dependency to name them:
+
+ ```rust,no_run
+ use openhuman_core::core::runtime::{AGENT_WORKER_STACK_BYTES, MAX_BLOCKING_THREADS};
+
+ let runtime = tokio::runtime::Builder::new_multi_thread()
+ .enable_all()
+ .thread_stack_size(AGENT_WORKER_STACK_BYTES)
+ .max_blocking_threads(MAX_BLOCKING_THREADS)
+ .build()
+ .expect("tokio runtime");
+ ```
+
+- Access has two halves. The autonomy tier drives `SecurityPolicy`, and the
+ turn origin (a task-local) drives the approval gate. `Access::full()` sets
+ both; setting only the tier through `config` gives an agent whose acting
+ tools refuse while the transcript looks plausible. `readonly()` and
+ `supervised()` set no origin and leave the approval gate on, so an
+ unattended supervised agent stalls on approvals until they expire.
+- When building a `CoreRuntime` yourself, set `config_path` together with
+ `workspace_dir` (`CoreBuilder::workspace(dir)` does both). Credentials,
+ auth profiles and the keyring file resolve beside `config_path`, so a
+ workspace-only override reads the operator's real credentials. `Runtime`
+ and `Harness` handle this for `Ephemeral`, `Stateless` and `Dir`, and the
+ `AgentSpec::config` escape hatch cannot move it.
+- Supply skills through `skills_dir`, which copies bundles. Skill discovery
+ rejects symlinked bundles, so linking them in silently does nothing.
+- `Provider::model` is advisory. A model no provider serves falls back to
+ the default rather than failing, and a route with no model resolved is
+ ignored.
+- A `Route` (or `Provider::openai_compatible`) that pairs a key with a plain
+ `http://` endpoint is refused before dispatch with
+ `CoreError::InsecureRoute`. A route without a key is allowed.
+- A resumed session keeps its first system prompt and tool list. Prompt
+ changes and a tool factory that returns a different belt only reach new
+ sessions.
+
+## Tests
+
+The integration suites under [`tests/`](tests/README.md) each build one
+runtime per process against `wiremock` providers; unit tests sit beside
+their modules as `*_tests.rs`.
```bash
-OPENHUMAN_EXAMPLE_BASE_URL=https://api.openai.com/v1 \
-OPENHUMAN_EXAMPLE_API_KEY=sk-… \
-OPENHUMAN_EXAMPLE_MODEL=gpt-5 \
- cargo run -p openhuman-embed --example two_agents -- "Describe this directory."
-
-# Or managed inference, no BYOK endpoint needed:
-OPENHUMAN_EXAMPLE_TINYHUMANS_API_KEY=th_… \
- cargo run -p openhuman-embed --example two_agents -- "Describe this directory."
+cargo test -p openhuman-embed --features inference,mcp,skills
+cargo test -p openhuman-embed --features inference,mcp,skills --test runtime_agents
```
-The repository-root `examples/embed_headless.rs` (`DomainSet::harness()`,
-`ServiceSet::none()`, RPC through `CoreRuntime::invoke`) and
-`examples/embed_kernel.rs` (`DomainSet::kernel()`, then opt one family back
-in) drive `CoreBuilder` from `openhuman_core` directly, without this crate;
-they are `[[example]]` entries of the `openhuman` package, so run them with
-`cargo run --example embed_headless`.
-
-`tests/harness_embed.rs` is the end-to-end proof that `Harness` runs a real
-turn against a `wiremock` provider with nothing bound;
-`tests/runtime_agents.rs` runs three agents with different providers, access
-tiers, skills, MCP servers and working directories on one runtime and shows
-the API key reaching a mocked managed backend as a bearer;
-`tests/public_api.rs` pins the host-facing embedding contract at compile
-time. Run them with `cargo test -p openhuman-embed --features inference,mcp,skills`.
-
-## Relationship to other crates
-
-Its only in-repo dependency is `openhuman-core` (package `openhuman`) with
-`default-features = false`: every capability comes from a feature forwarded
-above. It does not depend on `openhuman-rpc`; `Outcome` and `StructuredRpcError`
-are core types (`openhuman_core::core`). `openhuman-app` and `openhuman-tui`
-depend on `openhuman-rpc` for its client (and the app on its server) and on
-`openhuman-core`; neither uses `openhuman-embed`.
-
-## Permanent tools on supplied agents
-
-Hosts can pass an existing configured `Agent` to another library, which adds
-its tools through `Agent::attach_tools` without constructing a replacement.
-Attachments are shared by clones, always directly advertised, and update only
-their managed system catalogue when a continuing conversation gains tools.
-See [agent attachment semantics and example](src/agent/README.md#attach-tools-to-an-existing-agent)
-for source identity, collision errors, policy composition, and runtime identity.
+The repository-root `examples/embed_headless.rs` and `examples/embed_kernel.rs`
+drive `CoreBuilder` directly, without this crate. They are `[[example]]`
+targets of `openhuman-cli`:
+`cargo run -p openhuman-cli --example embed_headless`.