Skip to content

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

docs(agent): add README for subagent host and API key documentation

Steven Enamakeld8c7af30b585
diff --git a/crates/openhuman-core/src/agent/subagent_host/README.md b/crates/openhuman-core/src/agent/subagent_host/README.md
new file mode 100644
index 0000000000..7422aebe6d
--- /dev/null
+++ b/crates/openhuman-core/src/agent/subagent_host/README.md
@@ -0,0 +1,54 @@
+# Subagent host
+
+OpenHuman adapters over the neutral TinyAgents sub-agent lifecycle. Given an
+`AgentDefinition` and a task prompt, the runner reads the parent's task-local
+`ParentExecutionContext`, resolves the child's model, filters the parent's
+tool registry per the definition's `tools`, `disallowed_tools`, and
+`skill_filter` (or inherits the parent's tools verbatim in fork mode), builds
+a narrowed system prompt, runs the child turn on the TinyAgents harness, and
+mirrors its transcript and progress back to the parent as one compact tool
+result.
+
+This module owns product policy and effects: definition resolution, prompt
+assembly, tool narrowing, model selection, workspace and sandbox setup,
+artifacts, checkpoints, and progress. `tinyagents_orchestration::subagent`
+owns lifecycle ordering, task-key coalescing, and mutually exclusive pause or
+terminal persistence; this crate does not duplicate that state machine.
+
+## Layout
+
+| File | Role |
+| --- | --- |
+| `types.rs` | `SubagentRunOptions`, `SubagentRunOutcome`, `SubagentRunError`, `SubagentMode`, `SubagentCheckpointData`, `SubagentUsage` |
+| `ops/` | `run_subagent`, the typed and fork execution modes, and the TinyAgents graph route |
+| `lifecycle.rs` | `run_subagent`, `run_subagent_with_parent`, `continue_subagent`, checkpoint load/save, `OpenHumanSubagentHost` |
+| `handoff.rs` | Oversized tool-result cache and hygiene, shared with `extract_tool.rs` |
+| `extract_tool.rs` | The `extract_from_result` tool for direct provider extraction over a cached handoff |
+| `tool_prep.rs` | Tool filtering, prompt loading, and the text-mode protocol block |
+| `autonomous.rs` | Iteration-cap policy for autonomous (non-interactive) sub-agent runs |
+
+`SubagentRunOptions::run_context` carries the child's `OpenHumanRunContext`
+explicitly; recursive execution passes this value rather than snapshotting
+task-local scopes after a `tokio::spawn`, since task-local state does not
+survive that boundary on its own.
+
+## Handoff
+
+A sub-agent's tool result can be large enough that returning it verbatim
+would blow the parent's context. `HandoffMiddleware` (in TinyAgents)
+intercepts an oversized result through `apply_handoff` and stores it in a
+per-spawn `ResultHandoffCache`; the parent gets a small reference back, and
+`extract_from_result` lets a later turn pull a specific piece of the cached
+result out on demand instead of resending the whole thing.
+
+## Where next
+
+- `crate::agent::harness::definition` for `AgentDefinition`, `AgentTier`,
+ `SandboxMode`, and the other archetype shapes this module resolves against.
+- `crate::agent::orchestration` for `spawn_subagent` and the other
+ user-facing tools that call into this runner.
+- `crate::agent::session_host` for the parent turn that sets up the
+ `ParentExecutionContext` a sub-agent reads.
+- `vendor/tinyagents` (`tinyagents-orchestration::subagent`,
+ `tinyagents-graph`) for the lifecycle and delegation-graph mechanics this
+ module adapts rather than reimplements.
diff --git a/gitbooks/developing/tinyhumans-api-key.md b/gitbooks/developing/tinyhumans-api-key.md
new file mode 100644
index 0000000000..8fd09d311d
--- /dev/null
+++ b/gitbooks/developing/tinyhumans-api-key.md
@@ -0,0 +1,70 @@
+# One TinyHumans API key
+
+One TinyHumans credential unlocks every managed backend surface: chat
+inference over the OpenRouter model catalogue, web search, embeddings, media
+generation, integrations, voice, and the Jev ranker. There's no separate key
+per service. The desktop app gets this credential through sign-in; a library
+host or a headless process supplies it directly.
+
+## How to get one
+
+Managed inference, search, and the rest of the backend surface all sit behind
+one TinyHumans account. Sign in through the desktop app to get a session
+credential, or generate an API key (`th_...`) for library and headless use.
+
+## Using it
+
+**Desktop app**: sign in with a TinyHumans account. The app stores a session
+credential in the OS-backed auth-profile store and the core resolves it the
+same way it resolves an API key, through `security::credentials::api_key` and
+`session_support::resolve_backend_credential`.
+
+**Library**: pass the key to `RuntimeBuilder` and it boots connected:
+
+```rust
+use openhuman_tinyhumans::{embed::Workspace, RuntimeBuilder};
+
+let runtime = RuntimeBuilder::new()
+ .workspace(Workspace::Ephemeral)
+ .api_key("th_...")
+ .build()
+ .await?;
+```
+
+`openhuman_tinyhumans::RuntimeBuilder` mirrors `openhuman_embed::RuntimeBuilder`
+method for method, then installs the SDK-backed transport and binds it to the
+runtime on `build()`.
+
+**Headless**: set `OPENHUMAN_BACKEND_API_KEY` before the core boots. The boot
+sequence (`crates/openhuman-core/src/security/credentials/ops/boot_env.rs`)
+installs it on a fresh credential store and never overwrites one that's
+already there.
+
+## Where it's stored and how it's sent
+
+The key lives in the same auth-profile store as an app session, under its own
+provider id (`api-key`), never in `config.toml` and never logged. It's the
+only credential a library embedder holds: no login-token exchange, no session
+JWT, no `/auth/me` round trip.
+
+Two wire forms, chosen by endpoint:
+
+- **Managed inference** (`{api_url}/openai/v1`): `Authorization: Bearer
+ <key>`. `OpenHumanBackendModel::resolve_bearer` prefers the stored API key
+ over an app session when both exist.
+- **Backend REST** (`BackendOAuthClient`, `IntegrationClient`):
+ `x-api-key: <key>`.
+
+`crates/openhuman-core/src/security/credentials/api_key.rs` owns storage and
+retrieval (`store_api_key`, `get_api_key`, `has_api_key`, `clear_api_key`);
+`session_support::BackendCredential` is what resolves either credential form
+into the right header at request time.
+
+## BYOK stays available
+
+The API key covers the managed path. Every workload can still be pointed at
+your own provider instead, chat and reasoning at a BYOK LLM slug, embeddings
+at Voyage or OpenAI or Cohere directly, search at Brave or Exa or Tavily
+directly. See [Pluggable engines](engines.md) for the full list and the
+config key for each. Running everything BYOK does not require a TinyHumans
+key at all; running anything through the managed backend does.