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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6739e4be2c75c08ffb553133324b96b29d13e0212e21cc23c4cd6287316b3249
4
- data.tar.gz: d051ce3a0916cd5fb9328df9b893e5aad15b6f60c8d5c23bb9be8b3126da7285
3
+ metadata.gz: d344ac737c8cf5b8e0a4de3afe5745718e1794556941cdd0512bf8d4d83d1eed
4
+ data.tar.gz: 414c446feec2a6307444f64324205a599363879e82b33ef36bc2cd8ace80e4e8
5
5
  SHA512:
6
- metadata.gz: 94c1df2b9d56ab1c31aacd79a52473bf6ed3da9ba43d2e7403658fdee0e52bc31bded23181dbe7f60e82b4fd9b0f5e64c5d933de80cf99f546ca0982b883d878
7
- data.tar.gz: ca8829f2003854bd1c24e2e77739b0b4c62bd173ee0bd31297171ba017f2c1a02dd31f6fb9bb7ef938fc1c67a93229c407f5fbae06b29c4aee305552f6eba242
6
+ metadata.gz: cd25708a4c1f9c35ff84e361ae06fa6aaf52050e3f663cecda12506ae0ad91d1af0f60db48f24147bd2cd92278f702bbd8feb6b7e49e5c1f090d343ef82864ac
7
+ data.tar.gz: 11e729c9e4695a178029b5fd01ba9cf206358fb952fec64bfb255f75dce74b0bc6e27d15b3c3de6c6f620694dd7b1e60446a95be752579adbb7d4ac325d87b9b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,159 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.14.0] - 2026-11-26
4
+
5
+ A security release. Three guarantees Nexo documented did not hold and now do, and a tool
6
+ you wrote yourself can be gated like Nexo's own.
7
+
8
+ **Upgrading:** four changes can affect a host.
9
+
10
+ 1. **The local shell no longer inherits your environment.** If a command an agent runs on
11
+ `sandbox :local` relied on an inherited variable, pass it with `env:`.
12
+ 2. **`resume(approved:)` answers one call.** A workflow whose agent makes several gated calls
13
+ now suspends once per distinct call. A host that drove an agent directly with
14
+ `Agent.new(decision:)` is unaffected.
15
+ 3. **Under `:read_only`, MCP tools outside `mcp_allow` are no longer attached.** They were
16
+ always denied when called; the model just stops seeing them.
17
+ 4. **Tools added by overriding `#chat` now warn once.** Move them to the `tools` macro.
18
+
19
+ ### Fixed
20
+
21
+ - **`Sandboxes::Local#shell` leaked the whole process environment.** The documented narrowing
22
+ to `PATH`/`HOME`/`LANG` never happened: those were added on top of an inherited environment,
23
+ so any secret in the host's `ENV` was readable by a model-run command. The child process now
24
+ gets only the narrowed set plus explicit `env:` entries.
25
+ - **A shell timeout did not stop the command.** `Timeout::Error` was raised only after the
26
+ command finished by itself. The command now runs in its own process group, which is killed
27
+ when the timeout fires. `Tools::Shell` returns the timeout to the model as `{error:}` instead
28
+ of failing the run.
29
+ - **One approval approved everything after it.** `Workflow.resume(id, approved: true)` handed
30
+ the re-driven agent a single global decision, so every later `:approve`-gated call in that
31
+ prompt ran without asking; the guide said it would suspend again. Answers are now filed per
32
+ call under the reserved `__approvals__` state key, keyed by capability and detail (and a
33
+ digest of the arguments for MCP tools). A call with no answer suspends.
34
+ - **`sandbox :local, env: {...}`** dropped `env:` in the Hash form. Every option now reaches
35
+ `Sandboxes::Local`.
36
+ - **`Tools::Fetch` failed on hosts whose first address was unreachable.** Only the first
37
+ resolved address was tried, so a host with an IPv6 record failed on a machine with no IPv6
38
+ route. Each vetted address is now tried in turn (up to four), and only on connect errors.
39
+
40
+ ### Added
41
+
42
+ - **`tools` macro on `Nexo::Agent`** for tools of your own, with an optional `capability:`.
43
+ A tool declared with one is wrapped in the new `Nexo::GatedTool`, so the agent's permissions
44
+ decide every call, and it is left out of the schema when the mode could never allow it.
45
+ - **`Nexo.config.strict_tools`.** One `around_tool_call` block catches calls to tools Nexo did
46
+ not attach. Default `false`: the call runs and Nexo warns once per tool. `true` refuses it.
47
+ This becomes the default in 1.0.
48
+ - **`isolation: :confined` on `Sandboxes::Local`** runs shell commands in an OS sandbox through
49
+ `ruby_llm`'s sandbox contract (the `mxc` gem, a soft dependency): writes only inside `cwd`,
50
+ no home directory, no network. `readable:` grants extra paths; `isolation:` also accepts an
51
+ `MXC::Sandbox` or any object answering the contract. Verified on macOS; opt-in.
52
+ - **`Sandbox#hardening_gaps`** on every sandbox. `Local` reports an unconfined shell.
53
+ - **`Permissions#decisions`, `#with_decisions`, `::approval_key`, `#never_allows_mcp?`** and
54
+ `Nexo::ApprovalRequired#key`.
55
+ - **Runs execute inside `RubyLLM.workflow`**, so `ruby_llm`'s instrumentation and usage records
56
+ carry the Nexo run id. `checkpoint` and `run_agent` are steps of it. No outcome changes.
57
+
58
+ ### Deprecated
59
+
60
+ - `Permissions#decision`, `#with_decision` and `Agent.new(decision:)`: one answer for every
61
+ gated call. `Workflow#run_agent` no longer uses them. Use `decisions:`.
62
+
63
+ ### Decided against, for now
64
+
65
+ Recorded so they are not re-litigated without new facts (all read from ruby_llm 2.2.3):
66
+
67
+ - **The permission check did not move into `around_tool_call`.** A skipped call can only give
68
+ the model `"The <name> call did not run."`; the block's return value is ignored. Nexo's
69
+ denial messages cannot travel through it, so the hook is the backstop, not the gate.
70
+ - **`:approve` was not rebuilt on ruby_llm's tool approvals.** Those are durable only with
71
+ `acts_as_chat`; without ActiveRecord the pending state lives in memory. Nexo's approvals
72
+ work with any run store.
73
+ - **`Nexo::Agent` is not a `RubyLLM::Agent` subclass**, and `Session`, `WebSearch`,
74
+ `ReadTracker` and `OutputTruncator` stay: ruby_llm has no plain-Ruby equivalent of them.
75
+
76
+ ## [0.13.0] - 2026-11-26
77
+
78
+ Nexo now runs on ruby_llm 2.2. MCP comes from ruby_llm itself, skills need no extra gem,
79
+ and `max_turns` is a real cap.
80
+
81
+ ### Changed
82
+
83
+ - **`ruby_llm` is now pinned to the 2.2 line (`~> 2.2.0`, was `~> 1.16`).** Verified against
84
+ 2.2.3. ruby_llm 1.x is no longer supported; it ended at 1.16.0 and carries ReDoS
85
+ advisories that are fixed only in 2.0.
86
+
87
+ **Upgrading:** this is a breaking release for the host app's Gemfile and for any
88
+ `RubyLLM::Tool` you wrote yourself.
89
+
90
+ 1. Remove `gem "ruby_llm-mcp"` and `gem "ruby_llm-skills"`. `ruby_llm-mcp` defines the
91
+ same `RubyLLM::MCP` constant as ruby_llm 2.x and cannot be bundled with it; both gems
92
+ pin ruby_llm 1.x. Anything you were getting from them transitively (for example
93
+ `bigdecimal`) must now be declared by you.
94
+ 2. In your own tools, rename `param` to `parameter` and `desc:` to `description:`
95
+ (`params do` becomes `parameters do`). ruby_llm 2.0 removed the old names.
96
+ 3. A tool wrapper you wrote (for `wrap_mcp_tool`) must accept keywords:
97
+ `def call(**arguments)`. ruby_llm 2.x calls tools as `tool.call(**arguments)`, and the
98
+ schema reader is `parameters_schema`, not `params_schema`.
99
+ 4. If you use `Nexo::Session` on ActiveRecord, run ruby_llm's own schema upgrade
100
+ (`rails g ruby_llm:upgrade`, one minor at a time). ruby_llm 2.x keeps tool calls and
101
+ the model registry in its own `ruby_llm_*` tables; the host owns only `Chat` and
102
+ `Message`.
103
+ 5. Read ruby_llm's [upgrade guide](https://rubyllm.com/upgrading/) for everything outside
104
+ Nexo — notably that OpenAI now defaults to the Responses API.
105
+
106
+ - **`max_turns` is a hard cap.** `Agent#prompt`, `Session#prompt` and
107
+ `Workflow#run_agent` pass it to ruby_llm as `with_tool_options(rounds:)`. When a prompt
108
+ uses up its tool rounds, `RubyLLM::ToolRoundLimitError` is raised instead of the model
109
+ being asked again; inside a workflow that fails the run. It was telemetry only before.
110
+
111
+ **Upgrading:** a run that used to pass `max_turns` and keep going now stops. Raise the
112
+ number for runs that legitimately need more rounds, or pass `max_turns: nil` to run
113
+ uncapped. The `:turn_limit_exceeded` event is still emitted, once per prompt.
114
+
115
+ - **MCP uses ruby_llm's built-in client.** The `mcp` macro, `mcp_allow`, the fail-closed
116
+ gate, `wrap_mcp_tool` and `Nexo::MCP.build` are unchanged for callers. Three behaviours
117
+ differ, all inherited from ruby_llm:
118
+ - a callable `token:` is read again for **every request**, so a rotated token no longer
119
+ needs `agent.close` and a reconnect;
120
+ - a `:stdio` server starts with a short, safe environment — pass what it needs with
121
+ `env:`;
122
+ - a `:stdio` server's stderr is your process's stderr.
123
+
124
+ An unknown transport or a `:stdio` server with no `command:` now raises
125
+ `Nexo::ConfigurationError` when the server is built.
126
+
127
+ - **Skills are read by Nexo itself** (`Nexo::Skills::Skill`). `skills`, `Nexo::Skills.find`
128
+ and `Nexo::Skills.materialize` are unchanged. A `SKILL.md` without YAML front matter now
129
+ raises `Nexo::Error` naming the file. ruby_llm's own skills are not used: they reject
130
+ underscore names (`email_triage`) and work through a `load_skill` tool, where Nexo's rule
131
+ is that a skill adds instructions and nothing else.
132
+
133
+ - **Workflow events store tool arguments string-keyed** in both run stores. ruby_llm 2.x
134
+ hands them over with Symbol keys; the Memory store would otherwise have disagreed with
135
+ the ActiveRecord one.
136
+
137
+ ### Removed
138
+
139
+ - **`Nexo::Loops::AgentSDK`**, with `Agent#permission_mode`, `Agent#allowed_tools`,
140
+ `Agent::ALLOWED_TOOLS` and `Agent::PERMISSION_MODE_MAP`. The `ruby_llm-agent_sdk` gem it
141
+ wrapped was never published, so this path never ran against real code. Its one purpose,
142
+ a hard turn cap, is now `max_turns` on the default loop. `Nexo::Loop` remains as the seam
143
+ for a backend of your own.
144
+ - **`Nexo::MCP.load!` and `Nexo::Skills.load!`.** There is no optional gem left to load.
145
+ - The `ruby_llm-test`, `ruby_llm-skills` and `ruby_llm-mcp` development dependencies. The
146
+ suite scripts model replies with ruby_llm's own `RubyLLM::TestHelper`.
147
+
148
+ ### Added
149
+
150
+ - `test/real_loop_test.rb` drives ruby_llm's real conversation loop with scripted replies
151
+ and proves, end to end: a `:read_only` agent cannot reach the write tool, the MCP gate
152
+ denies a tool before it runs, `max_turns` stops a runaway loop, and an `:approve` gate
153
+ suspends a workflow and resumes it.
154
+ - `mcp` accepts `env:` and `directory:` for `:stdio` servers, and `command:` as an argv
155
+ Array.
156
+
3
157
  ## [0.12.0] - 2026-09-12
