nexo_ai 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rdoc_options +5 -0
  3. data/CHANGELOG.md +95 -0
  4. data/README.md +13 -14
  5. data/Rakefile +5 -0
  6. data/docs/concurrency.md +1 -2
  7. data/docs/durable-workflows.md +5 -3
  8. data/docs/getting-started.md +1 -1
  9. data/docs/loops.md +62 -89
  10. data/docs/mcp.md +57 -51
  11. data/docs/rails.md +1 -1
  12. data/docs/sessions.md +7 -3
  13. data/docs/skills.md +20 -11
  14. data/docs/workflows.md +2 -2
  15. data/examples/mcp_filesystem.rb +1 -1
  16. data/lib/generators/nexo/artifacts/artifacts_generator.rb +9 -7
  17. data/lib/generators/nexo/artifacts/templates/add_artifacts_to_nexo_workflow_runs.rb +1 -1
  18. data/lib/generators/nexo/install/install_generator.rb +7 -5
  19. data/lib/generators/nexo/skill/skill_generator.rb +10 -8
  20. data/lib/generators/nexo/state/state_generator.rb +9 -7
  21. data/lib/generators/nexo/state/templates/add_state_to_nexo_workflow_runs.rb +1 -1
  22. data/lib/generators/nexo/workflows/templates/create_nexo_workflow_runs.rb +3 -3
  23. data/lib/generators/nexo/workflows/workflows_generator.rb +7 -5
  24. data/lib/nexo/agent.rb +159 -169
  25. data/lib/nexo/concurrent.rb +18 -16
  26. data/lib/nexo/configuration.rb +21 -21
  27. data/lib/nexo/engine.rb +1 -1
  28. data/lib/nexo/loop.rb +12 -14
  29. data/lib/nexo/loops/ruby_llm.rb +43 -34
  30. data/lib/nexo/mcp/gated_tool.rb +31 -27
  31. data/lib/nexo/mcp.rb +73 -68
  32. data/lib/nexo/output_truncator.rb +9 -9
  33. data/lib/nexo/permissions.rb +44 -46
  34. data/lib/nexo/read_tracker.rb +4 -4
  35. data/lib/nexo/run_store.rb +30 -28
  36. data/lib/nexo/sandbox.rb +29 -27
  37. data/lib/nexo/sandboxes/container.rb +75 -75
  38. data/lib/nexo/sandboxes/local.rb +15 -15
  39. data/lib/nexo/sandboxes/remote.rb +25 -23
  40. data/lib/nexo/sandboxes/virtual.rb +2 -2
  41. data/lib/nexo/sandboxes.rb +9 -9
  42. data/lib/nexo/session.rb +31 -29
  43. data/lib/nexo/skills/skill.rb +89 -0
  44. data/lib/nexo/skills.rb +33 -58
  45. data/lib/nexo/tools/fetch.rb +21 -21
  46. data/lib/nexo/tools/glob.rb +6 -6
  47. data/lib/nexo/tools/read_file.rb +8 -8
  48. data/lib/nexo/tools/shell.rb +7 -7
  49. data/lib/nexo/tools/web_search.rb +16 -16
  50. data/lib/nexo/tools/write_file.rb +11 -11
  51. data/lib/nexo/turbo_broadcaster.rb +1 -1
  52. data/lib/nexo/version.rb +2 -2
  53. data/lib/nexo/workflow.rb +207 -193
  54. data/lib/nexo/workflow_job.rb +6 -6
  55. data/lib/nexo/workflow_run.rb +10 -10
  56. data/lib/nexo.rb +28 -26
  57. data/sig/nexo/agent.rbs +1 -1
  58. metadata +7 -34
  59. data/lib/nexo/loops/agent_sdk.rb +0 -68
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a372c4ac5c253a76cbf930d99b134bbdc62c596dc8bde4414da26f08c99ad39
4
- data.tar.gz: 8329003fd163b8b4131f4608b18ecb5604717b7dd6995699328216cb22143320
3
+ metadata.gz: 3ab3bc27263cfb9d2adc054a4579f983f8fa10ac2c94586116f3e6793d3d93b9
4
+ data.tar.gz: e967f788db7fce3e9205199b7cbe8628a60d5678e9daa0db8802852d6e87b7bf
5
5
  SHA512:
