nexo_ai 0.12.0 → 0.14.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 +154 -0
- data/README.md +13 -15
- data/docs/concurrency.md +1 -2
- data/docs/durable-workflows.md +18 -6
- data/docs/loops.md +67 -95
- data/docs/mcp.md +62 -51
- data/docs/permissions.md +2 -2
- data/docs/sandboxes.md +58 -6
- data/docs/sessions.md +7 -3
- data/docs/skills.md +20 -11
- data/docs/tools.md +47 -0
- data/examples/mcp_filesystem.rb +1 -1
- data/lib/nexo/agent.rb +142 -59
- data/lib/nexo/concurrent.rb +1 -1
- data/lib/nexo/configuration.rb +9 -0
- data/lib/nexo/gated_tool.rb +86 -0
- data/lib/nexo/loop.rb +7 -9
- data/lib/nexo/loops/ruby_llm.rb +41 -32
- data/lib/nexo/mcp/gated_tool.rb +12 -56
- data/lib/nexo/mcp.rb +71 -66
- data/lib/nexo/permissions.rb +86 -29
- data/lib/nexo/sandbox.rb +8 -0
- data/lib/nexo/sandboxes/local.rb +169 -17
- data/lib/nexo/sandboxes.rb +3 -2
- data/lib/nexo/skills/skill.rb +89 -0
- data/lib/nexo/skills.rb +14 -41
- data/lib/nexo/tools/fetch.rb +35 -5
- data/lib/nexo/tools/glob.rb +1 -1
- data/lib/nexo/tools/read_file.rb +1 -1
- data/lib/nexo/tools/shell.rb +6 -3
- 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 +67 -30
- data/lib/nexo.rb +22 -4
- data/sig/nexo/agent.rbs +4 -2
- data/sig/nexo/permissions.rbs +13 -1
- data/sig/nexo/sandbox.rbs +1 -0
- data/sig/nexo/sandboxes/local.rbs +6 -1
- metadata +5 -32
- data/lib/nexo/loops/agent_sdk.rb +0 -68
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
|
|
|
@@ -40,6 +40,11 @@ exact-match allow-list threaded into the agent's permissions:
|
|
|
40
40
|
| `:read_only` (default) | allow **only** tool names listed in `mcp_allow`; everything else is denied |
|
|
41
41
|
| `:ask` | call `on_ask.call(:mcp, {tool:, args:})`; a truthy return allows, else deny |
|
|
42
42
|
| `:approve` | names in `mcp_allow` are pre-approved; any other tool needs a human decision — undecided **suspends the run** (`Nexo::ApprovalRequired`), `approved: true` allows, `approved: false` denies (the durable sibling of `:ask`) |
|
|
43
|
+
|
|
44
|
+
Under `:read_only` an MCP tool that is not in `mcp_allow` is not attached at all (0.14): the
|
|
45
|
+
model never sees a tool it could not call. Under `:approve` each call is decided on its own —
|
|
46
|
+
the tool name and its arguments identify it — so approving one `send_email` does not approve
|
|
47
|
+
the next.
|
|
43
48
|
| `:auto` | allow every MCP tool |
|
|
44
49
|
|
|
45
50
|
`mcp_allow` defaults to `[]`, so attaching a powerful server under `:read_only` with no
|
|
@@ -56,10 +61,10 @@ no globs or regexes.
|
|
|
56
61
|
constrain what that server does with a call it is authorized to make — attaching a write
|
|
57
62
|
server and allowing a write tool means real writes happen. Gate deliberately, and prefer
|
|
58
63
|
`:read_only` with a tight `mcp_allow`.
|
|
59
|
-
2. **Connection lifecycle.**
|
|
60
|
-
reused across prompts (
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
2. **Connection lifecycle.** Servers are built once and **memoized on the agent instance**,
|
|
65
|
+
reused across prompts (a server connects on its first request and stays connected). A
|
|
66
|
+
long-lived agent holding stdio/HTTP servers should call `Agent#close` when done to tear
|
|
67
|
+
the connections down:
|
|
63
68
|
|
|
64
69
|
```ruby
|
|
65
70
|
agent = InboxDigest.new
|
|
@@ -68,13 +73,32 @@ no globs or regexes.
|
|
|
68
73
|
agent.close # stops every attached server
|
|
69
74
|
```
|
|
70
75
|
|
|
71
|
-
##
|
|
76
|
+
## Stdio servers: environment and stderr
|
|
77
|
+
|
|
78
|
+
A `:stdio` server is a process Nexo's host starts. Two things about it come from
|
|
79
|
+
`ruby_llm` and are worth knowing:
|
|
80
|
+
|
|
81
|
+
- **It gets a short environment.** The process inherits only a small set of safe variables
|
|
82
|
+
(`PATH`, `HOME`, `LANG`, `TMPDIR`, `USER`, and a few more) — not your application's
|
|
83
|
+
secrets. Pass anything else the server needs with `env:`:
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
mcp :github, transport: :stdio, command: "github-mcp", env: {GITHUB_TOKEN: ENV.fetch("GITHUB_TOKEN")}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- **Its stderr is your process's stderr.** A chatty server prints straight into your
|
|
90
|
+
terminal or log. To drop it, wrap the command:
|
|
91
|
+
`command: "sh", args: ["-c", 'exec "$0" 2>/dev/null', "apple-mail-mcp"]`.
|
|
92
|
+
|
|
93
|
+
`command:` takes a String or an argv Array, `args:` is appended to it, and `directory:`
|
|
94
|
+
sets the process's working directory.
|
|
72
95
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
96
|
+
## HTTP servers + a bearer `token:`
|
|
97
|
+
|
|
98
|
+
Beyond `:stdio`, Nexo attaches a server over HTTP — `transport: :http`, `:sse`, or
|
|
99
|
+
`:streamable` (all three are "a URL"; `ruby_llm` speaks Streamable HTTP and falls back for
|
|
100
|
+
older servers by itself). For an authenticated hosted server (Gmail, Drive, …) add a
|
|
101
|
+
`token:` — a static bearer `String`, or a **callable** that returns one:
|
|
78
102
|
|
|
79
103
|
```ruby
|
|
80
104
|
class InboxTriageHTTP < Nexo::Agent
|
|
@@ -85,7 +109,7 @@ class InboxTriageHTTP < Nexo::Agent
|
|
|
85
109
|
mcp :gmail,
|
|
86
110
|
transport: :http,
|
|
87
111
|
url: ENV.fetch("GMAIL_MCP_URL"),
|
|
88
|
-
token: -> { Current.user.gmail_access_token } #
|
|
112
|
+
token: -> { Current.user.gmail_access_token } # read again for each request
|
|
89
113
|
|
|
90
114
|
# READ tools only — the unchanged gate denies send/trash/modify.
|
|
91
115
|
mcp_allow %w[search_threads get_thread list_messages get_message list_labels]
|
|
@@ -93,53 +117,39 @@ end
|
|
|
93
117
|
```
|
|
94
118
|
|
|
95
119
|
A static token (`token: ENV.fetch("GMAIL_TOKEN")`) is equally valid. Under the hood
|
|
96
|
-
Nexo
|
|
120
|
+
Nexo hands the token to `ruby_llm` as the server's bearer token:
|
|
97
121
|
|
|
98
122
|
```ruby
|
|
99
|
-
RubyLLM
|
|
100
|
-
name: "gmail", transport_type: :http,
|
|
101
|
-
config: { url: "https://…", headers: { "Authorization" => "Bearer <resolved>" } }
|
|
102
|
-
)
|
|
123
|
+
RubyLLM.mcp(name: "gmail", url: "https://…", bearer_token: -> { … })
|
|
103
124
|
```
|
|
104
125
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
is untouched.
|
|
108
|
-
|
|
109
|
-
**Nexo does not own the OAuth flow.** It performs no authorization-code exchange, no
|
|
110
|
-
token refresh, and keeps no token store — that is your app or an OAuth library. Nexo's
|
|
111
|
-
only job is to call the provider, inject the header, and hand off. The token is never
|
|
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).
|
|
126
|
+
`ruby_llm` sends it as `Authorization: Bearer <token>`. Any `headers:` you pass are sent
|
|
127
|
+
too; the bearer token wins the `Authorization` header.
|
|
114
128
|
|
|
115
|
-
**
|
|
116
|
-
|
|
117
|
-
|
|
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:
|
|
129
|
+
**A callable token is read again for every request.** When a token rotates, the next
|
|
130
|
+
request carries the new value — no reconnect needed. (Under `ruby_llm` 1.x a callable was
|
|
131
|
+
resolved once per connection and a rotation needed `agent.close`; that caveat is gone.)
|
|
120
132
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
133
|
+
**Nexo does not own the OAuth flow.** It performs no authorization-code exchange, no
|
|
134
|
+
token refresh, and keeps no token store — that is your app or an OAuth library. The token
|
|
135
|
+
is never logged, persisted, placed in a URL/query string, or emitted in an event (the
|
|
136
|
+
event path carries only tool `name`/`args` and return values — never connection config).
|
|
125
137
|
|
|
126
|
-
**The gate is unchanged.** An HTTP
|
|
138
|
+
**The gate is unchanged.** An HTTP server's tools are gated exactly like `:stdio`
|
|
127
139
|
tools: denied under `:read_only` until the exact name is in `mcp_allow` (default `[]` ⇒
|
|
128
140
|
deny-all). Attaching an authenticated server adds no permission surface.
|
|
129
141
|
|
|
130
|
-
**
|
|
142
|
+
**The token is a live credential.** Even gated, an authorized MCP call runs its effect
|
|
143
|
+
server-side — a leaked bearer is a real compromise. Nexo keeps it out of logs, events,
|
|
144
|
+
persisted `WorkflowRun` records, and URLs; your host code must do the same. Nexo does
|
|
145
|
+
not police `ruby_llm`'s own debug logging (`RUBYLLM_DEBUG`) — that boundary is yours.
|
|
131
146
|
|
|
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.
|
|
147
|
+
`ruby_llm` can also run a full per-user OAuth flow for an MCP server
|
|
148
|
+
(`oauth owner:` on a `RubyLLM::MCP` class). Nexo's `mcp` macro does not expose it yet.
|
|
139
149
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
`
|
|
150
|
+
> **Upgrading from 0.12:** remove `gem "ruby_llm-mcp"` from your Gemfile. It defines the
|
|
151
|
+
> same `RubyLLM::MCP` constant as `ruby_llm` 2.x and the two cannot be bundled together.
|
|
152
|
+
> The `mcp` macro and `mcp_allow` are unchanged.
|
|
143
153
|
|
|
144
154
|
|
|
145
155
|
## Decorating MCP tools
|
|
@@ -161,8 +171,9 @@ end
|
|
|
161
171
|
```
|
|
162
172
|
|
|
163
173
|
A wrapper must keep the duck type the chat relies on — `#name`, `#description`,
|
|
164
|
-
`#
|
|
165
|
-
|
|
174
|
+
`#parameters_schema` and `#call`. `ruby_llm` 2.x calls every tool with **keywords**, so
|
|
175
|
+
write `def call(**arguments) = …@tool.call(**arguments)`. Delegate everything else with
|
|
176
|
+
`method_missing`, as `GatedTool` does, so wrappers compose.
|
|
166
177
|
|
|
167
178
|
Gating happens **underneath** the wrapper, so it only ever sees an already-authorized
|
|
168
179
|
call. Wrapping cannot widen what an agent may do.
|
data/docs/permissions.md
CHANGED
|
@@ -11,9 +11,9 @@ and the agent loop continues — it does not raise. A path that escapes the work
|
|
|
11
11
|
| `:read_only` (default) | ✅ | ✅ | ❌ not attached ‡ | ❌ not attached ‡ | ❌ not attached ‡ | ❌ not attached ‡ |
|
|
12
12
|
| `:auto` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
13
13
|
| `:ask` | ✅ | ✅ | per `on_ask` | per `on_ask` | per `on_ask` | per `on_ask` |
|
|
14
|
-
| `:approve` | ✅ | ✅ | per
|
|
14
|
+
| `:approve` | ✅ | ✅ | per call | per call | per call | per call |
|
|
15
15
|
| `Virtual` sandbox | ✅ | ✅ | ✅ (in-memory) | ❌ `NotImplementedError`→`{error}` | ✅ † | ✅ † |
|
|
16
|
-
| `Local` sandbox | ✅ (guarded) | ✅ | ✅ (guarded) | ✅ (narrowed ENV)
|
|
16
|
+
| `Local` sandbox | ✅ (guarded) | ✅ | ✅ (guarded) | ✅ (narrowed ENV, unconfined ⚠) | ✅ † | ✅ † |
|
|
17
17
|
| `Container` sandbox | ✅ (guarded) | ✅ | ✅ (guarded, scratch) | ✅ (in container) | ✅ † | ✅ † |
|
|
18
18
|
|
|
19
19
|
`:read`/`:glob` are auto-allowed under **every** mode (they sit in the default
|
data/docs/sandboxes.md
CHANGED
|
@@ -11,9 +11,9 @@ and the agent loop continues — it does not raise. A path that escapes the work
|
|
|
11
11
|
| `:read_only` (default) | ✅ | ✅ | ❌ `{error}` | ❌ `{error}` | ❌ `{error}` | ❌ `{error}` |
|
|
12
12
|
| `:auto` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
13
13
|
| `:ask` | ✅ | ✅ | per `on_ask` | per `on_ask` | per `on_ask` | per `on_ask` |
|
|
14
|
-
| `:approve` | ✅ | ✅ | per
|
|
14
|
+
| `:approve` | ✅ | ✅ | per call | per call | per call | per call |
|
|
15
15
|
| `Virtual` sandbox | ✅ | ✅ | ✅ (in-memory) | ❌ `NotImplementedError`→`{error}` | ✅ † | ✅ † |
|
|
16
|
-
| `Local` sandbox | ✅ (guarded) | ✅ | ✅ (guarded) | ✅ (narrowed ENV)
|
|
16
|
+
| `Local` sandbox | ✅ (guarded) | ✅ | ✅ (guarded) | ✅ (narrowed ENV, unconfined ⚠) | ✅ † | ✅ † |
|
|
17
17
|
| `Container` sandbox | ✅ (guarded) | ✅ | ✅ (guarded, scratch) | ✅ (in container) | ✅ † | ✅ † |
|
|
18
18
|
|
|
19
19
|
`:read`/`:glob` are auto-allowed under **every** mode (they sit in the default
|
|
@@ -26,10 +26,11 @@ only by the capability gate above plus `fetch_allow` / the injected backend.
|
|
|
26
26
|
- **`Virtual`** (default) — in-memory, zero host access. `#shell` raises
|
|
27
27
|
`NotImplementedError` on purpose: in-memory means no command execution. That is the
|
|
28
28
|
safety property, not a gap.
|
|
29
|
-
- **`Local`** — host filesystem + shell, for trusted dev/CI.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
- **`Local`** — host filesystem + shell, for trusted dev/CI. Every file path is expanded
|
|
30
|
+
against `cwd` and must stay inside it (else `SecurityError`). The shell sees only `PATH`,
|
|
31
|
+
`HOME`, `LANG` (plus explicit `env:` additions), and a command that outlives its timeout is
|
|
32
|
+
killed with everything it started. ⚠ The path guard does not cover what a shell command
|
|
33
|
+
touches: see [Confining the local shell](#confining-the-local-shell).
|
|
33
34
|
- **`Container`** — run the tools inside a throwaway local container via the `docker`
|
|
34
35
|
(default) or Apple `container` CLI. Shell-out only, no client gem. **Hardened by default**
|
|
35
36
|
(no network, dropped caps, read-only rootfs + ephemeral scratch, read-only host binds);
|
|
@@ -38,6 +39,57 @@ only by the capability gate above plus `fetch_allow` / the injected backend.
|
|
|
38
39
|
your own) by injecting a client. Escalating to `:remote` is always an explicit choice in
|
|
39
40
|
your code — the default stays `:virtual`.
|
|
40
41
|
|
|
42
|
+
## Confining the local shell
|
|
43
|
+
|
|
44
|
+
On `:local`, `read`/`write`/`glob` are guarded to `cwd`. A shell command is not: it is a host
|
|
45
|
+
process that can read and write wherever your user can, and reach the network. `#hardening_gaps`
|
|
46
|
+
says so, so a host can show it before trusting the sandbox with a model:
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
Nexo::Sandboxes::Local.new(cwd: dir).hardening_gaps
|
|
50
|
+
# => ["shell commands are not confined: they can read and write outside /path and reach the network …"]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`isolation: :confined` runs every command inside an OS sandbox — Seatbelt on macOS, Bubblewrap
|
|
54
|
+
on Linux — through `ruby_llm`'s sandbox contract. A confined command can write only inside
|
|
55
|
+
`cwd`, cannot read your home directory, and has no network:
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
# Gemfile
|
|
59
|
+
gem "mxc" # a soft dependency: Nexo loads it only for a confined shell
|
|
60
|
+
|
|
61
|
+
class Builder < Nexo::Agent
|
|
62
|
+
sandbox :local, isolation: :confined, readable: [RbConfig::CONFIG["prefix"]]
|
|
63
|
+
permissions Nexo::Permissions.new(mode: :read_only, allow: %i[read glob write shell])
|
|
64
|
+
end
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Things to know:
|
|
68
|
+
|
|
69
|
+
- **A confined command cannot read outside `cwd` either.** That includes a Ruby, Node or Python
|
|
70
|
+
installed under your home directory: `ruby` starts but cannot load its gems. Grant the
|
|
71
|
+
toolchain with `readable:`. Tools that link Homebrew libraries need those paths too.
|
|
72
|
+
- **It never falls back.** If the sandbox cannot run on the machine, the first `shell` raises
|
|
73
|
+
`Nexo::ConfigurationError` with the reason. A missing `mxc` gem raises
|
|
74
|
+
`Nexo::MissingDependencyError`.
|
|
75
|
+
- **Bring your own policy.** `isolation:` also takes an `MXC::Sandbox` class or instance, or any
|
|
76
|
+
object answering `supported?` and `run(*command, timeout:, readable:, writable:, directory:,
|
|
77
|
+
env:, network:)`.
|
|
78
|
+
- **Verified on macOS (Seatbelt), `mxc` 0.4.1:** a write outside `cwd`, a read of the home
|
|
79
|
+
directory and a network request were all refused. Linux (Bubblewrap) is not verified here.
|
|
80
|
+
- Unconfined remains the default in 0.14. Use a [container](#container-sandbox--docker--apple-container)
|
|
81
|
+
when you need a different filesystem, not only a fence.
|
|
82
|
+
|
|
83
|
+
### Two fixes in 0.14 that change behaviour
|
|
84
|
+
|
|
85
|
+
- **The narrowed environment is now real.** Before 0.14 the shell inherited the whole process
|
|
86
|
+
environment, API keys included; the `PATH`/`HOME`/`LANG` list was only added on top. A command
|
|
87
|
+
that relied on an inherited variable now needs it passed with `env:`
|
|
88
|
+
(`sandbox :local, env: {"BUNDLE_GEMFILE" => "..."}`).
|
|
89
|
+
- **A timeout now stops the command.** Before 0.14 `Timeout::Error` was raised only after the
|
|
90
|
+
command had finished on its own. Now the command's whole process group is killed, and the
|
|
91
|
+
`Shell` tool reports the timeout to the model as `{error: ...}` instead of failing the run.
|
|
92
|
+
|
|
41
93
|
## Safety refinements — safer, more legible real-FS sandboxes
|
|
42
94
|
|
|
43
95
|
Five small refinements tighten the real-filesystem sandboxes (`Local`, `Container`) and make
|
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/docs/tools.md
CHANGED
|
@@ -15,6 +15,9 @@ ever allow:
|
|
|
15
15
|
neither `WriteFile` nor `Shell` is attached. `:auto`, `:ask` and `:approve` decide per call
|
|
16
16
|
and always attach — `:approve` in particular *must* reach the gate so it can suspend the run.
|
|
17
17
|
|
|
18
|
+
The same rule covers a host tool declared with `capability:` and, since 0.14, an MCP tool:
|
|
19
|
+
under `:read_only` one that is not in `mcp_allow` is not attached.
|
|
20
|
+
|
|
18
21
|
`ReadFile` and `Glob` are always attached. This is a cost and description-accuracy measure, not
|
|
19
22
|
a security boundary: `Permissions#authorize!` remains the gate and still denies at call time.
|
|
20
23
|
|
|
@@ -41,6 +44,50 @@ ever allow:
|
|
|
41
44
|
the stale check (read-before-write is the primary guard). Clobber-safety within a session only —
|
|
42
45
|
no versioning, locking, or VCS semantics.
|
|
43
46
|
|
|
47
|
+
## Tools of your own — the `tools` macro
|
|
48
|
+
|
|
49
|
+
Declare a `RubyLLM::Tool` you wrote on the agent, and say what it does in Nexo's terms:
|
|
50
|
+
|
|
51
|
+
```ruby
|
|
52
|
+
class Archivist < Nexo::Agent
|
|
53
|
+
model ENV.fetch("NEXO_MODEL")
|
|
54
|
+
|
|
55
|
+
tools Today, SumPayments # no side effects: no gate
|
|
56
|
+
tools ArchiveRun, capability: :write # gated exactly like WriteFile
|
|
57
|
+
tools ->(agent) { Lookup.new(root: agent.cwd) }
|
|
58
|
+
end
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Each entry is a tool class (built with no arguments), an instance, or a lambda that takes the
|
|
62
|
+
agent and returns a tool or an Array of tools. The macro accumulates and is inherited.
|
|
63
|
+
|
|
64
|
+
With `capability:` (`:read`, `:write`, `:shell`, `:fetch` or `:search`) the tool is wrapped in
|
|
65
|
+
`Nexo::GatedTool`, and the agent's permissions decide every call the same way they do for Nexo's
|
|
66
|
+
own tools: refused under `:read_only`, put to `on_ask` under `:ask`, suspended under `:approve`.
|
|
67
|
+
A denied call returns `{error: ...}` and the tool body never runs. A gated tool the mode can never
|
|
68
|
+
allow is left out of the schema. The detail your `on_ask`/`ask_when` hook receives is the tool
|
|
69
|
+
name followed by its arguments as JSON.
|
|
70
|
+
|
|
71
|
+
Without `capability:` the tool runs ungated. That is right only for a tool with no side effects.
|
|
72
|
+
|
|
73
|
+
### `strict_tools` — refuse what was never declared
|
|
74
|
+
|
|
75
|
+
A tool added to the chat any other way — typically by overriding `#chat` and calling
|
|
76
|
+
`with_tools` — is one no permission gate ever saw. Nexo catches those calls with a single
|
|
77
|
+
`around_tool_call` block:
|
|
78
|
+
|
|
79
|
+
- By default the call runs and Nexo warns once per tool name.
|
|
80
|
+
- With `Nexo.config.strict_tools = true` the call is refused, and the model is told the call did
|
|
81
|
+
not run.
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
Nexo.configure { |config| config.strict_tools = true }
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Declare your tools with the macro and turn this on. It becomes the default in 1.0. The block is a
|
|
88
|
+
backstop, not the gate: a refused call can only carry `ruby_llm`'s fixed "did not run" text, so
|
|
89
|
+
the gate that explains itself stays with the tool.
|
|
90
|
+
|
|
44
91
|
These are sandbox refinements as much as tool behavior — see [Sandboxes](sandboxes.md) for the
|
|
45
92
|
guard details behind each capability. The `fetch` tool for reading the web lives in
|
|
46
93
|
[Web](web.md), gated by its own `:fetch` capability plus a host allow-list.
|
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
|
#
|