4
158
 
5
159
  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 skill loading, the tool-call loop, MCP, or structured output — those
13
- already live in the RubyLLM ecosystem (`ruby_llm` core, `ruby_llm-skills`, `ruby_llm-mcp`,
14
- `ruby_llm-schema`). Nexo **composes** them behind one front door and adds only the two pieces
15
- the ecosystem is missing:
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
- | [Loop backends](docs/loops.md) | RubyLLM vs AgentSDK, turn-cap caveat |
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) 1.16.x (`~> 1.16`) — the supported version is
98
- **1.16.0**; the upcoming ruby_llm 2.0 is not supported yet
99
- - [ruby_llm-skills](https://github.com/kieranklaassen/ruby_llm-skills) — optional, only
100
- when you use the `skills` macro
101
- - [ruby_llm-mcp](https://github.com/patvice/ruby_llm-mcp) — optional, only when you attach
102
- an MCP server with the `mcp` macro
103
- - `ruby_llm-agent_sdk` — optional (not yet published), only when you choose the
104
- Anthropic-oriented `Loops::AgentSDK` backend. Its exact API is verified-on-install
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 after every tool is attached, because each `with_tools` call
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
@@ -132,7 +132,7 @@ class ApprovedWrite < Nexo::Workflow
132
132
  end
133
133
  ```
134
134
 
135
- The loop is: **`:approve` gate with no decision → `Nexo::ApprovalRequired` → `run_agent`
135
+ The loop is: **`:approve` gate reaches a call nobody has decided → `Nexo::ApprovalRequired` → `run_agent`
136
136
  suspends → host renders the pending call → `resume(approved:)` threads the decision back
137
137
  through the gate.**
138
138
 
@@ -176,14 +176,26 @@ resumed.status # => "done" (the gate allowed the
176
176
  non-idempotent tool call *before* the approval gate re-runs on resume (agent tool calls
177
177
  generally aren't checkpointable). Put approval gates **early**, or after the expensive
178
178
  work is already `checkpoint`ed by the workflow.
179
- - **One approval per suspend cycle, global decision.** The `{approved:}` answers whichever
180
- gate the re-driven agent hits first. A *second* gate after an approved first one simply
181
- **suspends again** — the next resume decides it. There is no per-tool decision granularity
182
- in v1.
179
+ - **One answer decides one call.** `resume(approved:)` answers the call recorded under
180
+ `run.state["__approval__"]`, and nothing else. The answer is filed in
181
+ `run.state["__approvals__"]` under that call's key (capability plus path, command or URL; for
182
+ an MCP tool, its name plus a digest of the arguments). A *different* gated call later in the
183
+ same prompt **suspends again**, and the next resume decides it. Before 0.14 the first answer
184
+ silently applied to every later call.
185
+ - **A re-driven model may ask for something else.** Resume runs the prompt again, and nothing
186
+ forces the model to repeat the call you approved. If it writes `b.txt` where it asked for
187
+ `a.txt`, that is a new call and the run suspends for it. This is the safe direction.
188
+ - **`approved:` with nothing pending approves nothing.** An answer is recorded only when a call
189
+ is waiting.
190
+ - **A catch-all tool handler breaks it.** `RubyLLM::Tool.rescue_from StandardError` in the host
191
+ swallows the approval signal, and the call is reported to the model as an error instead of
192
+ suspending the run. Rescue specific classes.
183
193
  - **Cross-process approval needs the ActiveRecord store + ActiveJob** (like all durable resume).
184
194
  In-process `resume` works with the Memory store; a Memory run does not survive the process.
185
195
  - **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, 1.16.0). If a future
196
+ tool `execute` exception propagate out of `chat.ask` (verified on 2.2.3 through the real
197
+ loop, `test/real_loop_test.rb`). A host that registers a catch-all
198
+ `RubyLLM::Tool.rescue_from StandardError` would swallow the approval signal. If a future
187
199
  `ruby_llm` swallows tool exceptions, tool-triggered approval would be constrained — a
188
200
  genuine upstream dependency, stated plainly.
189
201
 
data/docs/loops.md CHANGED
@@ -1,121 +1,93 @@
1
- # Loop backends — swap the engine, not the agent
2
- The loop is the engine that drives one prompt to completion; swap it by constructor injection without touching the agent class.
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. Swapping it is constructor
5
- injection (`loop:`) — the agent class never changes. Two backends ship:
6
-
7
- | | `Loops::RubyLLM` (default) | `Loops::AgentSDK` (opt-in) |
8
- | ------------------ | ---------------------------------- | ------------------------------------- |
9
- | Provider neutral | ✅ any `ruby_llm` model | ❌ Anthropic-oriented |
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
- # Claude fast path — AgentSDK's own loop + host tools + native max_turns
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
- `Loops::AgentSDK` wraps `RubyLLM::AgentSDK.query` and requires the **optional**
38
- `ruby_llm-agent_sdk` gem (lazy `require`; a clear `Nexo::MissingDependencyError` if it's
39
- absent). It maps Nexo's permission modes onto the SDK's own vocabulary:
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
- ## Live smoke (optional)
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
- The core suite is fully offline and deterministic (models stubbed with `ruby_llm-test`).
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
- ```sh
87
- ollama serve &
88
- NEXO_LIVE=1 NEXO_MODEL=gemma3:12b bundle exec rake test TEST=test/live_smoke_test.rb
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
- If Gemma's tool-calling proves too weak, point `NEXO_MODEL` at a stronger model — the gem
92
- stays provider-neutral; only the smoke target changes.
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
- ## `max_turns` is a budget, not a hard stop
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
- `Agent#prompt`, `Session#prompt` and `Workflow#run_agent` all take `max_turns:`. On the
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
- What it does do is count tool calls and tell you when the budget is passed:
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
- ```ruby
104
- agent.prompt("Triage the inbox", max_turns: 10) do |type, payload|
105
- warn "over budget: #{payload}" if type == :turn_limit_exceeded
106
- end
107
- # => :turn_limit_exceeded, { turns: 11, max_turns: 10 }
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
- Emitted once per prompt, not per call.
78
+ ## Live smoke (optional)
111
79
 
112
- If you need a **hard** ceiling, the options are:
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
- - bound the work inside your own tools (a read tool that accepts at most N ids);
115
- - use `Loops::AgentSDK`, whose engine enforces `max_turns` natively;
116
- - stop the run yourself from the event block.
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
- Treat `max_turns` on the default loop as telemetry. It was previously accepted and never
119
- read, which made it look like a safety bound it has never been.
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)