6
- metadata.gz: 3e3de8747793d6c7b052d9272f6e23345e33d0749e66cd17a4247429eec1999f1329830c1c21841ac399bc04743f2d6595126496d8a24d340b537ad5ee4de026
7
- data.tar.gz: 271699e28b6c236f618250b06f75ed8c4fc5d0dec269d24d0f4bac145366e1cedc0f6fee37926117b9fbf2446a8d4d7b54054f2c73562f3d6a1bfd6ae41e21d5
6
+ metadata.gz: 97a086e9d89990c89c0be4d9ba03de89ac2c77aa6e6d5fcd5086179c9d5c55845f2b08543984ea67b77eafa4b6e085e2c2d60d2d9c25020a80853c81bfab61bd
7
+ data.tar.gz: 57b9cf4b4ab598badaad5cc59fa57b691ca3c4f8c88caa927ed3ef9bf9637587a029db2037ae04ac97b7e17341a41ac4c5a0435edbfe9d13f00d135b92efb375
data/.rdoc_options ADDED
@@ -0,0 +1,5 @@
1
+ # RDoc configuration for `rdoc`, `gem rdoc`, and rubydoc.info. All comments in
2
+ # lib/ and the docs/ guides are written in Markdown, not RDoc markup.
3
+ markup: markdown
4
+ main_page: README.md
5
+ title: nexo_ai
data/CHANGELOG.md CHANGED
@@ -1,5 +1,100 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.13.0] - 2026-11-26
4
+
5
+ Nexo now runs on ruby_llm 2.2. MCP comes from ruby_llm itself, skills need no extra gem,
6
+ and `max_turns` is a real cap.
7
+
8
+ ### Changed
9
+
10
+ - **`ruby_llm` is now pinned to the 2.2 line (`~> 2.2.0`, was `~> 1.16`).** Verified against
11
+ 2.2.3. ruby_llm 1.x is no longer supported; it ended at 1.16.0 and carries ReDoS
12
+ advisories that are fixed only in 2.0.
13
+
14
+ **Upgrading:** this is a breaking release for the host app's Gemfile and for any
15
+ `RubyLLM::Tool` you wrote yourself.
16
+
17
+ 1. Remove `gem "ruby_llm-mcp"` and `gem "ruby_llm-skills"`. `ruby_llm-mcp` defines the
18
+ same `RubyLLM::MCP` constant as ruby_llm 2.x and cannot be bundled with it; both gems
19
+ pin ruby_llm 1.x. Anything you were getting from them transitively (for example
20
+ `bigdecimal`) must now be declared by you.
21
+ 2. In your own tools, rename `param` to `parameter` and `desc:` to `description:`
22
+ (`params do` becomes `parameters do`). ruby_llm 2.0 removed the old names.
23
+ 3. A tool wrapper you wrote (for `wrap_mcp_tool`) must accept keywords:
24
+ `def call(**arguments)`. ruby_llm 2.x calls tools as `tool.call(**arguments)`, and the
25
+ schema reader is `parameters_schema`, not `params_schema`.
26
+ 4. If you use `Nexo::Session` on ActiveRecord, run ruby_llm's own schema upgrade
27
+ (`rails g ruby_llm:upgrade`, one minor at a time). ruby_llm 2.x keeps tool calls and
28
+ the model registry in its own `ruby_llm_*` tables; the host owns only `Chat` and
29
+ `Message`.
30
+ 5. Read ruby_llm's [upgrade guide](https://rubyllm.com/upgrading/) for everything outside
31
+ Nexo — notably that OpenAI now defaults to the Responses API.
32
+
33
+ - **`max_turns` is a hard cap.** `Agent#prompt`, `Session#prompt` and
34
+ `Workflow#run_agent` pass it to ruby_llm as `with_tool_options(rounds:)`. When a prompt
35
+ uses up its tool rounds, `RubyLLM::ToolRoundLimitError` is raised instead of the model
36
+ being asked again; inside a workflow that fails the run. It was telemetry only before.
37
+
38
+ **Upgrading:** a run that used to pass `max_turns` and keep going now stops. Raise the
39
+ number for runs that legitimately need more rounds, or pass `max_turns: nil` to run
40
+ uncapped. The `:turn_limit_exceeded` event is still emitted, once per prompt.
41
+
42
+ - **MCP uses ruby_llm's built-in client.** The `mcp` macro, `mcp_allow`, the fail-closed
43
+ gate, `wrap_mcp_tool` and `Nexo::MCP.build` are unchanged for callers. Three behaviours
44
+ differ, all inherited from ruby_llm:
45
+ - a callable `token:` is read again for **every request**, so a rotated token no longer
46
+ needs `agent.close` and a reconnect;
47
+ - a `:stdio` server starts with a short, safe environment — pass what it needs with
48
+ `env:`;
49
+ - a `:stdio` server's stderr is your process's stderr.
50
+
51
+ An unknown transport or a `:stdio` server with no `command:` now raises
52
+ `Nexo::ConfigurationError` when the server is built.
53
+
54
+ - **Skills are read by Nexo itself** (`Nexo::Skills::Skill`). `skills`, `Nexo::Skills.find`
55
+ and `Nexo::Skills.materialize` are unchanged. A `SKILL.md` without YAML front matter now
56
+ raises `Nexo::Error` naming the file. ruby_llm's own skills are not used: they reject
57
+ underscore names (`email_triage`) and work through a `load_skill` tool, where Nexo's rule
58
+ is that a skill adds instructions and nothing else.
59
+
60
+ - **Workflow events store tool arguments string-keyed** in both run stores. ruby_llm 2.x
61
+ hands them over with Symbol keys; the Memory store would otherwise have disagreed with
62
+ the ActiveRecord one.
63
+
64
+ ### Removed
65
+
66
+ - **`Nexo::Loops::AgentSDK`**, with `Agent#permission_mode`, `Agent#allowed_tools`,
67
+ `Agent::ALLOWED_TOOLS` and `Agent::PERMISSION_MODE_MAP`. The `ruby_llm-agent_sdk` gem it
68
+ wrapped was never published, so this path never ran against real code. Its one purpose,
69
+ a hard turn cap, is now `max_turns` on the default loop. `Nexo::Loop` remains as the seam
70
+ for a backend of your own.
71
+ - **`Nexo::MCP.load!` and `Nexo::Skills.load!`.** There is no optional gem left to load.
72
+ - The `ruby_llm-test`, `ruby_llm-skills` and `ruby_llm-mcp` development dependencies. The
73
+ suite scripts model replies with ruby_llm's own `RubyLLM::TestHelper`.
74
+
75
+ ### Added
76
+
77
+ - `test/real_loop_test.rb` drives ruby_llm's real conversation loop with scripted replies
78
+ and proves, end to end: a `:read_only` agent cannot reach the write tool, the MCP gate
79
+ denies a tool before it runs, `max_turns` stops a runaway loop, and an `:approve` gate
80
+ suspends a workflow and resumes it.
81
+ - `mcp` accepts `env:` and `directory:` for `:stdio` servers, and `command:` as an argv
82
+ Array.
83
+
84
+ ## [0.12.0] - 2026-09-12
85
+
86
+ The gem now says exactly which ruby_llm it supports, and its API docs are written in Markdown.
87
+
88
+ ### Changed
89
+
90
+ - **`ruby_llm` is now pinned to the 1.16 line (`~> 1.16`, was `>= 1.16`).** The supported
91
+ version is 1.16.0 — every composed API was verified against it. The upcoming ruby_llm 2.0
92
+ is not supported yet, and the pessimistic constraint keeps it from being resolved in.
93
+ - **API documentation is written in Markdown.** RDoc now runs with `markup: markdown`
94
+ (`.rdoc_options` + the `rake doc` task), and every doc comment under `lib/` was converted
95
+ from RDoc markup — backtick code spans, `##` headings, fenced code samples. Guides link the
96
+ `examples/` files by GitHub URL so the links work on rubydoc.info as well as on GitHub.
97
+
3
98
  ## [0.11.0] - 2026-08-20
