nexo_ai 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +81 -0
- data/README.md +13 -15
- data/docs/concurrency.md +1 -2
- data/docs/durable-workflows.md +3 -1
- data/docs/loops.md +67 -95
- data/docs/mcp.md +57 -51
- data/docs/sessions.md +7 -3
- data/docs/skills.md +20 -11
- data/examples/mcp_filesystem.rb +1 -1
- data/lib/nexo/agent.rb +24 -46
- data/lib/nexo/concurrent.rb +1 -1
- data/lib/nexo/loop.rb +7 -9
- data/lib/nexo/loops/ruby_llm.rb +41 -32
- data/lib/nexo/mcp/gated_tool.rb +29 -25
- data/lib/nexo/mcp.rb +71 -66
- data/lib/nexo/permissions.rb +1 -3
- data/lib/nexo/skills/skill.rb +89 -0
- data/lib/nexo/skills.rb +14 -41
- data/lib/nexo/tools/fetch.rb +1 -1
- data/lib/nexo/tools/glob.rb +1 -1
- data/lib/nexo/tools/read_file.rb +1 -1
- data/lib/nexo/tools/shell.rb +1 -1
- data/lib/nexo/tools/web_search.rb +1 -1
- data/lib/nexo/tools/write_file.rb +2 -2
- data/lib/nexo/version.rb +1 -1
- data/lib/nexo/workflow.rb +10 -5
- data/lib/nexo.rb +2 -4
- data/sig/nexo/agent.rbs +1 -1
- metadata +4 -32
- data/lib/nexo/loops/agent_sdk.rb +0 -68
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3ab3bc27263cfb9d2adc054a4579f983f8fa10ac2c94586116f3e6793d3d93b9
|
|
4
|
+
data.tar.gz: e967f788db7fce3e9205199b7cbe8628a60d5678e9daa0db8802852d6e87b7bf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 97a086e9d89990c89c0be4d9ba03de89ac2c77aa6e6d5fcd5086179c9d5c55845f2b08543984ea67b77eafa4b6e085e2c2d60d2d9c25020a80853c81bfab61bd
|
|
7
|
+
data.tar.gz: 57b9cf4b4ab598badaad5cc59fa57b691ca3c4f8c88caa927ed3ef9bf9637587a029db2037ae04ac97b7e17341a41ac4c5a0435edbfe9d13f00d135b92efb375
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,86 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.13.0] - 2026-11-26
|
|
4
|
+
|
|
5
|
+
Nexo now runs on ruby_llm 2.2. MCP comes from ruby_llm itself, skills need no extra gem,
|
|
6
|
+
and `max_turns` is a real cap.
|
|
7
|
+
|
|
8
|
+
### Changed
|
|
9
|
+
|
|
10
|
+
- **`ruby_llm` is now pinned to the 2.2 line (`~> 2.2.0`, was `~> 1.16`).** Verified against
|
|
11
|
+
2.2.3. ruby_llm 1.x is no longer supported; it ended at 1.16.0 and carries ReDoS
|
|
12
|
+
advisories that are fixed only in 2.0.
|
|
13
|
+
|
|
14
|
+
**Upgrading:** this is a breaking release for the host app's Gemfile and for any
|
|
15
|
+
`RubyLLM::Tool` you wrote yourself.
|
|
16
|
+
|
|
17
|
+
1. Remove `gem "ruby_llm-mcp"` and `gem "ruby_llm-skills"`. `ruby_llm-mcp` defines the
|
|
18
|
+
same `RubyLLM::MCP` constant as ruby_llm 2.x and cannot be bundled with it; both gems
|
|
19
|
+
pin ruby_llm 1.x. Anything you were getting from them transitively (for example
|
|
20
|
+
`bigdecimal`) must now be declared by you.
|
|
21
|
+
2. In your own tools, rename `param` to `parameter` and `desc:` to `description:`
|
|
22
|
+
(`params do` becomes `parameters do`). ruby_llm 2.0 removed the old names.
|
|
23
|
+
3. A tool wrapper you wrote (for `wrap_mcp_tool`) must accept keywords:
|
|
24
|
+
`def call(**arguments)`. ruby_llm 2.x calls tools as `tool.call(**arguments)`, and the
|
|
25
|
+
schema reader is `parameters_schema`, not `params_schema`.
|
|
26
|
+
4. If you use `Nexo::Session` on ActiveRecord, run ruby_llm's own schema upgrade
|
|
27
|
+
(`rails g ruby_llm:upgrade`, one minor at a time). ruby_llm 2.x keeps tool calls and
|
|
28
|
+
the model registry in its own `ruby_llm_*` tables; the host owns only `Chat` and
|
|
29
|
+
`Message`.
|
|
30
|
+
5. Read ruby_llm's [upgrade guide](https://rubyllm.com/upgrading/) for everything outside
|
|
31
|
+
Nexo — notably that OpenAI now defaults to the Responses API.
|
|
32
|
+
|
|
33
|
+
- **`max_turns` is a hard cap.** `Agent#prompt`, `Session#prompt` and
|
|
34
|
+
`Workflow#run_agent` pass it to ruby_llm as `with_tool_options(rounds:)`. When a prompt
|
|
35
|
+
uses up its tool rounds, `RubyLLM::ToolRoundLimitError` is raised instead of the model
|
|
36
|
+
being asked again; inside a workflow that fails the run. It was telemetry only before.
|
|
37
|
+
|
|
38
|
+
**Upgrading:** a run that used to pass `max_turns` and keep going now stops. Raise the
|
|
39
|
+
number for runs that legitimately need more rounds, or pass `max_turns: nil` to run
|
|
40
|
+
uncapped. The `:turn_limit_exceeded` event is still emitted, once per prompt.
|
|
41
|
+
|
|
42
|
+
- **MCP uses ruby_llm's built-in client.** The `mcp` macro, `mcp_allow`, the fail-closed
|
|
43
|
+
gate, `wrap_mcp_tool` and `Nexo::MCP.build` are unchanged for callers. Three behaviours
|
|
44
|
+
differ, all inherited from ruby_llm:
|
|
45
|
+
- a callable `token:` is read again for **every request**, so a rotated token no longer
|
|
46
|
+
needs `agent.close` and a reconnect;
|
|
47
|
+
- a `:stdio` server starts with a short, safe environment — pass what it needs with
|
|
48
|
+
`env:`;
|
|
49
|
+
- a `:stdio` server's stderr is your process's stderr.
|
|
50
|
+
|
|
51
|
+
An unknown transport or a `:stdio` server with no `command:` now raises
|
|
52
|
+
`Nexo::ConfigurationError` when the server is built.
|
|
53
|
+
|
|
54
|
+
- **Skills are read by Nexo itself** (`Nexo::Skills::Skill`). `skills`, `Nexo::Skills.find`
|
|
55
|
+
and `Nexo::Skills.materialize` are unchanged. A `SKILL.md` without YAML front matter now
|
|
56
|
+
raises `Nexo::Error` naming the file. ruby_llm's own skills are not used: they reject
|
|
57
|
+
underscore names (`email_triage`) and work through a `load_skill` tool, where Nexo's rule
|
|
58
|
+
is that a skill adds instructions and nothing else.
|
|
59
|
+
|
|
60
|
+
- **Workflow events store tool arguments string-keyed** in both run stores. ruby_llm 2.x
|
|
61
|
+
hands them over with Symbol keys; the Memory store would otherwise have disagreed with
|
|
62
|
+
the ActiveRecord one.
|
|
63
|
+
|
|
64
|
+
### Removed
|
|
65
|
+
|
|
66
|
+
- **`Nexo::Loops::AgentSDK`**, with `Agent#permission_mode`, `Agent#allowed_tools`,
|
|
67
|
+
`Agent::ALLOWED_TOOLS` and `Agent::PERMISSION_MODE_MAP`. The `ruby_llm-agent_sdk` gem it
|
|
68
|
+
wrapped was never published, so this path never ran against real code. Its one purpose,
|
|
69
|
+
a hard turn cap, is now `max_turns` on the default loop. `Nexo::Loop` remains as the seam
|
|
70
|
+
for a backend of your own.
|
|
71
|
+
- **`Nexo::MCP.load!` and `Nexo::Skills.load!`.** There is no optional gem left to load.
|
|
72
|
+
- The `ruby_llm-test`, `ruby_llm-skills` and `ruby_llm-mcp` development dependencies. The
|
|
73
|
+
suite scripts model replies with ruby_llm's own `RubyLLM::TestHelper`.
|
|
74
|
+
|
|
75
|
+
### Added
|
|
76
|
+
|
|
77
|
+
- `test/real_loop_test.rb` drives ruby_llm's real conversation loop with scripted replies
|
|
78
|
+
and proves, end to end: a `:read_only` agent cannot reach the write tool, the MCP gate
|
|
79
|
+
denies a tool before it runs, `max_turns` stops a runaway loop, and an `:approve` gate
|
|
80
|
+
suspends a workflow and resumes it.
|
|
81
|
+
- `mcp` accepts `env:` and `directory:` for `:stdio` servers, and `command:` as an argv
|
|
82
|
+
Array.
|
|
83
|
+
|
|
3
84
|
## [0.12.0] - 2026-09-12
|
|
4
85
|
|
|
5
86
|
The gem now says exactly which ruby_llm it supports, and its API docs are written in Markdown.
|
data/README.md
CHANGED
|
@@ -9,10 +9,10 @@ build a working agent in five lines without wiring anything.
|
|
|
9
9
|
|
|
10
10
|
## Compose, don't reimplement
|
|
11
11
|
|
|
12
|
-
Nexo does not rebuild
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
Nexo does not rebuild the tool-call loop, the MCP client, tool approval plumbing, or
|
|
13
|
+
structured output — those live in [`ruby_llm`](https://github.com/crmne/ruby_llm) itself.
|
|
14
|
+
Nexo **composes** them behind one front door and adds only the two pieces `ruby_llm`
|
|
15
|
+
leaves to the application:
|
|
16
16
|
|
|
17
17
|
- **Sandbox + Permissions seam** — pluggable execution environment (virtual / local /
|
|
18
18
|
remote) with explicit authorization gating. Default: `:virtual` + `:read_only`.
|
|
@@ -81,7 +81,7 @@ access until you explicitly opt in.
|
|
|
81
81
|
| [Sandboxes](docs/sandboxes.md) | Virtual / Local / Remote / Container + hardened defaults |
|
|
82
82
|
| [Permissions](docs/permissions.md) | modes, the gate, MCP gate, :ask |
|
|
83
83
|
| [Tools](docs/tools.md) | ReadFile / WriteFile / Shell / Glob |
|
|
84
|
-
| [
|
|
84
|
+
| [The loop](docs/loops.md) | the default loop, `max_turns` as a hard cap |
|
|
85
85
|
| [Workflows](docs/workflows.md) | lifecycle, staging, artifacts, run_agent |
|
|
86
86
|
| [Durable workflows](docs/durable-workflows.md) | checkpoint / suspend / resume |
|
|
87
87
|
| [Skills](docs/skills.md) | SKILL.md packages, gated tools |
|
|
@@ -94,16 +94,14 @@ access until you explicitly opt in.
|
|
|
94
94
|
## Requirements
|
|
95
95
|
|
|
96
96
|
- Ruby 3.3+
|
|
97
|
-
- [ruby_llm](https://github.com/crmne/ruby_llm)
|
|
98
|
-
**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
(see [Loops](docs/loops.md)); until it ships, `Loops::AgentSDK` raises a clear
|
|
106
|
-
`Nexo::MissingDependencyError`.
|
|
97
|
+
- [ruby_llm](https://github.com/crmne/ruby_llm) 2.2.x (`~> 2.2.0`) — verified against
|
|
98
|
+
**2.2.3**. It is the only runtime dependency besides `zeitwerk`: MCP and the test helper
|
|
99
|
+
ship with it, and Nexo reads `SKILL.md` packages itself.
|
|
100
|
+
|
|
101
|
+
Coming from `nexo_ai` 0.12 (on `ruby_llm` 1.16)? Remove `ruby_llm-mcp` and
|
|
102
|
+
`ruby_llm-skills` from your Gemfile — `ruby_llm-mcp` defines the same `RubyLLM::MCP`
|
|
103
|
+
constant as `ruby_llm` 2.x and cannot be bundled alongside it — and read the 0.13.0
|
|
104
|
+
entry in the [changelog](CHANGELOG.md).
|
|
107
105
|
|
|
108
106
|
## Status
|
|
109
107
|
|
data/docs/concurrency.md
CHANGED
|
@@ -114,8 +114,7 @@ Nexo.configure { |c| c.tool_concurrency = :fibers } # :fibers | :threads | fal
|
|
|
114
114
|
- `nil` (**default**) — leave RubyLLM's own setting alone, so behaviour is unchanged
|
|
115
115
|
until you opt in.
|
|
116
116
|
|
|
117
|
-
It is applied to the chat
|
|
118
|
-
resets the chat's concurrency.
|
|
117
|
+
It is applied to the chat with `with_tool_options(concurrency:)`.
|
|
119
118
|
|
|
120
119
|
This only matters when a model returns several tool calls in one turn. Tools that batch
|
|
121
120
|
their own work — one call that reads twenty messages rather than twenty calls — make it
|
data/docs/durable-workflows.md
CHANGED
|
@@ -183,7 +183,9 @@ resumed.status # => "done" (the gate allowed the
|
|
|
183
183
|
- **Cross-process approval needs the ActiveRecord store + ActiveJob** (like all durable resume).
|
|
184
184
|
In-process `resume` works with the Memory store; a Memory run does not survive the process.
|
|
185
185
|
- **Branch depends on upstream `ruby_llm`.** This works because `ruby_llm`'s tool loop lets a
|
|
186
|
-
tool `execute` exception propagate out of `chat.ask` (verified
|
|
186
|
+
tool `execute` exception propagate out of `chat.ask` (verified on 2.2.3 through the real
|
|
187
|
+
loop, `test/real_loop_test.rb`). A host that registers a catch-all
|
|
188
|
+
`RubyLLM::Tool.rescue_from StandardError` would swallow the approval signal. If a future
|
|
187
189
|
`ruby_llm` swallows tool exceptions, tool-triggered approval would be constrained — a
|
|
188
190
|
genuine upstream dependency, stated plainly.
|
|
189
191
|
|
data/docs/loops.md
CHANGED
|
@@ -1,121 +1,93 @@
|
|
|
1
|
-
#
|
|
2
|
-
The loop is the engine that drives one prompt to completion;
|
|
1
|
+
# The loop — one engine, a real turn cap
|
|
2
|
+
The loop is the engine that drives one prompt to completion; `max_turns` is a hard cap on its tool rounds.
|
|
3
3
|
|
|
4
|
-
The **loop** is the engine that drives one prompt to completion.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
| Tool source | your sandbox-backed tools | the SDK's own built-in/host tools |
|
|
11
|
-
| Turn cap | observability only (see caveat) | native `max_turns` hard cap |
|
|
12
|
-
| Execution location | your sandbox (virtual/local/remote)| the host process |
|
|
13
|
-
|
|
14
|
-
The whole point: **same agent code, swapped backends**. Both examples are model-agnostic
|
|
15
|
-
(`ENV.fetch("NEXO_MODEL")` — never a hardcoded `"claude-…"`):
|
|
4
|
+
The **loop** is the engine that drives one prompt to completion. Nexo ships one,
|
|
5
|
+
`Nexo::Loops::RubyLLM`, and it is the default: it builds the agent's chat with its
|
|
6
|
+
sandbox-backed tools and lets `ruby_llm` run the tool loop. It works identically on any
|
|
7
|
+
`ruby_llm`-supported model — Anthropic, OpenAI, Gemini, a local model through Ollama —
|
|
8
|
+
because every capability comes from the agent's own gated tools, not from anything
|
|
9
|
+
vendor-specific.
|
|
16
10
|
|
|
17
11
|
```ruby
|
|
18
|
-
|
|
19
|
-
claude = Nexo::Agent.new(
|
|
20
|
-
model: ENV.fetch("NEXO_MODEL"),
|
|
21
|
-
sandbox: Nexo::Sandboxes::Local.new(cwd: "/srv/checkout"),
|
|
22
|
-
permissions: Nexo::Permissions.new(mode: :auto),
|
|
23
|
-
loop: Nexo::Loops::AgentSDK.new
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
# Any-provider path — your sandbox, your tools, human-in-the-loop
|
|
27
|
-
gpt = Nexo::Agent.new(
|
|
12
|
+
agent = Nexo::Agent.new(
|
|
28
13
|
model: ENV.fetch("NEXO_MODEL"), # gpt-5.5, gemini, gemma3:12b via Ollama…
|
|
29
14
|
sandbox: Nexo::Sandboxes::Remote.new(client: my_container_client),
|
|
30
15
|
permissions: Nexo::Permissions.new(mode: :ask, on_ask: ->(cap, detail) {
|
|
31
16
|
SlackApproval.request!(capability: cap, detail: detail)
|
|
32
|
-
})
|
|
33
|
-
loop: Nexo::Loops::RubyLLM.new
|
|
17
|
+
})
|
|
34
18
|
)
|
|
35
19
|
```
|
|
36
20
|
|
|
37
|
-
|
|
38
|
-
`
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
| Nexo mode | AgentSDK `permission_mode` |
|
|
42
|
-
| ------------ | -------------------------- |
|
|
43
|
-
| `:read_only` | `:default` |
|
|
44
|
-
| `:auto` | `:bypass_permissions` |
|
|
45
|
-
| `:ask` | `:default` (human gating stays in Nexo's own `on_ask` path, not delegated to the SDK) |
|
|
46
|
-
| `:approve` | `:default` (durable approval stays in Nexo's own gate; any unmapped mode also falls back to `:default`) |
|
|
47
|
-
|
|
48
|
-
## The turn-cap caveat (read before running untrusted/expensive workloads)
|
|
49
|
-
|
|
50
|
-
`ruby_llm` runs the whole tool loop inside `ask`, so `Loops::RubyLLM` has **no clean public
|
|
51
|
-
hard "stop after N turns" halt** — `before_tool_call` gives turn-count *observability*, not a
|
|
52
|
-
hard stop. (Confirmed: `ruby_llm` 1.16.0's `Chat` exposes no public max-turns/max-iterations
|
|
53
|
-
setting.) Your three real options:
|
|
54
|
-
|
|
55
|
-
(a) use `Loops::AgentSDK` (native `max_turns`) for untrusted/expensive workloads;
|
|
56
|
-
(b) have a tool return `{ error: "turn limit reached, stop and summarize" }` once a turn
|
|
57
|
-
counter trips;
|
|
58
|
-
(c) check whether the installed `ruby_llm` exposes a max-iterations config (in 1.16.0 it
|
|
59
|
-
does not).
|
|
60
|
-
|
|
61
|
-
Do **not** ship `Loops::RubyLLM` for untrusted workloads claiming a hard cap that isn't
|
|
62
|
-
proven.
|
|
63
|
-
|
|
64
|
-
## Verified vs assumed
|
|
65
|
-
|
|
66
|
-
Built against **`ruby_llm` 1.16.0** (the supported line — the gemspec pins `~> 1.16`, and the
|
|
67
|
-
upcoming `ruby_llm` 2.0 is not supported yet) and **`ruby_llm-test` 0.2**. The tool body method is
|
|
68
|
-
`#execute`, tools attach with `chat.with_tools(*instances)`, and instructions set with
|
|
69
|
-
`chat.with_instructions`. `Open3.capture3` has no `timeout:` keyword on the target Ruby, so
|
|
70
|
-
`Local#shell` bounds the command with `Timeout.timeout`. These may differ on other
|
|
71
|
-
`ruby_llm` versions.
|
|
72
|
-
|
|
73
|
-
`Loops::RubyLLM`'s turn-count observability uses `RubyLLM::Chat#before_tool_call` /
|
|
74
|
-
`#after_tool_result`, confirmed present on `ruby_llm` 1.16.0 and guarded with `respond_to?`
|
|
75
|
-
so a version lacking them degrades to no observability rather than crashing.
|
|
76
|
-
`Loops::AgentSDK` targets `RubyLLM::AgentSDK.query`; `ruby_llm-agent_sdk` is **not** a
|
|
77
|
-
dependency of this release, so that signature is **assumed** (per the gem's README) and
|
|
78
|
-
verified-on-install — confirm it the moment you add the gem.
|
|
21
|
+
The loop is still a seam. A backend of your own subclasses `Nexo::Loop`, implements
|
|
22
|
+
`run(agent:, prompt:, max_turns:, chat:, &on_event)`, and is injected with `loop:` — the
|
|
23
|
+
agent class never changes.
|
|
79
24
|
|
|
80
|
-
|
|
25
|
+
> `Loops::AgentSDK` was removed in 0.13. It wrapped a `ruby_llm-agent_sdk` gem that was
|
|
26
|
+
> never published, and its one purpose — a hard turn cap — is now native (below).
|
|
81
27
|
|
|
82
|
-
|
|
83
|
-
A real end-to-end check is opt-in and env-gated — small local models like Gemma have weak
|
|
84
|
-
tool-calling, so it may be flaky and is never a gating test:
|
|
28
|
+
## `max_turns` is a hard cap
|
|
85
29
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
30
|
+
`Agent#prompt`, `Session#prompt` and `Workflow#run_agent` all take `max_turns:` (default
|
|
31
|
+
`25`). It caps **tool rounds**: the number of model responses that ask for tools within
|
|
32
|
+
one prompt, however many calls each response holds. Nexo passes it to `ruby_llm` as
|
|
33
|
+
`with_tool_options(rounds:)`.
|
|
34
|
+
|
|
35
|
+
When the cap is reached, `ruby_llm` raises `RubyLLM::ToolRoundLimitError` instead of
|
|
36
|
+
asking the model again. Every tool call that ran has its result, so the conversation
|
|
37
|
+
stays valid. Nexo emits a `:turn_limit_exceeded` event and lets the error propagate:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
begin
|
|
41
|
+
agent.prompt("Triage the inbox", max_turns: 10) do |type, payload|
|
|
42
|
+
warn "over budget: #{payload}" if type == :turn_limit_exceeded
|
|
43
|
+
end
|
|
44
|
+
rescue RubyLLM::ToolRoundLimitError
|
|
45
|
+
# the run used its 10 rounds — decide whether to retry with a larger budget
|
|
46
|
+
end
|
|
89
47
|
```
|
|
90
48
|
|
|
91
|
-
|
|
92
|
-
|
|
49
|
+
Inside a workflow the error fails the run like any other (`status: "failed"`, re-raised),
|
|
50
|
+
so a runaway agent cannot keep spending.
|
|
93
51
|
|
|
52
|
+
Things to know:
|
|
94
53
|
|
|
95
|
-
|
|
54
|
+
- **Upgrading from 0.12:** `max_turns` used to be telemetry only — a run that passed it
|
|
55
|
+
kept going. It now stops. If a legitimate run needs more rounds, raise the number.
|
|
56
|
+
- `max_turns: nil` runs uncapped. Use it only for trusted workloads.
|
|
57
|
+
- The event also fires, once per prompt, the first time the count of tool **calls** passes
|
|
58
|
+
`max_turns`. A round can hold several calls, so with concurrent tool calls this can
|
|
59
|
+
arrive before the round cap trips. It is a warning; the raise is the stop.
|
|
60
|
+
- The cap counts rounds, not time or tokens. Bound those inside your own tools (a read
|
|
61
|
+
tool that accepts at most N ids) or with your provider's limits.
|
|
96
62
|
|
|
97
|
-
|
|
98
|
-
default `Loops::RubyLLM` it **cannot halt a run**: ruby_llm executes the entire tool loop
|
|
99
|
-
inside `Chat#ask`, and the callbacks Nexo wires are observation-only.
|
|
63
|
+
## Verified against
|
|
100
64
|
|
|
101
|
-
|
|
65
|
+
Built and tested against **`ruby_llm` 2.2.3** (the gemspec pins `~> 2.2.0`). The tool body
|
|
66
|
+
method is `#execute`; the chat calls a tool as `tool.call(**arguments)`; tools attach with
|
|
67
|
+
`chat.with_tools(*instances)`; execution settings go through `chat.with_tool_options`;
|
|
68
|
+
instructions set with `chat.with_instructions`. Tool activity is observed with
|
|
69
|
+
`Chat#before_tool_call` / `#after_tool_result`, which are additive.
|
|
102
70
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
71
|
+
These facts are not taken on trust: `test/real_loop_test.rb` drives `ruby_llm`'s real
|
|
72
|
+
conversation loop with scripted model replies and asserts the permission gate, the MCP
|
|
73
|
+
gate, the turn cap, and approval suspension end to end.
|
|
74
|
+
|
|
75
|
+
`Open3.capture3` has no `timeout:` keyword on the target Ruby, so `Local#shell` bounds the
|
|
76
|
+
command with `Timeout.timeout`.
|
|
109
77
|
|
|
110
|
-
|
|
78
|
+
## Live smoke (optional)
|
|
111
79
|
|
|
112
|
-
|
|
80
|
+
The core suite is fully offline and deterministic (model replies are scripted with
|
|
81
|
+
`ruby_llm`'s own `RubyLLM::TestHelper`). A real end-to-end check is opt-in and env-gated —
|
|
82
|
+
small local models like Gemma have weak tool-calling, so it may be flaky and is never a
|
|
83
|
+
gating test:
|
|
113
84
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
85
|
+
```sh
|
|
86
|
+
ollama serve &
|
|
87
|
+
NEXO_LIVE=1 NEXO_MODEL=gemma3:12b bundle exec rake test TEST=test/live_smoke_test.rb
|
|
88
|
+
```
|
|
117
89
|
|
|
118
|
-
|
|
119
|
-
|
|
90
|
+
If Gemma's tool-calling proves too weak, point `NEXO_MODEL` at a stronger model — the gem
|
|
91
|
+
stays provider-neutral; only the smoke target changes.
|
|
120
92
|
|
|
121
93
|
← Back to the [README](../README.md)
|
data/docs/mcp.md
CHANGED
|
@@ -3,9 +3,9 @@ Attach one or more MCP servers with a single `mcp` macro — every call gated by
|
|
|
3
3
|
|
|
4
4
|
An **MCP server** exposes tools to a model over the [Model Context
|
|
5
5
|
Protocol](https://modelcontextprotocol.io) — Gmail, a filesystem, a fetch endpoint,
|
|
6
|
-
Drive, and so on. Nexo does not implement MCP; it composes the
|
|
7
|
-
[`ruby_llm
|
|
8
|
-
servers with a single `mcp` macro and no client wiring. Because a server is reached
|
|
6
|
+
Drive, and so on. Nexo does not implement MCP; it composes the MCP client built into
|
|
7
|
+
[`ruby_llm`](https://rubyllm.com/mcp/) (core since 2.1) so you attach one or more
|
|
8
|
+
servers with a single `mcp` macro and no client wiring — and no extra gem. Because a server is reached
|
|
9
9
|
*through the protocol* (never a vendor SDK), the behavior is identical on Anthropic, a
|
|
10
10
|
local model, or anything else `ruby_llm` supports.
|
|
11
11
|
|
|
@@ -56,10 +56,10 @@ no globs or regexes.
|
|
|
56
56
|
constrain what that server does with a call it is authorized to make — attaching a write
|
|
57
57
|
server and allowing a write tool means real writes happen. Gate deliberately, and prefer
|
|
58
58
|
`:read_only` with a tight `mcp_allow`.
|
|
59
|
-
2. **Connection lifecycle.**
|
|
60
|
-
reused across prompts (
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
2. **Connection lifecycle.** Servers are built once and **memoized on the agent instance**,
|
|
60
|
+
reused across prompts (a server connects on its first request and stays connected). A
|
|
61
|
+
long-lived agent holding stdio/HTTP servers should call `Agent#close` when done to tear
|
|
62
|
+
the connections down:
|
|
63
63
|
|
|
64
64
|
```ruby
|
|
65
65
|
agent = InboxDigest.new
|
|
@@ -68,13 +68,32 @@ no globs or regexes.
|
|
|
68
68
|
agent.close # stops every attached server
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
##
|
|
71
|
+
## Stdio servers: environment and stderr
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
**
|
|
77
|
-
`
|
|
73
|
+
A `:stdio` server is a process Nexo's host starts. Two things about it come from
|
|
74
|
+
`ruby_llm` and are worth knowing:
|
|
75
|
+
|
|
76
|
+
- **It gets a short environment.** The process inherits only a small set of safe variables
|
|
77
|
+
(`PATH`, `HOME`, `LANG`, `TMPDIR`, `USER`, and a few more) — not your application's
|
|
78
|
+
secrets. Pass anything else the server needs with `env:`:
|
|
79
|
+
|
|
80
|
+
```ruby
|
|
81
|
+
mcp :github, transport: :stdio, command: "github-mcp", env: {GITHUB_TOKEN: ENV.fetch("GITHUB_TOKEN")}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- **Its stderr is your process's stderr.** A chatty server prints straight into your
|
|
85
|
+
terminal or log. To drop it, wrap the command:
|
|
86
|
+
`command: "sh", args: ["-c", 'exec "$0" 2>/dev/null', "apple-mail-mcp"]`.
|
|
87
|
+
|
|
88
|
+
`command:` takes a String or an argv Array, `args:` is appended to it, and `directory:`
|
|
89
|
+
sets the process's working directory.
|
|
90
|
+
|
|
91
|
+
## HTTP servers + a bearer `token:`
|
|
92
|
+
|
|
93
|
+
Beyond `:stdio`, Nexo attaches a server over HTTP — `transport: :http`, `:sse`, or
|
|
94
|
+
`:streamable` (all three are "a URL"; `ruby_llm` speaks Streamable HTTP and falls back for
|
|
95
|
+
older servers by itself). For an authenticated hosted server (Gmail, Drive, …) add a
|
|
96
|
+
`token:` — a static bearer `String`, or a **callable** that returns one:
|
|
78
97
|
|
|
79
98
|
```ruby
|
|
80
99
|
class InboxTriageHTTP < Nexo::Agent
|
|
@@ -85,7 +104,7 @@ class InboxTriageHTTP < Nexo::Agent
|
|
|
85
104
|
mcp :gmail,
|
|
86
105
|
transport: :http,
|
|
87
106
|
url: ENV.fetch("GMAIL_MCP_URL"),
|
|
88
|
-
token: -> { Current.user.gmail_access_token } #
|
|
107
|
+
token: -> { Current.user.gmail_access_token } # read again for each request
|
|
89
108
|
|
|
90
109
|
# READ tools only — the unchanged gate denies send/trash/modify.
|
|
91
110
|
mcp_allow %w[search_threads get_thread list_messages get_message list_labels]
|
|
@@ -93,53 +112,39 @@ end
|
|
|
93
112
|
```
|
|
94
113
|
|
|
95
114
|
A static token (`token: ENV.fetch("GMAIL_TOKEN")`) is equally valid. Under the hood
|
|
96
|
-
Nexo
|
|
115
|
+
Nexo hands the token to `ruby_llm` as the server's bearer token:
|
|
97
116
|
|
|
98
117
|
```ruby
|
|
99
|
-
RubyLLM
|
|
100
|
-
name: "gmail", transport_type: :http,
|
|
101
|
-
config: { url: "https://…", headers: { "Authorization" => "Bearer <resolved>" } }
|
|
102
|
-
)
|
|
118
|
+
RubyLLM.mcp(name: "gmail", url: "https://…", bearer_token: -> { … })
|
|
103
119
|
```
|
|
104
120
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
is untouched.
|
|
121
|
+
`ruby_llm` sends it as `Authorization: Bearer <token>`. Any `headers:` you pass are sent
|
|
122
|
+
too; the bearer token wins the `Authorization` header.
|
|
108
123
|
|
|
109
|
-
**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
logged, persisted, placed in a URL/query string, or emitted in an event (the event path
|
|
113
|
-
carries only tool `name`/`args` and return values — never connection config).
|
|
114
|
-
|
|
115
|
-
**Refresh / reconnect caveat.** `ruby_llm-mcp`'s HTTP-family transports snapshot the
|
|
116
|
-
`headers` hash **at construction** — there is no per-request header callback for a plain
|
|
117
|
-
`headers` Hash. A callable `token:` is therefore resolved **once**, when the client is
|
|
118
|
-
built, and the client is memoized on the agent instance across prompts. So when a token
|
|
119
|
-
**rotates**, tear the connection down and reconnect to pick up the new value:
|
|
124
|
+
**A callable token is read again for every request.** When a token rotates, the next
|
|
125
|
+
request carries the new value — no reconnect needed. (Under `ruby_llm` 1.x a callable was
|
|
126
|
+
resolved once per connection and a rotation needed `agent.close`; that caveat is gone.)
|
|
120
127
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
128
|
+
**Nexo does not own the OAuth flow.** It performs no authorization-code exchange, no
|
|
129
|
+
token refresh, and keeps no token store — that is your app or an OAuth library. The token
|
|
130
|
+
is never logged, persisted, placed in a URL/query string, or emitted in an event (the
|
|
131
|
+
event path carries only tool `name`/`args` and return values — never connection config).
|
|
125
132
|
|
|
126
|
-
**The gate is unchanged.** An HTTP
|
|
133
|
+
**The gate is unchanged.** An HTTP server's tools are gated exactly like `:stdio`
|
|
127
134
|
tools: denied under `:read_only` until the exact name is in `mcp_allow` (default `[]` ⇒
|
|
128
135
|
deny-all). Attaching an authenticated server adds no permission surface.
|
|
129
136
|
|
|
130
|
-
**
|
|
137
|
+
**The token is a live credential.** Even gated, an authorized MCP call runs its effect
|
|
138
|
+
server-side — a leaked bearer is a real compromise. Nexo keeps it out of logs, events,
|
|
139
|
+
persisted `WorkflowRun` records, and URLs; your host code must do the same. Nexo does
|
|
140
|
+
not police `ruby_llm`'s own debug logging (`RUBYLLM_DEBUG`) — that boundary is yours.
|
|
131
141
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return. A static token stays constant for the client's life.
|
|
135
|
-
2. **The token is a live credential.** Even gated, an authorized MCP call runs its effect
|
|
136
|
-
server-side — a leaked bearer is a real compromise. Nexo keeps it out of logs, events,
|
|
137
|
-
persisted `WorkflowRun` records, and URLs; your host code must do the same. Nexo does
|
|
138
|
-
not police `ruby_llm-mcp`'s own internal logging of headers — that boundary is yours.
|
|
142
|
+
`ruby_llm` can also run a full per-user OAuth flow for an MCP server
|
|
143
|
+
(`oauth owner:` on a `RubyLLM::MCP` class). Nexo's `mcp` macro does not expose it yet.
|
|
139
144
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
`
|
|
145
|
+
> **Upgrading from 0.12:** remove `gem "ruby_llm-mcp"` from your Gemfile. It defines the
|
|
146
|
+
> same `RubyLLM::MCP` constant as `ruby_llm` 2.x and the two cannot be bundled together.
|
|
147
|
+
> The `mcp` macro and `mcp_allow` are unchanged.
|
|
143
148
|
|
|
144
149
|
|
|
145
150
|
## Decorating MCP tools
|
|
@@ -161,8 +166,9 @@ end
|
|
|
161
166
|
```
|
|
162
167
|
|
|
163
168
|
A wrapper must keep the duck type the chat relies on — `#name`, `#description`,
|
|
164
|
-
`#
|
|
165
|
-
|
|
169
|
+
`#parameters_schema` and `#call`. `ruby_llm` 2.x calls every tool with **keywords**, so
|
|
170
|
+
write `def call(**arguments) = …@tool.call(**arguments)`. Delegate everything else with
|
|
171
|
+
`method_missing`, as `GatedTool` does, so wrappers compose.
|
|
166
172
|
|
|
167
173
|
Gating happens **underneath** the wrapper, so it only ever sees an already-authorized
|
|
168
174
|
call. Wrapping cannot widen what an agent may do.
|
data/docs/sessions.md
CHANGED
|
@@ -27,13 +27,17 @@ do. The persisted record supplies the *thread*; the agent supplies the
|
|
|
27
27
|
## Composition — `acts_as_chat`, owned by the host
|
|
28
28
|
|
|
29
29
|
Message persistence is **RubyLLM's `acts_as_chat`** — Nexo defines no message table
|
|
30
|
-
and serializes nothing. The host Rails app owns
|
|
31
|
-
|
|
30
|
+
and serializes nothing. The host Rails app owns the `Chat` and `Message` models,
|
|
31
|
+
generated by ruby_llm's own installer (ruby_llm 2.x keeps the model registry, tool calls
|
|
32
|
+
and usage in its own `ruby_llm_*` tables):
|
|
32
33
|
|
|
33
34
|
```bash
|
|
34
|
-
rails g ruby_llm:install # generates the Chat/Message
|
|
35
|
+
rails g ruby_llm:install # generates the Chat/Message models + migrations
|
|
35
36
|
```
|
|
36
37
|
|
|
38
|
+
Already on ruby_llm 1.x persistence? Run ruby_llm's own schema upgrade first
|
|
39
|
+
(`rails g ruby_llm:upgrade`, see its [upgrade guide](https://rubyllm.com/upgrading/)).
|
|
40
|
+
|
|
37
41
|
**One setup step beyond the installer:** the session chat model must be addressable,
|
|
38
42
|
so add two columns and a **unique composite index** to the generated `chats` table:
|
|
39
43
|
|
data/docs/skills.md
CHANGED
|
@@ -3,9 +3,8 @@ A skill is a `SKILL.md` package that teaches the model *how you want a task done
|
|
|
3
3
|
|
|
4
4
|
A **skill** is a `SKILL.md` package — frontmatter plus instructions — that teaches the
|
|
5
5
|
model *how you want a task done*. Skills guide **reasoning**; the sandbox-backed tools
|
|
6
|
-
above perform **execution**.
|
|
7
|
-
|
|
8
|
-
skill with one macro and no loader setup.
|
|
6
|
+
above perform **execution**. You attach a skill with one macro: Nexo reads the `SKILL.md`
|
|
7
|
+
itself, so there is no loader to set up and no extra gem to install.
|
|
9
8
|
|
|
10
9
|
Drop a package under `app/skills/` (or scaffold one — see below):
|
|
11
10
|
|
|
@@ -52,10 +51,20 @@ rails g nexo:skill triage
|
|
|
52
51
|
# create app/skills/triage/SKILL.md
|
|
53
52
|
```
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
Referencing a skill that does not exist raises `Nexo::Error` naming the missing
|
|
55
|
+
`SKILL.md` path, as does a `SKILL.md` with no YAML front matter.
|
|
56
|
+
|
|
57
|
+
> **Upgrading from 0.12:** remove `gem "ruby_llm-skills"` from your Gemfile — it is no
|
|
58
|
+
> longer used (and it pins `ruby_llm` 1.x). The `skills` macro, `Nexo::Skills.find` and
|
|
59
|
+
> `Nexo::Skills.materialize` are unchanged.
|
|
60
|
+
|
|
61
|
+
### Why not `ruby_llm`'s own skills?
|
|
62
|
+
|
|
63
|
+
`ruby_llm` 2.2 ships skills too (`chat.with_skills`). Nexo does not use them, for two
|
|
64
|
+
reasons. Its loader enforces the Agent Skills naming rule — lowercase words joined by
|
|
65
|
+
hyphens — and so rejects the underscore names Nexo resolves from a symbol (`skills
|
|
66
|
+
:email_triage`). And it works by giving the model a `load_skill` tool, where Nexo's rule is
|
|
67
|
+
that a skill adds instructions and nothing else.
|
|
59
68
|
|
|
60
69
|
## Say what a skill needs with `compatibility:`
|
|
61
70
|
|
|
@@ -82,15 +91,15 @@ exactly their body, unchanged.
|
|
|
82
91
|
It is **free text, by design** — the spec does not make it machine-checkable, and Nexo does
|
|
83
92
|
not try to. It is documentation aimed at a human or a model, not a dependency manifest:
|
|
84
93
|
provisioning the sandbox (a gem, a library, a config) is the job of whoever wires the agent
|
|
85
|
-
to it, not of the skill file. `license:` and `allowed-tools:` are
|
|
86
|
-
|
|
94
|
+
to it, not of the skill file. `license:` and `allowed-tools:` are read from the front
|
|
95
|
+
matter but deliberately **not** surfaced — the first is prompt noise, and the
|
|
87
96
|
second would compete with `Nexo::Permissions`, which is the real gate.
|
|
88
97
|
|
|
89
98
|
## Skill tools stay gated
|
|
90
99
|
|
|
91
100
|
A skill contributes **instructions only**. A loaded skill ships no independent tools, and
|
|
92
|
-
Nexo deliberately does not attach `ruby_llm
|
|
93
|
-
|
|
101
|
+
Nexo deliberately does not attach `ruby_llm`'s `load_skill` tool (which reads skill
|
|
102
|
+
files from the host, outside the sandbox) — so **attaching a skill never widens what an agent can
|
|
94
103
|
do** beyond its configured sandbox/permission mode.
|
|
95
104
|
|
|
96
105
|
## Bundled files are not reachable until you stage them
|
data/examples/mcp_filesystem.rb
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
# * read tools are on the mcp_allow list -> the model can use them
|
|
8
8
|
# * write_file is NOT on the list -> the gate returns { error: ... } (denied)
|
|
9
9
|
#
|
|
10
|
-
# Requires:
|
|
10
|
+
# Requires: `npx` on PATH, and a model. MCP ships with ruby_llm — no extra gem.
|
|
11
11
|
#
|
|
12
12
|
# NEXO_LIVE=1 NEXO_MODEL=gemma3:12b ruby -Ilib examples/mcp_filesystem.rb /tmp
|
|
13
13
|
#
|