nexo_ai 0.16.1 → 0.17.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 +110 -0
- data/docs/durable-workflows.md +26 -15
- data/docs/loops.md +8 -5
- data/docs/mcp.md +4 -2
- data/docs/skills.md +18 -6
- data/docs/tools.md +35 -3
- data/docs/workflows.md +2 -2
- data/examples/README.md +63 -30
- data/examples/approval_agent.rb +21 -7
- data/examples/artifact_from_template.rb +1 -1
- data/examples/chat_session.rb +2 -1
- data/examples/code_reviewer.rb +4 -3
- data/examples/company_brain.rb +54 -0
- data/examples/confined_shell.rb +56 -0
- data/examples/container_review.rb +3 -2
- data/examples/data_analyst.rb +90 -0
- data/examples/deferred_tools.rb +57 -0
- data/examples/inbox_digest_task.rb +47 -21
- data/examples/llm_options.rb +56 -0
- data/examples/marketing_team.rb +85 -0
- data/examples/mcp_filesystem.rb +11 -6
- data/examples/multiple_approvals.rb +56 -0
- data/examples/news_search.rb +20 -11
- data/examples/news_summary.rb +4 -3
- data/examples/retry_and_cancel.rb +81 -0
- data/examples/skills/email-triage/SKILL.md +44 -0
- data/examples/skills/{news_summary → news-summary}/SKILL.md +1 -1
- data/examples/skills/refunds/SKILL.md +24 -0
- data/examples/software_factory.rb +127 -0
- data/examples/support/handbook/expenses.md +6 -0
- data/examples/support/handbook/on-call.md +5 -0
- data/examples/support/handbook/time-off.md +6 -0
- data/examples/support/handbook_server.rb +46 -0
- data/examples/support/model.rb +33 -0
- data/examples/support_agent.rb +102 -0
- data/examples/tool_question.rb +59 -0
- data/examples/usage_report.rb +50 -0
- data/lib/generators/nexo/skill/skill_generator.rb +7 -1
- data/lib/generators/nexo/skill/templates/SKILL.md.tt +1 -1
- data/lib/nexo/agent.rb +86 -10
- data/lib/nexo/approvable.rb +5 -1
- data/lib/nexo/gated_tool.rb +9 -1
- data/lib/nexo/loops/ruby_llm.rb +86 -10
- data/lib/nexo/model_options.rb +2 -2
- data/lib/nexo/permissions.rb +27 -1
- data/lib/nexo/run_store.rb +11 -4
- data/lib/nexo/sandbox.rb +9 -0
- data/lib/nexo/sandbox_file_store.rb +14 -5
- data/lib/nexo/sandboxes/container.rb +16 -1
- data/lib/nexo/sandboxes/local.rb +11 -0
- data/lib/nexo/sandboxes/virtual.rb +5 -0
- data/lib/nexo/skills/skill.rb +70 -33
- data/lib/nexo/skills.rb +10 -1
- data/lib/nexo/version.rb +1 -1
- data/lib/nexo/workflow.rb +77 -25
- data/lib/nexo.rb +10 -0
- data/sig/nexo/agent.rbs +5 -2
- data/sig/nexo/permissions.rbs +3 -0
- data/sig/nexo/sandbox.rbs +2 -0
- metadata +21 -5
- data/examples/inbox_digest.rb +0 -62
- data/examples/inbox_digest_http.rb +0 -69
- data/examples/skills/email_triage/SKILL.md +0 -47
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d892a96f46bae087af149ae6593af9e023ce586a44a369f4865917cc00287b70
|
|
4
|
+
data.tar.gz: 17e48c261733821b0c0cd1d9493d00239fe09edd3be601cf9a43f3132151fcc1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7fe93f368ae348eba7ac7a6abc5bd1e299a37f29062fc9f01e7022d55f9169125e204c49764cf5680026d79f16d950b69f561e079a8335ed89deacc054f97c53
|
|
7
|
+
data.tar.gz: 3cd8bf2dc89126bed7dfd9479caec21d9cfa4e4d28110cc58847738febe0e3dbb42dd9b79daacb8083e619435abfe94420baa383e9f279f5f61e2b7dbfd75ef3
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,115 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.17.0] - 2026-11-27
|
|
4
|
+
|
|
5
|
+
Closes what 0.16 left open. The headline: a resume no longer asks the model again.
|
|
6
|
+
|
|
7
|
+
**Upgrading:**
|
|
8
|
+
|
|
9
|
+
1. **Skill names are hyphenated.** Skills are read by ruby_llm's parser, which follows the
|
|
10
|
+
Agent Skills specification: `name` and `description` are required, and the name is
|
|
11
|
+
lower-case letters, digits and single hyphens, equal to its folder. Rename
|
|
12
|
+
`app/skills/email_triage/` to `email-triage/` and its `name:` with it. `skills
|
|
13
|
+
:email_triage` keeps resolving to the renamed folder. An underscore-named skill still
|
|
14
|
+
loads in 0.17, with a notice, and stops loading in 0.18. A skill with no `description`,
|
|
15
|
+
or whose `name:` differs from its folder, now raises `Nexo::Error`.
|
|
16
|
+
2. **A resume carries the conversation on.** If a test scripts the model's replies, the
|
|
17
|
+
resume now needs only what comes AFTER the approved call (see below).
|
|
18
|
+
3. **`Skill#metadata`** is the front matter's `metadata` mapping, not the whole front matter.
|
|
19
|
+
4. **A custom agent class given a `Permissions` instance** works on a copy of it.
|
|
20
|
+
5. `RunStore::Disk#all` lists runs by creation, newest first, not by file time.
|
|
21
|
+
6. Agents that may write get one more tool, `delete_file`.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- **A resume continues the paused conversation instead of asking the prompt again.** When
|
|
26
|
+
`run_agent` suspends for an approval or a question, the conversation is saved with the run
|
|
27
|
+
(reserved state key `"__chat__"`). The resume restores it and carries on: the held call
|
|
28
|
+
runs or is refused, nothing before it runs again, and the model is asked only for what
|
|
29
|
+
comes next. Before, the whole prompt was asked again, so a tool that had already run could
|
|
30
|
+
run twice and a model could ask for something different the second time. It works on all
|
|
31
|
+
three run stores. A run suspended by an older version, which has no saved conversation,
|
|
32
|
+
is asked again as before. A direct caller does the same with
|
|
33
|
+
`agent.prompt(text, continue: error.transcript)`.
|
|
34
|
+
- **Skills are parsed by `RubyLLM::Skill`** (see Upgrading). Nexo still puts a skill's text in
|
|
35
|
+
the instructions itself and never attaches ruby_llm's `load_skill` tool.
|
|
36
|
+
- **A timed-out MCP task answers its call with an error**, so the model hears it and the
|
|
37
|
+
prompt goes on, where it used to fail the prompt.
|
|
38
|
+
- **An absolute path outside the sandbox is refused by name** (`… is outside the workspace`)
|
|
39
|
+
where the file tools used to report it as not found.
|
|
40
|
+
- `Workflow#emit` is safe to call from several `checkpoint_all` steps at once.
|
|
41
|
+
- `rails g nexo:skill issue_triage` creates `app/skills/issue-triage/` with a matching
|
|
42
|
+
`name:`, the form skills now need.
|
|
43
|
+
- A container sandbox on a machine without the runtime raises `Nexo::ConfigurationError`
|
|
44
|
+
naming the missing command, where it raised a bare `Errno::ENOENT`.
|
|
45
|
+
|
|
46
|
+
### Added
|
|
47
|
+
|
|
48
|
+
- **`tools X, capability: :write, detail: ->(args) { … }`** says what identifies one call of a
|
|
49
|
+
gated tool. Without it the identity is the tool and all its arguments, so a free-text
|
|
50
|
+
argument made every attempt a new call that had to be approved again.
|
|
51
|
+
- **`:tool_declined`**: a call a recorded decision refuses is reported to the prompt's block
|
|
52
|
+
and logged on a run as `agent_tool_declined`. ruby_llm answers such a call itself, so it
|
|
53
|
+
used to leave no trace.
|
|
54
|
+
- **Remembered approvals.** A decision keyed `"write:*"` (or `"mcp:<tool>:*"`) answers every
|
|
55
|
+
later call of that kind, and `resume(id, approved: true, remember: true)` files one. The
|
|
56
|
+
exact call's own decision still wins.
|
|
57
|
+
- **`delete_file`**, for a sandbox that can delete (`Sandbox#delete` on Virtual, Local and
|
|
58
|
+
Container), gated as `:write`.
|
|
59
|
+
- **`provider_tools :web_search, capability: :search`** on an agent attaches a tool that runs
|
|
60
|
+
on the provider's servers, but only when the agent's permissions allow that capability for
|
|
61
|
+
every call (`:auto`, or listed in `allow:`): Nexo never sees those calls, so it cannot ask
|
|
62
|
+
about one. New `Permissions#always_allows?`.
|
|
63
|
+
- **`Agent#mcp_resource_templates`** and **`Agent#mcp_prompt_suggestions`**.
|
|
64
|
+
- `RunStore::Memory#all`. `Nexo::Workflow::RETRYABLE` is reachable as a constant.
|
|
65
|
+
- `Nexo::ApprovalRequired#transcript`, `Nexo::InputRequired#transcript`, `Permissions#on_decline`.
|
|
66
|
+
- **Twelve examples.** One for each headline 0.16 feature — `retry_and_cancel`,
|
|
67
|
+
`confined_shell`, `usage_report`, `tool_question`, `multiple_approvals`, `llm_options`,
|
|
68
|
+
`deferred_tools` — and five after the templates Vercel's Eve ships: `support_agent`,
|
|
69
|
+
`data_analyst`, `software_factory`, `marketing_team`, `company_brain` (with a small MCP
|
|
70
|
+
server of its own for resources).
|
|
71
|
+
|
|
72
|
+
### Changed
|
|
73
|
+
|
|
74
|
+
- `examples/inbox_digest_task.rb` triages three staged files, so it runs with nothing but a
|
|
75
|
+
model; `inbox_digest.rb` and `inbox_digest_http.rb`, which needed a Gmail MCP server, are
|
|
76
|
+
removed. `news_search.rb` ships a stand-in search backend so it runs.
|
|
77
|
+
|
|
78
|
+
### Verified
|
|
79
|
+
|
|
80
|
+
- **Against Anthropic** (`claude-haiku-5-5`; `test/live_smoke_test.rb -n /anthropic/`): deferred
|
|
81
|
+
tools found through the provider's own tool search, with no call to ruby_llm's
|
|
82
|
+
`tool_search`; a session with automatic compaction switched on in the `llm` block (the
|
|
83
|
+
request is accepted and the session remembers; the conversation was too short to make the
|
|
84
|
+
provider compact anything); and a workflow that suspends for approval, resumes, and writes
|
|
85
|
+
its file with exactly one `write_file` call.
|
|
86
|
+
- Every example, on a local model through an OpenAI-compatible server.
|
|
87
|
+
|
|
88
|
+
### Still declined, with the reason
|
|
89
|
+
|
|
90
|
+
- **`code_execution` (`run_code`).** ruby_llm builds that tool inside the chat with private
|
|
91
|
+
wiring and attaches it outside `with_tools`, so no gate can wrap it. It stays refused in
|
|
92
|
+
the `llm` block. The gated `Shell` tool, in a confined or container sandbox, is Nexo's way
|
|
93
|
+
to run code.
|
|
94
|
+
- **`file_store`** stays refused: the agent's sandbox is the store.
|
|
95
|
+
- **Push updates for MCP tasks (`listen`).** Tasks are polled. Nothing here could be tested
|
|
96
|
+
against a server that pushes.
|
|
97
|
+
|
|
98
|
+
Not exercised: OpenAI's own tool search and compaction (no key), a compaction that
|
|
99
|
+
actually fires, and compaction on a persisted chat.
|
|
100
|
+
|
|
101
|
+
### Fixed
|
|
102
|
+
|
|
103
|
+
- **Examples could not run on a local model.** Eight live examples declared only
|
|
104
|
+
`model ENV.fetch("NEXO_MODEL")`, so a model outside ruby_llm's registry (the Ollama tag
|
|
105
|
+
their own headers suggest) raised "Unknown model". They now take `NEXO_PROVIDER` too
|
|
106
|
+
(`examples/support/model.rb`). `approval_agent.rb` wrote its demo file into the directory it
|
|
107
|
+
was run from; it uses a temporary one.
|
|
108
|
+
- Docs only: `docs/workflows.md` said the interrupted-run sweep skips the Disk store,
|
|
109
|
+
`docs/loops.md` still described the removed `:turn_limit_exceeded` event, and
|
|
110
|
+
`examples/mcp_filesystem.rb` said an unlisted MCP tool returns an error when it is not
|
|
111
|
+
attached at all.
|
|
112
|
+
|
|
3
113
|
## [0.16.1] - 2026-11-27
|
|
4
114
|
|
|
5
115
|
### Added
|
data/docs/durable-workflows.md
CHANGED
|
@@ -204,9 +204,10 @@ Booking.resume(run.id, answers: {"book:seat" => "aisle"})
|
|
|
204
204
|
```
|
|
205
205
|
|
|
206
206
|
Answers accumulate on the run (`"__answers__"`), like approvals: a later, different question
|
|
207
|
-
suspends it again.
|
|
208
|
-
|
|
209
|
-
|
|
207
|
+
suspends it again. The resume carries the paused conversation on (0.17): the tool that asked
|
|
208
|
+
is given the answer and the model is not asked again. `ruby_llm` re-enters a tool that calls
|
|
209
|
+
`ask` from the top with the answer in hand, so code before the `ask` runs again; keep side
|
|
210
|
+
effects after it. An answer for a key that was not asked is ignored.
|
|
210
211
|
|
|
211
212
|
## Durable **agent** approval — `:approve` (bridge a mid-run gate to a suspend)
|
|
212
213
|
|
|
@@ -281,22 +282,31 @@ resumed.status # => "done" (the gate allowed the
|
|
|
281
282
|
durable, cross-process sibling for `run_later`/`resume_later`.
|
|
282
283
|
|
|
283
284
|
**Caveats (read before relying on it):**
|
|
284
|
-
- **
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
285
|
+
- **The paused conversation carries on (0.17).** When `run_agent` suspends, the conversation
|
|
286
|
+
so far is saved with the run under `"__chat__"`. The resume restores it and continues:
|
|
287
|
+
the held call runs (or is refused), a tool that ran before the pause does **not** run again,
|
|
288
|
+
and the model is asked only for what comes next. Before 0.17 the prompt was asked again
|
|
289
|
+
from the start, which could run a tool twice. Two limits remain: the workflow's own
|
|
290
|
+
`#call` is still re-entered from the top, so work outside a `checkpoint` and outside the
|
|
291
|
+
paused `run_agent` runs again; and a run suspended by an older version has no saved
|
|
292
|
+
conversation and is asked again.
|
|
293
|
+
- **Say what identifies a call.** An approval is filed under the tool and its arguments. For
|
|
294
|
+
a tool with a free-text argument, declare the part that matters:
|
|
295
|
+
`tools IssueRefund, capability: :write, detail: ->(args) { "refund #{args[:order]}" }`.
|
|
296
|
+
- **Approve a kind of call once.** `resume(id, approved: true, remember: true)` also answers
|
|
297
|
+
every later call with the same capability (or the same MCP tool) in that run.
|
|
288
298
|
- **One answer decides one call.** `resume(approved:)` answers the call recorded under
|
|
289
299
|
`run.state["__approval__"]`, and nothing else. The answer is filed in
|
|
290
300
|
`run.state["__approvals__"]` under that call's key (capability plus path, command or URL; for
|
|
291
301
|
an MCP tool, its name plus a digest of the arguments). A *different* gated call later in the
|
|
292
302
|
same prompt **suspends again**, and the next resume decides it. Before 0.14 the first answer
|
|
293
303
|
silently applied to every later call.
|
|
294
|
-
- **A
|
|
295
|
-
|
|
296
|
-
`a.txt`, that is a new call and the run suspends for it. This is the safe direction.
|
|
304
|
+
- **A declined call is on the record.** It is logged as `agent_tool_declined`, with the tool
|
|
305
|
+
and its arguments.
|
|
297
306
|
- **`approved:` with nothing pending approves nothing.** An answer is recorded only when a call
|
|
298
307
|
is waiting.
|
|
299
|
-
- **Cross-process approval needs
|
|
308
|
+
- **Cross-process approval needs a durable store** (ActiveRecord with ActiveJob, or the Disk
|
|
309
|
+
store for a single-machine program), like all durable resume.
|
|
300
310
|
In-process `resume` works with the Memory store; a Memory run does not survive the process.
|
|
301
311
|
- **It depends on `ruby_llm`'s approval hooks.** The chat asks the registered tool
|
|
302
312
|
`requires_approval?(tool_call)` and reads its `approval_resolver` (verified on 2.2.3 through
|
|
@@ -330,10 +340,11 @@ capture, so this is **not** replay:
|
|
|
330
340
|
retried.
|
|
331
341
|
- **Checkpoint values must be json-serializable** — they round-trip the store exactly
|
|
332
342
|
like `result`/`events`.
|
|
333
|
-
- **Cross-process resume needs the
|
|
334
|
-
in-memory store resumes only *in-process
|
|
335
|
-
|
|
336
|
-
|
|
343
|
+
- **Cross-process resume needs a store that outlives the process.** A run suspended under
|
|
344
|
+
the in-memory store resumes only *in-process*. Across processes on several machines, use
|
|
345
|
+
the ActiveRecord store with a shared database. For a single-machine program such as a CLI,
|
|
346
|
+
`Nexo::RunStore::Disk.new(dir:)` keeps each run as a file; its claim is atomic within one
|
|
347
|
+
process only, so do not point two workers at one directory.
|
|
337
348
|
- **Never `suspend!` inside a `checkpoint` block** (undefined — unsupported), and
|
|
338
349
|
never name a checkpoint `"__suspend__"` (reserved for the suspend metadata) or
|
|
339
350
|
`"__approval__"` (reserved for the pending approval call — see the durable-approval
|
data/docs/loops.md
CHANGED
|
@@ -57,9 +57,9 @@ Things to know:
|
|
|
57
57
|
- **Upgrading from 0.12:** `max_turns` used to be telemetry only — a run that passed it
|
|
58
58
|
kept going. It now stops. If a legitimate run needs more rounds, raise the number.
|
|
59
59
|
- `max_turns: nil` runs uncapped. Use it only for trusted workloads.
|
|
60
|
-
-
|
|
61
|
-
`
|
|
62
|
-
|
|
60
|
+
- There is no event for it. The `:turn_limit_exceeded` event was removed in 0.16; rescue
|
|
61
|
+
`RubyLLM::ToolRoundLimitError`. One round can hold several tool calls, and
|
|
62
|
+
`Nexo.config.tool_calls_per_round` (default 20) bounds those.
|
|
63
63
|
- The cap counts rounds, not time or tokens. Bound those inside your own tools (a read
|
|
64
64
|
tool that accepts at most N ids) or with your provider's limits.
|
|
65
65
|
|
|
@@ -72,6 +72,7 @@ Things to know:
|
|
|
72
72
|
| `:tool_call` | `RubyLLM::ToolCall` | before each tool call |
|
|
73
73
|
| `:tool_progress` | `{tool_call:, progress:}` — a `RubyLLM::Progress` (`message`, `value`, `total`) | when a tool reports progress (0.16) |
|
|
74
74
|
| `:tool_result` | the tool's return value | after each tool call |
|
|
75
|
+
| `:tool_declined` | `RubyLLM::ToolCall` | when a recorded decision refuses a call under `:approve` (0.17); no `:tool_call` or `:tool_result` follows |
|
|
75
76
|
| `:fallback` | `RubyLLM::Fallback` (`from`, `to`, `error`) | after a request moved to a fallback model declared in the `llm` block (0.16) |
|
|
76
77
|
| `:done` | the final `RubyLLM::Message` | when the prompt ends |
|
|
77
78
|
| `:usage` | `{tokens: {input_tokens:, output_tokens:, …}, cost:}` | once per prompt, last, **even when the prompt raises** (0.16) |
|
|
@@ -125,8 +126,10 @@ These facts are not taken on trust: `test/real_loop_test.rb` drives `ruby_llm`'s
|
|
|
125
126
|
conversation loop with scripted model replies and asserts the permission gate, the MCP
|
|
126
127
|
gate, the turn cap, and approval suspension end to end.
|
|
127
128
|
|
|
128
|
-
`
|
|
129
|
-
|
|
129
|
+
`Local#shell` runs a command through `Nexo::Sandboxes::Subprocess`: in its own process group,
|
|
130
|
+
with only the environment it is given, and with the whole group killed when the timeout
|
|
131
|
+
passes. (`Timeout.timeout` around `Open3.capture3` reports a timeout without stopping the
|
|
132
|
+
command, which is what Nexo did until 0.14.)
|
|
130
133
|
|
|
131
134
|
## Live smoke (optional)
|
|
132
135
|
|
data/docs/mcp.md
CHANGED
|
@@ -191,6 +191,7 @@ itself (the tools the model then calls are gated as always):
|
|
|
191
191
|
|
|
192
192
|
```ruby
|
|
193
193
|
agent.mcp_prompts(:github).map(&:name) # => ["code_review", …]
|
|
194
|
+
agent.mcp_prompt_suggestions(:github, :code_review, language: "ru") # => ["ruby", "rust"] (0.17)
|
|
194
195
|
agent.prompt(agent.mcp_prompt(:github, :code_review, code: diff))
|
|
195
196
|
```
|
|
196
197
|
|
|
@@ -209,8 +210,9 @@ mcp :builds, transport: :http, url: "https://mcp.example.com/mcp", tasks: true
|
|
|
209
210
|
|
|
210
211
|
The prompt then waits for the task, checking at the interval the server asks for; the
|
|
211
212
|
server's status messages arrive as `:tool_progress` events. After
|
|
212
|
-
`Nexo.config.mcp_task_timeout` seconds (default `300`) the task is cancelled and
|
|
213
|
-
|
|
213
|
+
`Nexo.config.mcp_task_timeout` seconds (default `300`) the task is cancelled and its call is
|
|
214
|
+
answered with an error, so the model hears it and the prompt goes on (0.17; before, the
|
|
215
|
+
prompt failed). `Workflow.cancel` cancels the task too. The task is held in memory: if
|
|
214
216
|
the process dies while it waits, a retry makes the call again and the server starts a new
|
|
215
217
|
task. Without `tasks: true` the extension is not declared and a server answers in one go.
|
|
216
218
|
|
data/docs/skills.md
CHANGED
|
@@ -58,13 +58,25 @@ Referencing a skill that does not exist raises `Nexo::Error` naming the missing
|
|
|
58
58
|
> longer used (and it pins `ruby_llm` 1.x). The `skills` macro, `Nexo::Skills.find` and
|
|
59
59
|
> `Nexo::Skills.materialize` are unchanged.
|
|
60
60
|
|
|
61
|
-
###
|
|
61
|
+
### What comes from `ruby_llm`, and what does not
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
Since 0.17 a skill is **parsed** by `ruby_llm`'s own `RubyLLM::Skill`, which follows the
|
|
64
|
+
Agent Skills specification:
|
|
65
|
+
|
|
66
|
+
- `name` and `description` are required.
|
|
67
|
+
- The name is lower-case letters, digits and single hyphens (`email-triage`), and equal to
|
|
68
|
+
the folder's name.
|
|
69
|
+
- `compatibility`, `license`, `allowed-tools` and `metadata` are read and checked.
|
|
70
|
+
|
|
71
|
+
What Nexo does **not** take is how a skill reaches the model. `ruby_llm` (`chat.with_skills`)
|
|
72
|
+
gives the model a `load_skill` tool that reads the skill's files from the host when asked.
|
|
73
|
+
Nexo's rule is that a skill adds instructions and nothing else: the text goes into the
|
|
74
|
+
system prompt, and the model gets nothing new to call.
|
|
75
|
+
|
|
76
|
+
**Coming from underscore names.** Before 0.17 Nexo read skills itself and accepted
|
|
77
|
+
`email_triage`. Rename the folder and its `name:` to `email-triage`. `skills :email_triage`
|
|
78
|
+
keeps working, because a name given with underscores resolves to the hyphenated folder.
|
|
79
|
+
Until 0.18 an underscore-named skill still loads and prints a notice saying what to rename.
|
|
68
80
|
|
|
69
81
|
## Say what a skill needs with `compatibility:`
|
|
70
82
|
|
data/docs/tools.md
CHANGED
|
@@ -61,7 +61,7 @@ class Editor < Nexo::Agent
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
Editor.new.chat.tools.keys
|
|
64
|
-
# => [:list_files, :read_file, :search_files, :write_file, :edit_file]
|
|
64
|
+
# => [:list_files, :read_file, :search_files, :write_file, :edit_file, :delete_file]
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
Reading, listing and searching are `:read`; writing and editing are `:write`, and under
|
|
@@ -75,7 +75,8 @@ run with the file's path as the detail.
|
|
|
75
75
|
- **Dotfiles are not listed.**
|
|
76
76
|
- **Listing goes through the sandbox.** `:virtual` and `:local` answer directly. A container
|
|
77
77
|
or remote sandbox runs one `find`, and reads each file to report its size.
|
|
78
|
-
-
|
|
78
|
+
- **`delete_file`** is attached with the writing tools (0.17), on a sandbox that can delete:
|
|
79
|
+
`:virtual`, `:local` and containers. A custom sandbox without `#delete` gets none.
|
|
79
80
|
- The tool classes are internal to `ruby_llm`; Nexo's tests drive them through the real
|
|
80
81
|
loop, which is what will catch a change there.
|
|
81
82
|
|
|
@@ -83,7 +84,7 @@ The `file_tools` macro chooses the set per agent, and `Nexo.config.file_tools` f
|
|
|
83
84
|
|
|
84
85
|
| `file_tools` | What the agent gets |
|
|
85
86
|
|---|---|
|
|
86
|
-
| `:core` (default) | `list_files`, `read_file`, `search_files`, `write_file`, `edit_file` |
|
|
87
|
+
| `:core` (default) | `list_files`, `read_file`, `search_files`, and for an agent that may write `write_file`, `edit_file`, `delete_file` |
|
|
87
88
|
| `:none` | No file tools. For an agent whose files come from somewhere else, such as a filesystem MCP server. |
|
|
88
89
|
|
|
89
90
|
### An MCP server with the same tool names
|
|
@@ -146,6 +147,37 @@ name followed by its arguments as JSON.
|
|
|
146
147
|
|
|
147
148
|
Without `capability:` the tool runs ungated. That is right only for a tool with no side effects.
|
|
148
149
|
|
|
150
|
+
### What identifies a call — `detail:`
|
|
151
|
+
|
|
152
|
+
Under `:ask` and `:approve` a gated call is identified by the tool and **all** its arguments.
|
|
153
|
+
That is right for `write_file` (the path) and wrong for a tool with a free-text argument: a
|
|
154
|
+
model words `reason:` differently each time, so each attempt looks like a new call. Say
|
|
155
|
+
which part matters:
|
|
156
|
+
|
|
157
|
+
```ruby
|
|
158
|
+
tools IssueRefund, capability: :write, detail: ->(args) { "refund $#{args[:amount]} on #{args[:order]}" }
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
The callable gets the call's arguments with Symbol keys and returns a String. It is what
|
|
162
|
+
`ask_when` and `on_ask` are told, and what an approval is filed under.
|
|
163
|
+
|
|
164
|
+
### Tools that run on the provider — `provider_tools`
|
|
165
|
+
|
|
166
|
+
Some tools run on the provider's servers: its own web search, for one. Nexo never sees their
|
|
167
|
+
calls, so it cannot ask about one or refuse one. An agent may have such a tool only when its
|
|
168
|
+
permissions allow the capability for **every** call:
|
|
169
|
+
|
|
170
|
+
```ruby
|
|
171
|
+
class Researcher < Nexo::Agent
|
|
172
|
+
permissions Nexo::Permissions.new(mode: :read_only, allow: %i[read glob search])
|
|
173
|
+
provider_tools :web_search, capability: :search
|
|
174
|
+
end
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Under `:auto`, or with the capability in `allow:`, the tool is attached. Under `:read_only`
|
|
178
|
+
without it, and under `:ask` and `:approve` (which decide call by call), it is left out.
|
|
179
|
+
`capability:` is required. Declaring `provider_tools` inside the `llm` block is refused.
|
|
180
|
+
|
|
149
181
|
### A long catalogue — `defer: true`
|
|
150
182
|
|
|
151
183
|
```ruby
|
data/docs/workflows.md
CHANGED
|
@@ -107,8 +107,8 @@ is meant for (a CLI's own history) and is wrong for a busy multi-worker queue
|
|
|
107
107
|
is what the ActiveRecord backend is for. `claim_for_resume!` re-reads from disk, so a
|
|
108
108
|
stale in-memory copy cannot win a claim, but it is atomic **within** a process only.
|
|
109
109
|
Runs are never pruned: retention is the host's policy and `dir` is a plain directory
|
|
110
|
-
it can manage. `Workflow.reconcile_interrupted!` sweeps
|
|
111
|
-
|
|
110
|
+
it can manage. `Workflow.reconcile_interrupted!` sweeps this store too (since 0.16), so a CLI
|
|
111
|
+
killed mid-run can mark its run `"interrupted"` on the next start and `Workflow.retry` it.
|
|
112
112
|
|
|
113
113
|
## Input staging and artifacts
|
|
114
114
|
|
data/examples/README.md
CHANGED
|
@@ -1,51 +1,84 @@
|
|
|
1
1
|
# Nexo examples
|
|
2
2
|
|
|
3
|
-
Each example is
|
|
3
|
+
Each example is one runnable script. Run them from the repo root:
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
any ruby_llm-supported model id; nothing is provider-specific) and sometimes
|
|
9
|
-
an external service (an MCP server, docker, an API key).
|
|
5
|
+
```sh
|
|
6
|
+
ruby -Ilib examples/<name>.rb
|
|
7
|
+
```
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
- **Offline** examples need no model, no network and no key.
|
|
10
|
+
- **Live** examples need `NEXO_LIVE=1` and a tool-calling model. `NEXO_MODEL` takes
|
|
11
|
+
any model id `ruby_llm` knows. For a model its registry does not list — a local
|
|
12
|
+
Ollama tag, a self-hosted build — also set `NEXO_PROVIDER`:
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
```sh
|
|
15
|
+
NEXO_LIVE=1 NEXO_MODEL=gemma3:12b NEXO_PROVIDER=ollama ruby -Ilib examples/chat_session.rb
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`OLLAMA_API_BASE` and `API_KEY` point the `ollama` provider at any local
|
|
19
|
+
OpenAI-compatible server (default `http://127.0.0.1:11434/v1`, no key).
|
|
20
|
+
|
|
21
|
+
## Offline — start here
|
|
14
22
|
|
|
15
23
|
| Example | Shows |
|
|
16
24
|
|---|---|
|
|
17
|
-
| [`
|
|
18
|
-
| [`
|
|
25
|
+
| [`approval_workflow.rb`](approval_workflow.rb) | A run that pauses for a person: `checkpoint`, `suspend!`, `resume` |
|
|
26
|
+
| [`retry_and_cancel.rb`](retry_and_cancel.rb) | `Workflow.retry` finishing a failed run without repeating its checkpoints; `Workflow.cancel` |
|
|
27
|
+
| [`artifact_from_template.rb`](artifact_from_template.rb) | Staging files into a run's sandbox and rendering a named artifact from an ERB template |
|
|
28
|
+
| [`confined_shell.rb`](confined_shell.rb) | The local shell in an OS sandbox: what it can write, read and reach, next to the unconfined one (needs `mxc`) |
|
|
19
29
|
|
|
20
|
-
## Live —
|
|
30
|
+
## Live — one agent
|
|
21
31
|
|
|
22
|
-
| Example | Shows |
|
|
32
|
+
| Example | Shows | Also needs |
|
|
23
33
|
|---|---|---|
|
|
24
|
-
| [`code_reviewer.rb`](code_reviewer.rb) | The
|
|
25
|
-
| [`chat_session.rb`](chat_session.rb) |
|
|
26
|
-
| [`
|
|
27
|
-
| [`
|
|
28
|
-
| [`
|
|
34
|
+
| [`code_reviewer.rb`](code_reviewer.rb) | The smallest agent: a model, a skill, a read-only sandbox | — |
|
|
35
|
+
| [`chat_session.rb`](chat_session.rb) | `Nexo::Session`: a conversation that remembers earlier turns | — |
|
|
36
|
+
| [`llm_options.rb`](llm_options.rb) | The `llm` block: a fallback model, a temperature, a context budget, and the `:fallback` event | — |
|
|
37
|
+
| [`deferred_tools.rb`](deferred_tools.rb) | `tools …, defer: true`: a catalogue the model searches instead of carrying | — |
|
|
38
|
+
| [`usage_report.rb`](usage_report.rb) | Tokens and cost per prompt (`:usage`) and per run (`Workflow.usage`) | — |
|
|
39
|
+
| [`news_summary.rb`](news_summary.rb) | Web fetch limited to an allow-list of hosts | network |
|
|
40
|
+
| [`news_search.rb`](news_search.rb) | A search backend you inject, plus fetch (ships with a stand-in backend) | network |
|
|
41
|
+
| [`container_review.rb`](container_review.rb) | An agent whose tools run in a locked-down container | `docker` or Apple `container` |
|
|
42
|
+
|
|
43
|
+
## Live — a person in the loop
|
|
44
|
+
|
|
45
|
+
| Example | Shows |
|
|
46
|
+
|---|---|
|
|
47
|
+
| [`approval_agent.rb`](approval_agent.rb) | `permissions :approve`: a write suspends the run until someone decides |
|
|
48
|
+
| [`multiple_approvals.rb`](multiple_approvals.rb) | Several calls waiting at once, approved and declined by key |
|
|
49
|
+
| [`tool_question.rb`](tool_question.rb) | A tool that asks the person a question; the run resumes with the answer |
|
|
50
|
+
| [`data_analyst.rb`](data_analyst.rb) | `:ask`: SQL reads run freely, a statement that changes data is put to a hook (needs `sqlite3`) |
|
|
29
51
|
|
|
30
52
|
## Live — MCP
|
|
31
53
|
|
|
32
|
-
| Example | Shows |
|
|
54
|
+
| Example | Shows | Also needs |
|
|
33
55
|
|---|---|---|
|
|
34
|
-
| [`mcp_filesystem.rb`](mcp_filesystem.rb) |
|
|
35
|
-
| [`
|
|
36
|
-
| [`
|
|
37
|
-
| [`inbox_digest_task.rb`](inbox_digest_task.rb) | The digest as a Workflow **Task**: `agent` macro + `run_agent` + a named artifact (Spec 8) | same as `inbox_digest.rb` |
|
|
56
|
+
| [`mcp_filesystem.rb`](mcp_filesystem.rb) | An MCP server behind the allow-list: reads allowed, writes not offered. **Start here for MCP.** | `npx` |
|
|
57
|
+
| [`company_brain.rb`](company_brain.rb) | MCP resources (`resources: true`) and a session: answers from documents, with the source | — (ships its own small server) |
|
|
58
|
+
| [`mcp_oauth.rb`](mcp_oauth.rb) | Signing in to an OAuth MCP server from a terminal, with stored credentials | an OAuth MCP server (`NEXO_MCP_URL`) |
|
|
38
59
|
|
|
39
|
-
## Live —
|
|
60
|
+
## Live — several agents in a workflow
|
|
40
61
|
|
|
41
|
-
| Example | Shows |
|
|
42
|
-
|
|
43
|
-
| [`
|
|
62
|
+
| Example | Shows |
|
|
63
|
+
|---|---|
|
|
64
|
+
| [`inbox_digest_task.rb`](inbox_digest_task.rb) | A Task: `agent` + `run_agent` over staged files, with the result kept as an artifact |
|
|
65
|
+
| [`support_agent.rb`](support_agent.rb) | A policy in a skill, a lookup tool, and two tools that act and wait for approval; the approved call runs once, and `detail:` says what identifies it |
|
|
66
|
+
| [`software_factory.rb`](software_factory.rb) | A coder and a read-only reviewer with the tests run as plain code between them; `emit_agent_event` |
|
|
67
|
+
| [`marketing_team.rb`](marketing_team.rb) | Three specialists working one brief concurrently with `checkpoint_all`, then an editor |
|
|
68
|
+
|
|
69
|
+
`support_agent`, `data_analyst`, `software_factory`, `marketing_team` and
|
|
70
|
+
`company_brain` are Nexo versions of the templates [Eve](https://vercel.com/eve)
|
|
71
|
+
ships. Eve's channels (Slack, Discord), schedules and subagents have no
|
|
72
|
+
counterpart in Nexo: a channel and a schedule belong to your application, and
|
|
73
|
+
routing between agents is plain Ruby in a workflow.
|
|
44
74
|
|
|
45
|
-
##
|
|
75
|
+
## Support files
|
|
46
76
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
77
|
+
- `skills/` — the `SKILL.md` packages the examples use (`email-triage`, `news-summary`,
|
|
78
|
+
`refunds`, `ruby-code-review`). The examples point `Nexo.config.skills_path` here;
|
|
79
|
+
in a Rails app the default is `app/skills`.
|
|
80
|
+
- `support/model.rb` — reads `NEXO_MODEL` and `NEXO_PROVIDER` for the live examples.
|
|
81
|
+
- `support/handbook_server.rb`, `support/handbook/` — the small MCP server and the
|
|
82
|
+
pages `company_brain.rb` reads.
|
|
50
83
|
|
|
51
84
|
See also [`rails_usage.md`](rails_usage.md) for the Rails host-app walkthrough.
|
data/examples/approval_agent.rb
CHANGED
|
@@ -24,18 +24,21 @@
|
|
|
24
24
|
# so the suspended run survives across processes, and resume from a controller/job
|
|
25
25
|
# once a human clicks "approve" (`MyWorkflow.resume_later(run.id, approved: true)`).
|
|
26
26
|
require "nexo"
|
|
27
|
+
require "tmpdir"
|
|
28
|
+
require_relative "support/model"
|
|
27
29
|
|
|
28
|
-
# A local
|
|
29
|
-
# :approve gates that write for a human decision.
|
|
30
|
+
# A local sandbox in a throwaway directory — the agent writes a file the model
|
|
31
|
+
# chooses; :approve gates that write for a human decision.
|
|
32
|
+
WORKSPACE = Dir.mktmpdir("nexo-approval")
|
|
30
33
|
class Scribe < Nexo::Agent
|
|
31
|
-
model
|
|
34
|
+
Examples.model(self, default: "gpt-4o-mini")
|
|
32
35
|
sandbox :local
|
|
33
36
|
permissions :approve # every write/shell needs a human decision (undecided ⇒ suspend)
|
|
34
|
-
instructions "You write short files when asked. Use the
|
|
37
|
+
instructions "You write short files when asked. Use the write_file tool."
|
|
35
38
|
end
|
|
36
39
|
|
|
37
40
|
class ApprovedWrite < Nexo::Workflow
|
|
38
|
-
cwd
|
|
41
|
+
cwd WORKSPACE # not the directory you run this from
|
|
39
42
|
sandbox :local
|
|
40
43
|
agent Scribe
|
|
41
44
|
|
|
@@ -56,9 +59,20 @@ if __FILE__ == $PROGRAM_NAME
|
|
|
56
59
|
|
|
57
60
|
# 2) A human approves. Resume threads {approved: true} into the agent, so the
|
|
58
61
|
# same gate now allows and the run completes. (Denying — resume(approved:
|
|
59
|
-
# false) — instead
|
|
60
|
-
#
|
|
62
|
+
# false) — instead has the call refused; the model adapts and the run still
|
|
63
|
+
# completes "done", without the write.)
|
|
64
|
+
#
|
|
65
|
+
# One answer decides one call, and a resume asks the model again: if it asks
|
|
66
|
+
# for something different this time, that is a new call and the run suspends
|
|
67
|
+
# for it. So a host answers until the run stops asking.
|
|
61
68
|
resumed = ApprovedWrite.resume(run.id, approved: true)
|
|
69
|
+
2.times do
|
|
70
|
+
break unless resumed.status == "suspended"
|
|
71
|
+
|
|
72
|
+
puts "asked again for: #{resumed.state["__approval__"].inspect}"
|
|
73
|
+
resumed = ApprovedWrite.resume(resumed.id, approved: true)
|
|
74
|
+
end
|
|
62
75
|
puts "status after resume: #{resumed.status}" # => "done"
|
|
63
76
|
puts "result: #{resumed.result.inspect}"
|
|
77
|
+
puts "written: #{File.join(WORKSPACE, "notes/approval_demo.txt")}"
|
|
64
78
|
end
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
# ruby -Ilib examples/artifact_from_template.rb
|
|
9
9
|
#
|
|
10
10
|
# This is the mechanics of use case #2 (file-upload -> artifact) with the "improve" step
|
|
11
|
-
# left out (that needs an agent — see
|
|
11
|
+
# left out (that needs an agent — see examples/inbox_digest_task.rb).
|
|
12
12
|
require "nexo"
|
|
13
13
|
|
|
14
14
|
class BuildDigest < Nexo::Workflow
|
data/examples/chat_session.rb
CHANGED
|
@@ -17,9 +17,10 @@
|
|
|
17
17
|
# A session adds only memory + addressability. The agent's sandbox, permissions
|
|
18
18
|
# (default :read_only), skills, MCP, and fetch_allow all apply unchanged.
|
|
19
19
|
require "nexo"
|
|
20
|
+
require_relative "support/model"
|
|
20
21
|
|
|
21
22
|
class Assistant < Nexo::Agent
|
|
22
|
-
model
|
|
23
|
+
Examples.model(self)
|
|
23
24
|
instructions "You are a helpful assistant. Remember what the user tells you."
|
|
24
25
|
end
|
|
25
26
|
|
data/examples/code_reviewer.rb
CHANGED
|
@@ -38,9 +38,10 @@ if __FILE__ == $PROGRAM_NAME
|
|
|
38
38
|
|
|
39
39
|
totals = Hash.new(0)
|
|
40
40
|
show_stats = ->(response) do
|
|
41
|
-
|
|
42
|
-
totals[:
|
|
43
|
-
|
|
41
|
+
tokens = response.tokens # ruby_llm 2: a message's usage is on #tokens
|
|
42
|
+
totals[:input] += tokens.input.to_i
|
|
43
|
+
totals[:output] += tokens.output.to_i
|
|
44
|
+
puts "— #{response.model_id}: in=#{tokens.input} out=#{tokens.output}"
|
|
44
45
|
end
|
|
45
46
|
|
|
46
47
|
# Stage this very file into the agent's in-memory sandbox: the review target.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# A company assistant that answers from the company's own documents, says which
|
|
4
|
+
# one it used, and remembers the conversation. (After Eve's "Company Brain"
|
|
5
|
+
# template, without the Slack channel: a channel is your application's job.)
|
|
6
|
+
#
|
|
7
|
+
# NEXO_LIVE=1 NEXO_MODEL=gemma3:12b NEXO_PROVIDER=ollama ruby -Ilib examples/company_brain.rb
|
|
8
|
+
#
|
|
9
|
+
# What it shows:
|
|
10
|
+
#
|
|
11
|
+
# * MCP RESOURCES — a server offering things to read, not only tools to call.
|
|
12
|
+
# `resources: true` attaches `list_mcp_resources` and `read_mcp_resource`,
|
|
13
|
+
# which the agent must be allowed (`mcp_allow`) like any MCP tool.
|
|
14
|
+
# * `Nexo::Session` — a continuing conversation addressed by an id, so a later
|
|
15
|
+
# question can lean on an earlier one.
|
|
16
|
+
#
|
|
17
|
+
# The server is a 50-line script in examples/support/, serving the three pages in
|
|
18
|
+
# examples/support/handbook/. Point `command:` at a real MCP server to use yours.
|
|
19
|
+
require "nexo"
|
|
20
|
+
require_relative "support/model"
|
|
21
|
+
|
|
22
|
+
class CompanyBrain < Nexo::Agent
|
|
23
|
+
Examples.model(self)
|
|
24
|
+
file_tools :none # everything it knows comes from the server
|
|
25
|
+
|
|
26
|
+
mcp :handbook, transport: :stdio, command: RbConfig.ruby,
|
|
27
|
+
args: [File.expand_path("support/handbook_server.rb", __dir__), File.expand_path("support/handbook", __dir__)],
|
|
28
|
+
resources: true
|
|
29
|
+
mcp_allow "list_mcp_resources", "read_mcp_resource"
|
|
30
|
+
|
|
31
|
+
instructions "You answer questions about company policy from the handbook resources. List them, read the one " \
|
|
32
|
+
"that applies, and answer in two sentences. End with the resource you used, as (source: <uri>). " \
|
|
33
|
+
"If the handbook does not say, say so."
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
if __FILE__ == $PROGRAM_NAME
|
|
37
|
+
abort "set NEXO_LIVE=1 to run this live example" unless ENV["NEXO_LIVE"]
|
|
38
|
+
|
|
39
|
+
def ask(question)
|
|
40
|
+
session = Nexo::Session.resume(CompanyBrain, "team-platform") # the same thread each time
|
|
41
|
+
calls = []
|
|
42
|
+
answer = session.prompt(question) { |type, payload| calls << payload.name.to_s if type == :tool_call }
|
|
43
|
+
puts "Q: #{question}"
|
|
44
|
+
puts "A: #{answer.content}"
|
|
45
|
+
puts " (tools: #{calls.join(", ")})"
|
|
46
|
+
puts
|
|
47
|
+
ensure
|
|
48
|
+
session&.close
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
ask "How many days of paid leave do I get?"
|
|
52
|
+
ask "And how many of those can I carry over?" # "those" needs the first turn
|
|
53
|
+
ask "What is the budget for a team offsite?" # not in the handbook
|
|
54
|
+
end
|