-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(rlm): language-based workflows — Rhai .ragsh REPL as a first-class rlm tool
#4528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
senamakel
merged 7 commits into
tinyhumansai:main
from
senamakel:feat/rlm-language-workflows
Jul 5, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0911fe5
chore(deps): enable tinyagents `repl` feature for RLM workflows
senamakel e3ad178
refactor(tinyagents): expose tool executor, model factory, cancellati…
senamakel a31ca79
feat(rlm): language-workflow domain (Rhai `.ragsh` REPL)
senamakel d62de92
feat(rlm): register `rlm` tool + surface it in prompt/about_app/docs
senamakel b70ac8f
chore(vendor): bump tinyagents submodule to REPL host-embedding branch
senamakel c9d5611
fix: disambiguate `String + &String` after rhai pulls smartstring int…
senamakel 26f145e
style: apply rustfmt to RLM domain and touched files
senamakel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # `rlm` — language-based workflows (Rhai `.ragsh` REPL) | ||
|
|
||
| Exposes TinyAgents' Rhai-backed `.ragsh` session runtime (the `repl` cargo | ||
| feature, `tinyagents::ReplSession`) as a first-class **`rlm` tool** so the | ||
| orchestrator model can author and execute its own workflow scripts — fan-out | ||
| over subagents, batched tool/model calls, loops, dedup/verify pipelines — and | ||
| run them deterministically, in the spirit of Claude Code Workflows and | ||
| Recursive Language Models. | ||
|
|
||
| One orchestrator tool call maps to **one `eval_cell`**: the model writes a Rhai | ||
| cell, the cell runs against a persistent per-session namespace (top-level `let` | ||
| bindings survive into the next cell), and the structured result flows back as | ||
| the tool result. The orchestrator's own turn loop *is* the CodeAct driver loop. | ||
|
|
||
| ## Module shape | ||
|
|
||
| | File | Role | | ||
| | ---- | ---- | | ||
| | `mod.rs` | Exports only (no controller schemas in v1). | | ||
| | `types.rs` | `RlmSessionId`, `RlmEvalRequest`/`RlmEvalResponse`, `RlmLimitsOverride`, `RlmCallSummary`, serde types. | | ||
| | `policy.rs` | Maps openhuman autonomy tier + `tool_timeout` clamps → `tinyagents::ReplPolicy` (fail-closed, bounded). | | ||
| | `bridge.rs` | Builds the `CapabilityRegistry<()>`: openhuman tools (approval-gated, scope-filtered) + provider models + subagents. | | ||
| | `sessions.rs` | `RlmSessionManager`: LRU + idle-TTL bounded map of persistent `ReplSession`s, keyed `<thread>:<session_id>`, one cell at a time. | | ||
| | `ops.rs` | `eval_rlm_cell`: spawn_blocking + outer timeout, cancellation wiring, event forwarding, error → model-consumable result. | | ||
| | `tools.rs` | `RlmTool` (the `rlm` tool: schema, permission, scope, timeout, display). | | ||
|
|
||
| ## Fail-closed guarantees | ||
|
|
||
| Every failure mode returns a **model-consumable tool result** — never a panic, | ||
| never a hung turn: | ||
|
|
||
| - **Layered time bounds:** (1) rhai `on_progress` deadline for pure script | ||
| loops; (2) `bridge_block_on` timer race for hung capability futures; | ||
| (3) an outer `tokio::time::timeout(policy.timeout + 5s)` around | ||
| `spawn_blocking`; (4) the harness `ToolTimeout::Secs` backstop above all of | ||
| them. The tool's own timeout is always set below the harness backstop. | ||
| - **Bounded sessions:** LRU cap (16) + idle TTL (30 min); a second concurrent | ||
| call on a busy session returns a typed "session busy" error rather than | ||
| deadlocking; a poisoned/errored session is dropped, never reused. | ||
| - **Bounded work per session:** `ReplPolicy` caps on operations, output bytes, | ||
| script bytes, and per-kind call counts. `full` tier may raise call-count | ||
| limits up to a hard 2× ceiling via the tool's `limits` arg; `readonly` tier | ||
| does not get the tool at all. | ||
| - **Cancellation end-to-end:** the turn's run-cancellation token drives a | ||
| `ReplCancelFlag` watcher, so a user cancel drops an in-flight cell (script or | ||
| capability call) promptly; the session is left resumable. | ||
|
|
||
| ## Approval & security (bridged tools keep their own gates) | ||
|
|
||
| The RLM bridge restricts callable tools to the parent turn's | ||
| `visible_tool_names`, and **excludes** recursion/duplication hazards: `rlm` | ||
| itself, `spawn_subagent`/`spawn_parallel_agents` (use `agent_query` instead), | ||
| and `run_workflow`/`await_workflow`. `ToolScope::CliRpcOnly` tools are denied. | ||
|
|
||
| Approval gating is **not** on the tinyagents repl bridge path (it lives in the | ||
| harness `wrap_tool` middleware, which the REPL bypasses), so the bridge itself | ||
| invokes `ApprovalGate::intercept_audited` (+ `record_execution`) for any tool | ||
| whose `external_effect_with_args` is true, failing closed on denial. | ||
|
|
||
| ## Capability surface exposed to scripts | ||
|
|
||
| `model_query`, `tool_call`, `agent_query`, their `*_batched` variants, `emit`, | ||
| and `answer`. Graph authoring/execution (`graph_*`) is **out of scope for v1** | ||
| (the REPL's `graph_run` returns a reference, not an execution). | ||
|
|
||
| ## Kill switch & rollout | ||
|
|
||
| The tool is **not registered** when the autonomy tier is `readonly` or when | ||
| `OPENHUMAN_RLM=0`; default-on for `supervised`/`full`. Reverting the | ||
| registration line disables the surface without touching the domain. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prompt teaches the orchestrator to call
rlm, but the orchestrator uses aToolScope::Namedallowlist fromsrc/openhuman/agent_registry/agents/orchestrator/agent.toml, and that list does not includerlm. The session builder filters prompt/provider tools through that non-empty allowlist before applying policy, so in normal chat sessions the model is instructed to use a tool that is not actually advertised or callable; addrlmto the orchestrator's named tools (or otherwise surface it through the scope) with this prompt change.Useful? React with 👍 / 👎.