4
99
 
5
100
  An agent's tool schema now tells the truth about what it may do.
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,15 +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
98
- - [ruby_llm-skills](https://github.com/kieranklaassen/ruby_llm-skills) — optional, only
99
- when you use the `skills` macro
100
- - [ruby_llm-mcp](https://github.com/patvice/ruby_llm-mcp) — optional, only when you attach
101
- an MCP server with the `mcp` macro
102
- - `ruby_llm-agent_sdk` — optional (not yet published), only when you choose the
103
- Anthropic-oriented `Loops::AgentSDK` backend. Its exact API is verified-on-install
104
- (see [Loops](docs/loops.md)); until it ships, `Loops::AgentSDK` raises a clear
105
- `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).
106
105
 
107
106
  ## Status
108
107
 
data/Rakefile CHANGED
@@ -31,7 +31,12 @@ RDoc::Task.new(:doc) do |rd|
31
31
  # are not part of the gem's Ruby API, so they belong in neither the generated
32
32
  # API site nor the coverage denominator.
33
33
  rd.rdoc_files.exclude("lib/generators/**/templates/*.rb")
34
+ # Local planning notes (gitignored) that happen to live under docs/.
35
+ rd.rdoc_files.exclude("docs/SITE_DOCS_PLAN.md")
34
36
  rd.rdoc_dir = "doc"
37
+ # Every comment in lib/ (and the docs/ guides) is Markdown, not RDoc markup.
38
+ # Mirrors `.rdoc_options`, which `gem rdoc`/rubydoc.info read instead of this task.
39
+ rd.markup = "markdown"
35
40
  end
36
41
 
37
42
  # NOTE: `default` intentionally stays test + standard — `rake doc`/`doc:coverage`
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
@@ -61,7 +61,7 @@ run:
61
61
  DocumentApproval.resume_later(run.id, { approved: true }, queue: :nexo)
62
62
  ```
63
63
 
64
- See [`examples/approval_workflow.rb`](../examples/approval_workflow.rb) for the full
64
+ See [`examples/approval_workflow.rb`](https://github.com/maquina-app/nexo/blob/main/examples/approval_workflow.rb) for the full
65
65
  offline flow (`ruby -Ilib examples/approval_workflow.rb`).
66
66
 
67
67
  ## Parallel checkpoints — `checkpoint_all`
@@ -183,11 +183,13 @@ resumed.status # => "done" (the gate allowed the
183
183
  - **Cross-process approval needs the ActiveRecord store + ActiveJob** (like all durable resume).
184
184
  In-process `resume` works with the Memory store; a Memory run does not survive the process.
185
185
  - **Branch depends on upstream `ruby_llm`.** This works because `ruby_llm`'s tool loop lets a
186
- tool `execute` exception propagate out of `chat.ask` (verified, 1.16.0). If a future
186
+ tool `execute` exception propagate out of `chat.ask` (verified on 2.2.3 through the real
187
+ loop, `test/real_loop_test.rb`). A host that registers a catch-all
188
+ `RubyLLM::Tool.rescue_from StandardError` would swallow the approval signal. If a future
187
189
  `ruby_llm` swallows tool exceptions, tool-triggered approval would be constrained — a
188
190
  genuine upstream dependency, stated plainly.
189
191
 
190
- See [`examples/approval_agent.rb`](../examples/approval_agent.rb) for the live flow
192
+ See [`examples/approval_agent.rb`](https://github.com/maquina-app/nexo/blob/main/examples/approval_agent.rb) for the live flow
191
193
  (`NEXO_LIVE=1 NEXO_MODEL=… ruby -Ilib examples/approval_agent.rb`).
192
194
 
193
195
  The `state` column ships with fresh installs. Apps installed before this feature
@@ -97,7 +97,7 @@ Both are class macros with the same reader/writer convention as `model`. `provid
97
97
  is passed straight through to `RubyLLM.chat`; `assume_model_exists` defaults to
98
98
  `false` (registry validation on). Setting `assume_model_exists` **without** a
99
99
  `provider` raises `Nexo::ConfigurationError` — `ruby_llm` can't infer a provider once
100
- the lookup is skipped. See [`examples/code_reviewer.rb`](../examples/code_reviewer.rb)
100
+ the lookup is skipped. See [`examples/code_reviewer.rb`](https://github.com/maquina-app/nexo/blob/main/examples/code_reviewer.rb)
101
101
  for a runnable Ollama example.
102
102
 
103
103
  ← Back to the [README](../README.md)
data/docs/loops.md CHANGED
@@ -1,86 +1,86 @@
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:
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.
24
+
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).
27
+
28
+ ## `max_turns` is a hard cap
40
29
 
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`) |
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:)`.
47
34
 
48
- ## The turn-cap caveat (read before running untrusted/expensive workloads)
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:
49
38
 
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:
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
47
+ ```
54
48
 
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).
49
+ Inside a workflow the error fails the run like any other (`status: "failed"`, re-raised),
50
+ so a runaway agent cannot keep spending.
60
51
 
61
- Do **not** ship `Loops::RubyLLM` for untrusted workloads claiming a hard cap that isn't
62
- proven.
52
+ Things to know:
63
53
 
64
- ## Verified vs assumed
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.
65
62
 
66
- Built against **`ruby_llm` 1.16** and **`ruby_llm-test` 0.2**. The tool body method is
67
- `#execute`, tools attach with `chat.with_tools(*instances)`, and instructions set with
68
- `chat.with_instructions`. `Open3.capture3` has no `timeout:` keyword on the target Ruby, so
69
- `Local#shell` bounds the command with `Timeout.timeout`. These may differ on other
70
- `ruby_llm` versions.
63
+ ## Verified against
71
64
 
72
- `Loops::RubyLLM`'s turn-count observability uses `RubyLLM::Chat#before_tool_call` /
73
- `#after_tool_result`, confirmed present on `ruby_llm` 1.16.0 and guarded with `respond_to?`
74
- so a version lacking them degrades to no observability rather than crashing.
75
- `Loops::AgentSDK` targets `RubyLLM::AgentSDK.query`; `ruby_llm-agent_sdk` is **not** a
76
- dependency of this release, so that signature is **assumed** (per the gem's README) and
77
- verified-on-install — confirm it the moment you add the gem.
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.
70
+
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`.
78
77
 
79
78
  ## Live smoke (optional)
80
79
 
81
- The core suite is fully offline and deterministic (models stubbed with `ruby_llm-test`).
82
- A real end-to-end check is opt-in and env-gated — small local models like Gemma have weak
83
- tool-calling, so it may be flaky and is never a gating test:
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:
84
84
 
85
85
  ```sh
86
86
  ollama serve &
@@ -90,31 +90,4 @@ NEXO_LIVE=1 NEXO_MODEL=gemma3:12b bundle exec rake test TEST=test/live_smoke_tes
90
90
  If Gemma's tool-calling proves too weak, point `NEXO_MODEL` at a stronger model — the gem
91
91
  stays provider-neutral; only the smoke target changes.
92
92
 
93
-
94
- ## `max_turns` is a budget, not a hard stop
95
-
96
- `Agent#prompt`, `Session#prompt` and `Workflow#run_agent` all take `max_turns:`. On the
97
- default `Loops::RubyLLM` it **cannot halt a run**: ruby_llm executes the entire tool loop
98
- inside `Chat#ask`, and the callbacks Nexo wires are observation-only.
99
-
100
- What it does do is count tool calls and tell you when the budget is passed:
101
-
102
- ```ruby
103
- agent.prompt("Triage the inbox", max_turns: 10) do |type, payload|
104
- warn "over budget: #{payload}" if type == :turn_limit_exceeded
105
- end
106
- # => :turn_limit_exceeded, { turns: 11, max_turns: 10 }
107
- ```
108
-
109
- Emitted once per prompt, not per call.
110
-
111
- If you need a **hard** ceiling, the options are:
112
-
113
- - bound the work inside your own tools (a read tool that accepts at most N ids);
114
- - use `Loops::AgentSDK`, whose engine enforces `max_turns` natively;
115
- - stop the run yourself from the event block.
116
-
117
- Treat `max_turns` on the default loop as telemetry. It was previously accepted and never
118
- read, which made it look like a safety bound it has never been.
119
-
120
93
  ← Back to the [README](../README.md)
data/docs/mcp.md CHANGED
@@ -3,9 +3,9 @@ Attach one or more MCP servers with a single `mcp` macro — every call gated by
3
3
 
4
4
  An **MCP server** exposes tools to a model over the [Model Context
5
5
  Protocol](https://modelcontextprotocol.io) — Gmail, a filesystem, a fetch endpoint,
6
- Drive, and so on. Nexo does not implement MCP; it composes the
7
- [`ruby_llm-mcp`](https://github.com/patvice/ruby_llm-mcp) gem so you attach one or more
8
- servers with a single `mcp` macro and no client wiring. Because a server is reached
6
+ Drive, and so on. Nexo does not implement MCP; it composes the MCP client built into
7
+ [`ruby_llm`](https://rubyllm.com/mcp/) (core since 2.1) so you attach one or more
8
+ servers with a single `mcp` macro and no client wiring — and no extra gem. Because a server is reached
9
9
  *through the protocol* (never a vendor SDK), the behavior is identical on Anthropic, a
10
10
  local model, or anything else `ruby_llm` supports.
11
11
 
@@ -56,10 +56,10 @@ no globs or regexes.
56
56
  constrain what that server does with a call it is authorized to make — attaching a write
57
57
  server and allowing a write tool means real writes happen. Gate deliberately, and prefer
58
58
  `:read_only` with a tight `mcp_allow`.
59
- 2. **Connection lifecycle.** Clients are built once and **memoized on the agent instance**,
60
- reused across prompts (the `ruby_llm-mcp` client connects on construction and stays
61
- connected). A long-lived agent holding stdio/SSE servers should call `Agent#close` when
62
- done to tear the connections down:
59
+ 2. **Connection lifecycle.** Servers are built once and **memoized on the agent instance**,
60
+ reused across prompts (a server connects on its first request and stays connected). A
61
+ long-lived agent holding stdio/HTTP servers should call `Agent#close` when done to tear
62
+ the connections down:
63
63
 
64
64
  ```ruby
65
65
  agent = InboxDigest.new
@@ -68,13 +68,32 @@ no globs or regexes.
68
68
  agent.close # stops every attached server
69
69
  ```
70
70
 
71
- ## HTTP-family servers + an OAuth `token:` provider
71
+ ## Stdio servers: environment and stderr
72
72
 
73
- Beyond `:stdio`, Nexo attaches a server over any HTTP-family transport `ruby_llm-mcp`
74
- supports — `transport: :http`, `:sse`, or `:streamable`. For an OAuth-authenticated
75
- hosted server (Gmail, Drive, …) add a `token:` — a static bearer `String`, or a
76
- **callable** re-read close to connection time. Nexo resolves it and injects an
77
- `Authorization: Bearer <token>` header per connection:
73
+ A `:stdio` server is a process Nexo's host starts. Two things about it come from
74
+ `ruby_llm` and are worth knowing:
75
+
76
+ - **It gets a short environment.** The process inherits only a small set of safe variables
77
+ (`PATH`, `HOME`, `LANG`, `TMPDIR`, `USER`, and a few more) — not your application's
78
+ secrets. Pass anything else the server needs with `env:`:
79
+
80
+ ```ruby
81
+ mcp :github, transport: :stdio, command: "github-mcp", env: {GITHUB_TOKEN: ENV.fetch("GITHUB_TOKEN")}
82
+ ```
83
+
84
+ - **Its stderr is your process's stderr.** A chatty server prints straight into your
85
+ terminal or log. To drop it, wrap the command:
86
+ `command: "sh", args: ["-c", 'exec "$0" 2>/dev/null', "apple-mail-mcp"]`.
87
+
88
+ `command:` takes a String or an argv Array, `args:` is appended to it, and `directory:`
89
+ sets the process's working directory.
90
+
91
+ ## HTTP servers + a bearer `token:`
92
+
93
+ Beyond `:stdio`, Nexo attaches a server over HTTP — `transport: :http`, `:sse`, or
94
+ `:streamable` (all three are "a URL"; `ruby_llm` speaks Streamable HTTP and falls back for
95
+ older servers by itself). For an authenticated hosted server (Gmail, Drive, …) add a
96
+ `token:` — a static bearer `String`, or a **callable** that returns one:
78
97
 
79
98
  ```ruby
80
99
  class InboxTriageHTTP < Nexo::Agent
@@ -85,7 +104,7 @@ class InboxTriageHTTP < Nexo::Agent
85
104
  mcp :gmail,
86
105
  transport: :http,
87
106
  url: ENV.fetch("GMAIL_MCP_URL"),
88
- token: -> { Current.user.gmail_access_token } # re-read at connection time
107
+ token: -> { Current.user.gmail_access_token } # read again for each request
89
108
 
90
109
  # READ tools only — the unchanged gate denies send/trash/modify.
91
110
  mcp_allow %w[search_threads get_thread list_messages get_message list_labels]
@@ -93,53 +112,39 @@ end
93
112
  ```
94
113
 
95
114
  A static token (`token: ENV.fetch("GMAIL_TOKEN")`) is equally valid. Under the hood
96
- Nexo strips `token:` and hands off:
115
+ Nexo hands the token to `ruby_llm` as the server's bearer token:
97
116
 
98
117
  ```ruby
99
- RubyLLM::MCP.client(
100
- name: "gmail", transport_type: :http,
101
- config: { url: "https://…", headers: { "Authorization" => "Bearer <resolved>" } }
102
- )
118
+ RubyLLM.mcp(name: "gmail", url: "https://…", bearer_token: -> { … })
103
119
  ```
104
120
 
105
- Any other `headers:` you pass are preserved; Nexo's `Authorization` wins. With no
106
- `token:`, `config:` passes through byte-for-byte (no `headers` key) — the `:stdio` path
107
- is untouched.
121
+ `ruby_llm` sends it as `Authorization: Bearer <token>`. Any `headers:` you pass are sent
122
+ too; the bearer token wins the `Authorization` header.
108
123
 
109
- **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).
114
-
115
- **Refresh / reconnect caveat.** `ruby_llm-mcp`'s HTTP-family transports snapshot the
116
- `headers` hash **at construction** — there is no per-request header callback for a plain
117
- `headers` Hash. A callable `token:` is therefore resolved **once**, when the client is
118
- built, and the client is memoized on the agent instance across prompts. So when a token
119
- **rotates**, tear the connection down and reconnect to pick up the new value:
124
+ **A callable token is read again for every request.** When a token rotates, the next
125
+ request carries the new value — no reconnect needed. (Under `ruby_llm` 1.x a callable was
126
+ resolved once per connection and a rotation needed `agent.close`; that caveat is gone.)
120
127
 
121
- ```ruby
122
- agent.close # stops the memoized MCP client
123
- agent.prompt("…") # a fresh prompt rebuilds the client → token: re-resolved
124
- ```
128
+ **Nexo does not own the OAuth flow.** It performs no authorization-code exchange, no
129
+ token refresh, and keeps no token store — that is your app or an OAuth library. The token
130
+ is never logged, persisted, placed in a URL/query string, or emitted in an event (the
131
+ event path carries only tool `name`/`args` and return values — never connection config).
125
132
 
126
- **The gate is unchanged.** An HTTP OAuth server's tools are gated exactly like `:stdio`
133
+ **The gate is unchanged.** An HTTP server's tools are gated exactly like `:stdio`
127
134
  tools: denied under `:read_only` until the exact name is in `mcp_allow` (default `[]` ⇒
128
135
  deny-all). Attaching an authenticated server adds no permission surface.
129
136
 
130
- **Two honest caveats — read before attaching a token:**
137
+ **The token is a live credential.** Even gated, an authorized MCP call runs its effect
138
+ server-side — a leaked bearer is a real compromise. Nexo keeps it out of logs, events,
139
+ persisted `WorkflowRun` records, and URLs; your host code must do the same. Nexo does
140
+ not police `ruby_llm`'s own debug logging (`RUBYLLM_DEBUG`) — that boundary is yours.
131
141
 
132
- 1. **Refresh may require a reconnect.** Because headers are construction-only,
133
- a rotated token needs `agent.close` + a fresh prompt (above), not just a new proc
134
- return. A static token stays constant for the client's life.
135
- 2. **The token is a live credential.** Even gated, an authorized MCP call runs its effect
136
- server-side — a leaked bearer is a real compromise. Nexo keeps it out of logs, events,
137
- persisted `WorkflowRun` records, and URLs; your host code must do the same. Nexo does
138
- not police `ruby_llm-mcp`'s own internal logging of headers — that boundary is yours.
142
+ `ruby_llm` can also run a full per-user OAuth flow for an MCP server
143
+ (`oauth owner:` on a `RubyLLM::MCP` class). Nexo's `mcp` macro does not expose it yet.
139
144
 
140
- `ruby_llm-mcp` is an **optional** dependency — required lazily only when you attach a
141
- server. Without it installed, `require "nexo"` still loads; building a server raises a clear
142
- `Nexo::MissingDependencyError` telling you to add `gem "ruby_llm-mcp"`.
145
+ > **Upgrading from 0.12:** remove `gem "ruby_llm-mcp"` from your Gemfile. It defines the
146
+ > same `RubyLLM::MCP` constant as `ruby_llm` 2.x and the two cannot be bundled together.
147
+ > The `mcp` macro and `mcp_allow` are unchanged.
143
148
 
144
149
 
145
150
  ## Decorating MCP tools
@@ -161,8 +166,9 @@ end
161
166
  ```
162
167
 
163
168
  A wrapper must keep the duck type the chat relies on — `#name`, `#description`,
164
- `#params_schema` and `#call`. `GatedTool` delegates the rest through `method_missing`, so
165
- wrappers compose.
169
+ `#parameters_schema` and `#call`. `ruby_llm` 2.x calls every tool with **keywords**, so
170
+ write `def call(**arguments) = …@tool.call(**arguments)`. Delegate everything else with
171
+ `method_missing`, as `GatedTool` does, so wrappers compose.
166
172
 
167
173
  Gating happens **underneath** the wrapper, so it only ever sees an already-authorized
168
174
  call. Wrapping cannot widen what an agent may do.
data/docs/rails.md CHANGED
@@ -156,7 +156,7 @@ run.artifact("digest.md") # => {"name" =>, "content" =>, "at" =>} or ni
156
156
  run.artifact_content("digest.md") # => "…the body…" or nil
157
157
  ```
158
158
 
159
- See [`examples/rails_usage.md`](../examples/rails_usage.md) for a controller +
159
+ See [`examples/rails_usage.md`](https://github.com/maquina-app/nexo/blob/main/examples/rails_usage.md) for a controller +
160
160
  Turbo-page walkthrough.
161
161
 
162
162
  ← Back to the [README](../README.md)
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 all four persistence models (`Chat`,
31
- `Message`, `ToolCall`, `Model`), generated by ruby_llm's own installer:
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/ToolCall/Model models + migrations
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