Skip to content

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

Merge branch 'main' into openhuman-embed-complete

Steven Enamakeld683cafc4717
diff --cc crates/openhuman-embed/README.md
index a19b28c3a2,f0c69cb919..37c3aba1a7
--- a/crates/openhuman-embed/README.md
+++ b/crates/openhuman-embed/README.md
@@@ -263,187 -351,161 +351,200 @@@ 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.
+## One model call, no runtime: `Completer`
+
+A host that needs *a completion*, not an agent — a code reviewer asking for a
+JSON verdict, a classifier, an extractor — uses `complete::Completer`. It needs
+no `Runtime`, so none of the one-per-process and worker-stack constraints above
+apply, and any number of calls can run concurrently.
+
+```rust,no_run
+# async fn demo() -> Result<(), openhuman_embed::CoreError> {
+use openhuman_embed::complete::{ChatMessage, CompletionRequest, Completer, ResponseFormat};
+use openhuman_embed::Route;
+
+let completer = Completer::new(Route::openai_compatible("https://openrouter.ai/api/v1", "sk-…"))
+ .header("X-Title", "my-app");
+let response = completer
+ .complete(
+ CompletionRequest::new("openai/gpt-5-mini", vec![ChatMessage::user("Is 7 prime?")])
+ .response_format(ResponseFormat::JsonObject)
+ .max_tokens(64)
+ .provider_options(serde_json::json!({"usage": {"include": true}})),
+ )
+ .await?;
+println!("{:?} {:?} {:?}", response.structured, response.finish_reason, response.usage);
+# Ok(())
+# }
+```
+
+It differs from an agent turn on purpose: no prompt-injection guard (callers
+pass untrusted text *as data*), no tools (a request declaring tools is
+refused), no session or orchestrator prompt, and no model fallback — the
+requested model is sent verbatim and `answered_model` reports what the
+provider says actually ran. `finish_reason`, token usage (cached and reasoning
+included) and the gateway-reported cost come back on the response; a
+`CompletionObserver` sees every call, success or failure, for trace export.
+
+`openhuman_embed::embeddings` re-exports the embedding models (OpenAI, Voyage,
+Cohere, Ollama, mock) for hosts that keep their own vector index, with the
+signature format unchanged so stored vectors stay in their partition.
+
## 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`.