Skip to content

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

docs(flows): add documentation for tinyflows module

Steven Enamakelba98a18e02dd
diff --git a/crates/openhuman-core/src/flows/tinyflows/README.md b/crates/openhuman-core/src/flows/tinyflows/README.md
index 9aea35336a..6f80bc3426 100644
--- a/crates/openhuman-core/src/flows/tinyflows/README.md
+++ b/crates/openhuman-core/src/flows/tinyflows/README.md
@@ -17,44 +17,54 @@ security model); this README covers only the host seam.
[`caps::open_flow_checkpointer`], the two entry points `flows::ops*.rs`
calls to drive a run; re-exports `tinyflows_sqlite::checkpoint` as
`checkpoint_sqlite` under its historical path.
-- `caps/` — six of the seven capability adapters, plus construction,
- curation, preflight, and invocation logic:
+- `caps/` — every capability adapter except `memory`, plus construction,
+ curation, preflight, and invocation logic. `build_capabilities` also fills
+ `tasks` with the engine's own `TokioTaskRunner` and deliberately leaves
+ `shell` and `approvals` as `None` (no host shell adapter yet; approvals
+ reuse the engine's pause/`flows_resume` fallback).
- `ops.rs` — `build_capabilities` (assembles the `Capabilities` bundle for
one run), `open_flow_checkpointer` (opens the durable SQLite checkpointer
at `<workspace_dir>/flows/checkpoints.db`), Composio curation/preflight
(`is_curated_flow_tool`, `preflight_composio_args`), and the
`OpenHumanTools` / `PreflightToolInvoker` tool-call adapters.
- - `agent.rs` — `AgentRunner`: runs an `agent` node as a nested harness
- invocation, resolving `agent_ref` and scaling the per-attempt timeout
- against the iteration cap.
- - `llm.rs` — `LlmProvider` over OpenHuman's inference stack; what an
- `agent` node falls back to without an agent runner, and what a raw
- completion node uses directly.
+ - `agent.rs` — `OpenHumanAgentRunner` (`AgentRunner`): resolves an `agent`
+ node's trusted `agent_ref` and routes it to a full harness turn
+ (`Agent::run_single`, a nested tinyagents graph) when a harness
+ `AgentDefinition` exists, or to a persona-shaped `OpenHumanLlm::complete`
+ when only a custom registry entry does. Also owns the timeout clamp and
+ its scaling against the definition's iteration cap.
+ - `llm.rs` — `OpenHumanLlm` (`LlmProvider`) over OpenHuman's inference
+ stack; what an `agent` node falls back to without an agent runner, and
+ what a raw completion node uses directly.
- `prompt.rs` — message assembly, the `input_context` carrier and its size
cap, and tolerant JSON extraction for structured-output nodes.
- - `http.rs` — `HttpClient`; inherits the allowlist/DNS-rebind protection of
- the underlying `HttpRequestTool` and adds `http_cred:<name>` credential
- resolution, injected server-side after the approval gate computes its
- redacted summary.
- - `code.rs` — `CodeRunner`; runs JS/Python in the sandbox under a
- wall-clock timeout.
- - `state.rs` — `StateStore` over `flows::{kv_get,kv_set}`, namespaced per
- flow so saved flows never collide on a state key.
- - `resolver.rs` — `WorkflowResolver`; resolves a `sub_workflow` node's id to
- a stored workflow (the engine only knows the id).
- - `tier.rs` — the autonomy-tier and approval gate every acting node
- (tool call, HTTP request, code run) passes through first.
+ - `http.rs` — `OpenHumanHttp` (`HttpClient`); inherits the allowlist and
+ DNS-rebind protection of the underlying `HttpRequestTool` and adds
+ `http_cred:<name>` credential resolution, injected after the approval
+ gate computes its redacted summary so the secret never reaches the UI,
+ graph, output, or logs.
+ - `code.rs` — `OpenHumanCode` (`CodeRunner`); runs JS/Python through
+ `sandbox::execute_in_sandbox` under `CODE_RUN_TIMEOUT_SECS`.
+ - `state.rs` — `FlowStateStore` (`StateStore`) over
+ `flows::{kv_get,kv_set}`, namespaced per flow (`"flow:<id>"`) so saved
+ flows never collide on a state key.
+ - `resolver.rs` — `OpenHumanWorkflowResolver` (`WorkflowResolver`);
+ resolves a `sub_workflow` node's id to a stored workflow.
+ - `tier.rs` — `enforce_node_tier_gate` / `gate_call_for_tier`: the
+ autonomy-tier and approval gate every acting node (tool call, HTTP
+ request, code run, memory read/write) passes through first.
- `tools/` — `tool_call` node dispatch, split by slug namespace:
`native.rs` for the `oh:` prefix (native OpenHuman tools, same registry
the assistant uses), `composio.rs` for everything else (Composio
actions; must stay the catch-all backend since Composio slugs carry no
prefix).
- `memory_adapter.rs` — `OpenHumanMemory`, the `MemoryProvider` adapter for
- the `memory` node. Lives outside `caps/` per the repo's ~500-line
- file-size convention (`caps/ops.rs` is already large). Routes every
- operation through the same tier-gate pair as the other acting adapters
- (`Read` for `recall`/`search`/`flavour`/`people`, `Write` for
- `remember`/`forget`).
+ the `memory` node. Routes every operation through the same `tier.rs` gate
+ pair as the other acting adapters (`CommandClass::Read` for
+ `recall`/`search`/`flavour`/`people`, `CommandClass::Write` for
+ `remember`/`forget`); `remember`/`forget` hard-refuse any scope other than
+ `"flow"`, and `scope: "flow"` shares the `flow_namespace` the
+ `flow_memory_*` agent tools use.
- `observability.rs` — `tinyflows::observability::RunObserver` impls:
`TracingRunObserver` (log-only) and `FlowRunObserver`, which persists live
steps via `flows::upsert_flow_run_step` and publishes
@@ -66,14 +76,18 @@ security model); this README covers only the host seam.
## Security model
-Every capability adapter that reaches outside the process goes through two
-independent layers before it acts: `tier.rs`'s autonomy-tier/approval gate,
-and (for Composio) `caps/ops.rs`'s deny-by-default curation check, which is
-intentionally stricter than the normal agent tool-call loop's curation
-because a flow author's `tool_call.slug` is free-form and never round-trips
-through live tool discovery first. See
-[flows-on-tinyagents.md § The security model: two gates](../../../../../gitbooks/developing/architecture/flows-on-tinyagents.md#the-security-model-two-gates)
-for the full contract.
+The contract is spelled out in
+[flows-on-tinyagents.md § The security model: two gates](../../../../../gitbooks/developing/architecture/flows-on-tinyagents.md#the-security-model-two-gates);
+this module holds the outer gate. `tier.rs` consults the user's autonomy
+tier for each acting node's `CommandClass` and forces an `ApprovalGate`
+round-trip on `Prompt`, even when the saved flow's own `require_approval` is
+false. Composio `tool_call` nodes additionally pass `caps/ops.rs`'s
+deny-by-default curation check (`is_curated_flow_tool`), stricter than the
+agent loop's because a flow author's slug is free-form and never round-trips
+through live tool discovery; `tools/composio.rs` documents why the tier gate
+must run before curation. The inner gate (the agent definition's `ToolScope`
+and sandbox) applies to the nested harness turn `agent.rs` starts, with no
+new origin wrapper.
## Used by
@@ -83,9 +97,12 @@ for the full contract.
## Tests
-`tinyflows_tests.rs` (capability-seam smoke tests against the real engine),
-`checkpoint_compat_tests.rs` (SQLite checkpoint schema/format compatibility),
-`memory_node_e2e_tests.rs` (end-to-end `memory` node coverage through the
-real engine, adapter, and store — kept separate from `tinyflows_tests.rs`
-because it exercises a real store rather than doubles), plus a
-`*_tests.rs`/`#[cfg(test)] mod tests` file alongside most modules above.
+`tinyflows_tests.rs` (capability-seam smoke tests against the real engine;
+note the real `HttpRequestTool` blocks loopback, so HTTP coverage asserts the
+SSRF/allowlist rejections rather than a mock round-trip),
+`checkpoint_compat_tests.rs` (proves the `tinyflows-sqlite` checkpoint store
+stays byte-compatible with the `tinyagents` backend it was ported from),
+`memory_node_e2e_tests.rs` (the `memory` node through the real engine,
+adapter, and on-disk store — kept apart from `tinyflows_tests.rs` because the
+unit tests only exercise error paths against an empty workspace), plus a
+`<module>_tests.rs` file beside most modules above.
diff --git a/crates/openhuman-core/src/flows/tinyflows/mod.rs b/crates/openhuman-core/src/flows/tinyflows/mod.rs
index 439d55f943..f9ce9cfcbc 100644
--- a/crates/openhuman-core/src/flows/tinyflows/mod.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/mod.rs
@@ -2,12 +2,12 @@
//! (an external, host-agnostic crate — validate → compile → run on its own
//! in-crate state-graph runtime) to real OpenHuman services.
//!
-//! This module is export-focused. Six of the seven capability adapters plus
-//! the two run entry points — [`build_capabilities`] and
+//! This module is export-focused. Every capability adapter except `memory`,
+//! plus the two run entry points — [`build_capabilities`] and
//! [`open_flow_checkpointer`], re-exported below — live in [`caps`]; the
//! `memory` node's `MemoryProvider` adapter (`OpenHumanMemory`) lives in its
//! own [`memory_adapter`] module, per this repo's ~500-line file-size
-//! convention (`caps.rs` is already large); the durable SQLite checkpoint
+//! convention (`caps/` is already large); the durable SQLite checkpoint
//! backend lives in `tinyflows_sqlite::checkpoint`; run observability logging lives
//! in [`observability`]; post-run Langfuse export of a run's durable graph
//! observations lives in [`langfuse_export`]. The `flows::` domain
diff --git a/gitbooks/developing/architecture/flows-on-tinyagents.md b/gitbooks/developing/architecture/flows-on-tinyagents.md
index c797076c76..8a62735773 100644
--- a/gitbooks/developing/architecture/flows-on-tinyagents.md
+++ b/gitbooks/developing/architecture/flows-on-tinyagents.md
@@ -36,12 +36,12 @@ is the first downstream host and injects everything real through the seam.
## The run pipeline
-A flow is a [`WorkflowGraph`](../../../vendor/tinyflows/src/model/) - a directed
+A flow is a [`WorkflowGraph`](../../../vendor/tinyflows/crates/tinyflows/src/model/) - a directed
graph of typed [`Node`]s joined by [`Edge`]s, JSON on the wire. Running it is a
fixed four-stage pipeline
-([`vendor/tinyflows/src/lib.rs`](../../../vendor/tinyflows/src/lib.rs),
-[`compiler.rs`](../../../vendor/tinyflows/src/compiler.rs),
-[`engine.rs`](../../../vendor/tinyflows/src/engine.rs)):
+([`vendor/tinyflows/crates/tinyflows/src/lib.rs`](../../../vendor/tinyflows/crates/tinyflows/src/lib.rs),
+[`compiler.rs`](../../../vendor/tinyflows/crates/tinyflows/src/compiler.rs),
+[`engine.rs`](../../../vendor/tinyflows/crates/tinyflows/src/engine.rs)):
```mermaid
flowchart LR
@@ -56,18 +56,18 @@ flowchart LR
seam["openhuman::flows::tinyflows<br/>capability seam"] -. host-injected .-> run
```
-1. **validate** ([`validate.rs`](../../../vendor/tinyflows/src/validate.rs)) -
+1. **validate** ([`validate.rs`](../../../vendor/tinyflows/crates/tinyflows/src/validate.rs)) -
structural checks over the raw graph: unique node ids, that every referenced
node exists, and **exactly one trigger node** (0 → `MissingTrigger`, >1 →
`MultipleTriggers`). This is the single-trigger invariant the whole model
rests on (see [Trigger model](#the-trigger-model)).
-2. **compile** ([`compiler.rs`](../../../vendor/tinyflows/src/compiler.rs)) - runs
+2. **compile** ([`compiler.rs`](../../../vendor/tinyflows/crates/tinyflows/src/compiler.rs)) - runs
validation, then lowers the validated graph onto a fresh `tinyagents` state
graph. **Every tinyflows node becomes a tinyagents graph node**; every
tinyflows edge becomes a graph edge, with conditional/parallel routing and a
merge barrier expressed on the tinyagents graph layer. The graph is rebuilt
per run so compilation stays independent of any host state.
-3. **run** ([`engine.rs`](../../../vendor/tinyflows/src/engine.rs)) - the host
+3. **run** ([`engine.rs`](../../../vendor/tinyflows/crates/tinyflows/src/engine.rs)) - the host
calls `engine::run_with_checkpointer_journaled_observed`
([`flows/ops.rs`](../../../crates/openhuman-core/src/flows/ops.rs), `flows_run`), which
drives the compiled graph to completion, folding each node's output into the
@@ -86,7 +86,7 @@ host at `<workspace_dir>/flows/checkpoints.db`
## Run state: one JSON map, a merge reducer, and the `{json,text,raw}` envelope
The entire run's working memory is a single `serde_json::Value` laid out as
-([`vendor/tinyflows/src/engine.rs`](../../../vendor/tinyflows/src/engine.rs)):
+([`vendor/tinyflows/crates/tinyflows/src/engine.rs`](../../../vendor/tinyflows/crates/tinyflows/src/engine.rs)):
```json
{
@@ -128,7 +128,7 @@ never see the raw completion shape - they bind against the envelope:
### The `=`-expression scope
Node config is resolved through jq/jaq `=`-expressions
-([`vendor/tinyflows/src/expr.rs`](../../../vendor/tinyflows/src/expr.rs)) against a
+([`vendor/tinyflows/crates/tinyflows/src/expr.rs`](../../../vendor/tinyflows/crates/tinyflows/src/expr.rs)) against a
per-node **scope** with four bindings:
| Binding | What it holds |
@@ -149,7 +149,7 @@ panicking - node wiring never crashes the run.
`tinyflows` touches nothing real on its own. Everything - LLM calls, tools, HTTP,
code, persistence, sub-workflow lookup - is a **capability trait** the host
-implements ([`vendor/tinyflows/src/caps/mod.rs`](../../../vendor/tinyflows/src/caps/mod.rs)).
+implements ([`vendor/tinyflows/crates/tinyflows/src/caps/mod.rs`](../../../vendor/tinyflows/crates/tinyflows/src/caps/mod.rs)).
`openhuman::flows::tinyflows::caps` supplies one adapter per trait, assembled into a
`Capabilities` bundle per run by `build_capabilities`
([`caps/`](../../../crates/openhuman-core/src/flows/tinyflows/caps/mod.rs)):
@@ -163,11 +163,15 @@ implements ([`vendor/tinyflows/src/caps/mod.rs`](../../../vendor/tinyflows/src/c
| `CodeRunner` | `code` | `OpenHumanCode` | the sandbox (`execute_in_sandbox`) |
| `StateStore` | resumable/stateful runs | `FlowStateStore` | the `flow_state` KV table |
| `WorkflowResolver` | `sub_workflow` by id | `OpenHumanWorkflowResolver` | the saved-flow store (`load_flow_graph`) |
+| `MemoryProvider` | `memory` | `OpenHumanMemory` | the memory store (`tinyflows/memory_adapter.rs`) |
`AgentRunner` is **optional** in the crate (`Capabilities::agent` is
`Option`): a host without an agent registry leaves it `None` and `agent` nodes
fall back to a bare `LlmProvider` completion. OpenHuman always wires it, so
-`agent` nodes get the real agent runtime described next.
+`agent` nodes get the real agent runtime described next. Of the remaining
+optional slots, `tasks` takes the crate's own `TokioTaskRunner`, while `shell`
+and `approvals` are left `None`: there is no host shell adapter yet, and
+approvals reuse the engine's pause-and-`flows_resume` fallback.
## Agent nodes: a graph within the graph
@@ -220,7 +224,7 @@ output**, so a prompt-injected upstream completion cannot pick an arbitrary agen
kind. The **builder's dry-run** exercises this path too:
`dry_run_workflow` compiles a draft and runs it against `tinyflows`' _mock_
capabilities wired with a `MockAgentRunner`
-([`vendor/tinyflows/src/caps/mock.rs`](../../../vendor/tinyflows/src/caps/mock.rs)),
+([`vendor/tinyflows/crates/tinyflows/src/caps/mock.rs`](../../../vendor/tinyflows/crates/tinyflows/src/caps/mock.rs)),
so a draft whose `agent` nodes carry an `agent_ref` is self-tested end-to-end
before it is ever saved.
@@ -268,7 +272,7 @@ approval checks) but never _which agent kind or tool identity_ runs.
## The trigger model
`tinyflows` enforces **exactly one trigger node per graph** at validate time
-([`validate.rs`](../../../vendor/tinyflows/src/validate.rs)). A workflow therefore
+([`validate.rs`](../../../vendor/tinyflows/crates/tinyflows/src/validate.rs)). A workflow therefore
has a single entry point, and the trigger's payload is what seeds `run.trigger`
in the run state.
@@ -341,8 +345,8 @@ sequenceDiagram
| Path | What lives there |
| --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
-| [`vendor/tinyflows/src/`](../../../vendor/tinyflows/src/) | The engine: `model/`, `validate.rs`, `compiler.rs`, `engine.rs`, `expr.rs`, `caps/`, `nodes/`. |
-| [`vendor/tinyflows/src/caps/mod.rs`](../../../vendor/tinyflows/src/caps/mod.rs) | The seven capability traits + `Capabilities` bundle. |
+| [`vendor/tinyflows/crates/tinyflows/src/`](../../../vendor/tinyflows/crates/tinyflows/src/) | The engine: `model/`, `validate.rs`, `compiler.rs`, `engine.rs`, `expr.rs`, `caps/`, `nodes/`. |
+| [`vendor/tinyflows/crates/tinyflows/src/caps/mod.rs`](../../../vendor/tinyflows/crates/tinyflows/src/caps/mod.rs) | The capability traits + `Capabilities` bundle. |
| [`crates/openhuman-core/src/flows/tinyflows/caps/`](../../../crates/openhuman-core/src/flows/tinyflows/caps/mod.rs) | The host adapters, `build_capabilities`, `open_flow_checkpointer`, the two-layer gate helpers. |
| [`crates/openhuman-core/src/flows/ops.rs`](../../../crates/openhuman-core/src/flows/ops.rs) | `flows_run` / `flows_resume` / `flows_build` / `flows_discover` and CRUD. |
| [`crates/openhuman-core/src/flows/bus.rs`](../../../crates/openhuman-core/src/flows/bus.rs) | `FlowTriggerSubscriber` - the host-side multi-trigger bridge. |