mistri 0.7.0 → 0.8.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 +321 -2
- data/CONTRIBUTING.md +17 -3
- data/NOTICE +11 -0
- data/README.md +145 -284
- data/UPGRADING.md +810 -0
- data/assets/vendors/README.md +12 -0
- data/assets/vendors/claude-mark.svg +3 -0
- data/assets/vendors/gemini-mark.svg +10 -0
- data/assets/vendors/openai-mark-dark.svg +1 -0
- data/assets/vendors/openai-mark.svg +1 -0
- data/docs/README.md +2 -1
- data/docs/context-and-workspaces.md +84 -13
- data/docs/logging.md +90 -0
- data/docs/mcp.md +762 -21
- data/docs/reliability.md +210 -24
- data/docs/sessions.md +415 -36
- data/docs/sub-agents.md +85 -7
- data/docs/tool-contracts.md +528 -13
- data/examples/approval.rb +7 -7
- data/examples/browser.rb +1 -1
- data/examples/page_editor.rb +2 -2
- data/examples/quickstart.rb +1 -1
- data/lib/generators/mistri/install/templates/migration.rb.tt +4 -2
- data/lib/generators/mistri/mcp/mcp_generator.rb +2 -2
- data/lib/generators/mistri/mcp/templates/model.rb.tt +21 -8
- data/lib/mistri/agent.rb +815 -180
- data/lib/mistri/call_order.rb +137 -0
- data/lib/mistri/child.rb +69 -13
- data/lib/mistri/compaction.rb +200 -35
- data/lib/mistri/compactor/text.rb +91 -0
- data/lib/mistri/compactor.rb +474 -117
- data/lib/mistri/console.rb +44 -11
- data/lib/mistri/content.rb +70 -3
- data/lib/mistri/definition.rb +2 -2
- data/lib/mistri/edit.rb +13 -7
- data/lib/mistri/errors.rb +37 -0
- data/lib/mistri/event.rb +20 -9
- data/lib/mistri/locks/rails_cache.rb +16 -2
- data/lib/mistri/locks.rb +12 -3
- data/lib/mistri/mcp/client.rb +247 -61
- data/lib/mistri/mcp/conversation.rb +161 -0
- data/lib/mistri/mcp/egress.rb +5 -4
- data/lib/mistri/mcp/mirror.rb +90 -0
- data/lib/mistri/mcp/negotiation.rb +222 -0
- data/lib/mistri/mcp/oauth/client_identity.rb +53 -0
- data/lib/mistri/mcp/oauth/tolerance.rb +61 -0
- data/lib/mistri/mcp/oauth.rb +303 -82
- data/lib/mistri/mcp/results.rb +97 -0
- data/lib/mistri/mcp/sdk_client.rb +47 -0
- data/lib/mistri/mcp/wires.rb +325 -52
- data/lib/mistri/mcp.rb +304 -55
- data/lib/mistri/memory.rb +1 -1
- data/lib/mistri/message.rb +45 -8
- data/lib/mistri/models.rb +146 -24
- data/lib/mistri/partial_json.rb +5 -5
- data/lib/mistri/providers/anthropic/assembler.rb +40 -3
- data/lib/mistri/providers/anthropic/serializer.rb +154 -22
- data/lib/mistri/providers/anthropic.rb +77 -12
- data/lib/mistri/providers/fake.rb +4 -1
- data/lib/mistri/providers/gemini/assembler.rb +63 -3
- data/lib/mistri/providers/gemini/serializer.rb +27 -16
- data/lib/mistri/providers/gemini.rb +56 -11
- data/lib/mistri/providers/openai/assembler.rb +36 -5
- data/lib/mistri/providers/openai/serializer.rb +76 -22
- data/lib/mistri/providers/openai.rb +91 -14
- data/lib/mistri/reminder.rb +35 -3
- data/lib/mistri/result.rb +6 -4
- data/lib/mistri/result_limit.rb +164 -0
- data/lib/mistri/sandbox/quickjs.rb +345 -0
- data/lib/mistri/sandbox.rb +18 -0
- data/lib/mistri/schema.rb +26 -2
- data/lib/mistri/scratchpad.rb +107 -0
- data/lib/mistri/session/log.rb +137 -0
- data/lib/mistri/session.rb +405 -75
- data/lib/mistri/sinks/logger.rb +17 -11
- data/lib/mistri/skills.rb +10 -4
- data/lib/mistri/spawner.rb +43 -12
- data/lib/mistri/sse.rb +3 -2
- data/lib/mistri/stores/active_record.rb +30 -6
- data/lib/mistri/stores/jsonl.rb +26 -7
- data/lib/mistri/stores/memory.rb +6 -2
- data/lib/mistri/sub_agent/execution.rb +10 -2
- data/lib/mistri/sub_agent/runtime.rb +11 -1
- data/lib/mistri/sub_agent.rb +13 -4
- data/lib/mistri/tool.rb +71 -7
- data/lib/mistri/tool_arguments.rb +10 -11
- data/lib/mistri/tool_context.rb +15 -3
- data/lib/mistri/tool_executor.rb +49 -26
- data/lib/mistri/tool_result.rb +8 -2
- data/lib/mistri/tool_search/index.rb +193 -0
- data/lib/mistri/tool_search.rb +200 -0
- data/lib/mistri/tools/delete_file.rb +22 -0
- data/lib/mistri/tools/edit_file.rb +24 -14
- data/lib/mistri/tools/find_in_file.rb +1 -0
- data/lib/mistri/tools/grep.rb +212 -0
- data/lib/mistri/tools/list_files.rb +38 -5
- data/lib/mistri/tools/read_file.rb +83 -21
- data/lib/mistri/tools/read_memory.rb +2 -1
- data/lib/mistri/tools/run_code.rb +167 -0
- data/lib/mistri/tools/write_file.rb +66 -9
- data/lib/mistri/tools.rb +72 -1
- data/lib/mistri/transport/streamable_http.rb +140 -0
- data/lib/mistri/transport.rb +53 -63
- data/lib/mistri/usage.rb +33 -4
- data/lib/mistri/version.rb +1 -1
- data/lib/mistri/workspace/active_record.rb +22 -10
- data/lib/mistri/workspace/directory.rb +5 -1
- data/lib/mistri/workspace/memory.rb +4 -0
- data/lib/mistri/workspace/path_space.rb +56 -0
- data/lib/mistri/workspace/single.rb +6 -1
- data/lib/mistri.rb +10 -4
- metadata +29 -2
data/README.md
CHANGED
|
@@ -18,15 +18,25 @@
|
|
|
18
18
|
<a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
|
|
19
19
|
</p>
|
|
20
20
|
|
|
21
|
+
Mistri runs AI agents inside your own Ruby application, on your models, your
|
|
22
|
+
database, your authorization, and your queue. A run can stop and wait for a
|
|
23
|
+
human to approve a tool call, then finish hours later in a different process.
|
|
24
|
+
The gem declares zero runtime dependencies.
|
|
25
|
+
|
|
21
26
|
A mistri (Urdu: مستری) is the fixer: the skilled tradesperson who actually
|
|
22
|
-
gets it done. Mistri
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
gets it done. Mistri works in plain Ruby, Rails, Sinatra, Hanami, jobs, and
|
|
28
|
+
services.
|
|
29
|
+
|
|
30
|
+
<p align="center">
|
|
31
|
+
<img src="assets/vendors/claude-mark.svg" height="30" alt="Claude">
|
|
32
|
+
<picture>
|
|
33
|
+
<source media="(prefers-color-scheme: dark)" srcset="assets/vendors/openai-mark-dark.svg">
|
|
34
|
+
<img src="assets/vendors/openai-mark.svg" height="30" alt="OpenAI">
|
|
35
|
+
</picture>
|
|
36
|
+
<img src="assets/vendors/gemini-mark.svg" height="30" alt="Gemini">
|
|
37
|
+
</p>
|
|
26
38
|
|
|
27
|
-
|
|
28
|
-
and services. Rails integrations are optional. The gem declares zero runtime
|
|
29
|
-
dependencies.
|
|
39
|
+
<p align="center">Anthropic, OpenAI, and Gemini, each through its own native protocol.</p>
|
|
30
40
|
|
|
31
41
|
## Start in sixty seconds
|
|
32
42
|
|
|
@@ -48,7 +58,7 @@ weather = Mistri::Tool.define(
|
|
|
48
58
|
{ city: args.fetch("city"), forecast: "34 C and clear" }
|
|
49
59
|
end
|
|
50
60
|
|
|
51
|
-
agent = Mistri.agent("claude-opus-
|
|
61
|
+
agent = Mistri.agent("claude-opus-5-5", tools: [weather])
|
|
52
62
|
|
|
53
63
|
result = agent.run("What should I wear in Lahore today? One sentence.") do |event|
|
|
54
64
|
print event.delta if event.type == :text_delta
|
|
@@ -57,163 +67,117 @@ puts
|
|
|
57
67
|
```
|
|
58
68
|
|
|
59
69
|
`Mistri.agent` infers the provider from the model ID and reads
|
|
60
|
-
`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, or `GEMINI_API_KEY`.
|
|
61
|
-
|
|
62
|
-
completed invocation returns a `Mistri::Result` with status
|
|
63
|
-
predicates, final text, usage, and structured task output when requested.
|
|
64
|
-
Host-contract failures raise as documented in [Reliability](docs/reliability.md).
|
|
70
|
+
`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, or `GEMINI_API_KEY`. Runnable examples
|
|
71
|
+
live in [`examples/`](examples).
|
|
65
72
|
|
|
66
|
-
|
|
73
|
+
## Watch a run happen
|
|
67
74
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
Active Record, or a host store. With a persistent store, runs can suspend,
|
|
72
|
-
reload, resume, steer, and compact without inventing a second state model. See
|
|
73
|
-
[Sessions and control](docs/sessions.md).
|
|
74
|
-
- **Human approval does not hold a thread.** A gated tool parks the request and
|
|
75
|
-
returns. With a shared store, another process can record the decision later;
|
|
76
|
-
`resume` revalidates the exact call before execution.
|
|
77
|
-
- **Provider semantics survive the abstraction.** Anthropic, OpenAI, and
|
|
78
|
-
Gemini stream through direct implementations that retain each provider's
|
|
79
|
-
reasoning, tool-pairing, and replay requirements. Unknown model IDs still
|
|
80
|
-
pass through when their provider can be inferred.
|
|
81
|
-
- **Tool input crosses a real boundary.** Completed model arguments are owned,
|
|
82
|
-
bounded, validated, and deeply frozen before hooks, approval predicates, MCP,
|
|
83
|
-
or handlers see them. See [Tool contracts](docs/tool-contracts.md).
|
|
84
|
-
- **The runtime stays small.** The [gemspec](mistri.gemspec) declares no runtime
|
|
85
|
-
gem dependencies. Optional Rails adapters load only when required.
|
|
86
|
-
- **Real APIs are part of the test strategy.** The
|
|
87
|
-
[live integration suite](CONTRIBUTING.md#setup)
|
|
88
|
-
exercises critical control, persistence, delegation, MCP, and
|
|
89
|
-
structured-output paths across all three providers when their keys are
|
|
90
|
-
present. The default CI suite remains hermetic.
|
|
91
|
-
|
|
92
|
-
## Choose the right layer
|
|
93
|
-
|
|
94
|
-
These projects solve different problems:
|
|
95
|
-
|
|
96
|
-
| Need | Start with |
|
|
97
|
-
| --- | --- |
|
|
98
|
-
| A durable tool loop inside any Ruby application, with append-only sessions, approval, steering, compaction, linked workers, and provider-neutral MCP | **Mistri** |
|
|
99
|
-
| Broad model access plus media, embeddings, image generation, and Rails-backed chat | [RubyLLM](https://github.com/crmne/ruby_llm) |
|
|
100
|
-
| Agents expressed through Rails controllers, actions, callbacks, views, and Active Job | [Active Agent](https://github.com/activeagents/activeagent) |
|
|
101
|
-
|
|
102
|
-
Mistri is deliberately not a terminal UI, hosted agent service, broad media
|
|
103
|
-
client, policy engine, or exactly-once job system. The host application keeps
|
|
104
|
-
its users, authorization rules, queues, database, UI, idempotency keys, and
|
|
105
|
-
reconciliation policy. Mistri supplies the execution mechanism that connects
|
|
106
|
-
them.
|
|
107
|
-
|
|
108
|
-
## How the loop works
|
|
75
|
+
```ruby
|
|
76
|
+
Mistri.logger = Rails.logger # or any Logger-compatible object
|
|
77
|
+
```
|
|
109
78
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
79
|
+
```text
|
|
80
|
+
[mistri 0a1b2c3d] run "What is 2 plus 3?" (gpt-6.1-sol, 3 tools)
|
|
81
|
+
[mistri 0a1b2c3d] turn 1 done tool_use (312 in / 48 out)
|
|
82
|
+
[mistri 0a1b2c3d] tool add#7f3a {"a":2,"b":3}
|
|
83
|
+
[mistri 0a1b2c3d] tool add#7f3a ok 12ms "5"
|
|
84
|
+
[mistri 0a1b2c3d] text "The sum is 5."
|
|
85
|
+
[mistri 0a1b2c3d] turn 2 done stop (410 in / 22 out)
|
|
86
|
+
[mistri 0a1b2c3d] done completed in 1.2s, 2 turns, 722 in / 70 out, $0.0042
|
|
87
|
+
```
|
|
117
88
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
89
|
+
One assignment, and every run tells its story in your ordinary log: inputs,
|
|
90
|
+
tools, durations, tokens, and dollar cost whenever pricing is known. Ship
|
|
91
|
+
those lines to your log platform and you have agent observability without a
|
|
92
|
+
dashboard. `content: false` keeps the story as metadata when payloads must
|
|
93
|
+
stay out. See [Logging](docs/logging.md).
|
|
121
94
|
|
|
122
|
-
##
|
|
95
|
+
## Pause for a human
|
|
123
96
|
|
|
124
|
-
A tool
|
|
125
|
-
|
|
97
|
+
A tool can require approval. The run parks the call and returns immediately;
|
|
98
|
+
no thread waits for the decision.
|
|
126
99
|
|
|
127
100
|
```ruby
|
|
128
|
-
|
|
129
|
-
"
|
|
130
|
-
schema:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
},
|
|
134
|
-
needs_approval: ->(args) { args.fetch("total_usd") > 500 },
|
|
135
|
-
) do |args, context|
|
|
136
|
-
Bookings.create!(
|
|
137
|
-
hotel_id: args.fetch("hotel_id"),
|
|
138
|
-
traveler: context.app.fetch(:traveler),
|
|
139
|
-
)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
agent = Mistri.agent(
|
|
143
|
-
"claude-opus-4-8",
|
|
144
|
-
tools: [book_hotel],
|
|
145
|
-
context: { traveler: current_traveler },
|
|
146
|
-
)
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
Validation runs before the approval predicate, so policy never receives a
|
|
150
|
-
string where the schema promised a number. Invalid calls return a bounded,
|
|
151
|
-
model-readable error and valid siblings still run. Mistri never coerces model
|
|
152
|
-
input implicitly.
|
|
101
|
+
issue_refund = Mistri::Tool.define(
|
|
102
|
+
"issue_refund", "Refunds an order.",
|
|
103
|
+
schema: -> { number :amount_usd, "Refund amount", required: true },
|
|
104
|
+
needs_approval: ->(args) { args.fetch("amount_usd") > 500 },
|
|
105
|
+
) { |args| Refunds.issue!(args) }
|
|
153
106
|
|
|
154
|
-
|
|
107
|
+
agent = Mistri.agent("claude-opus-5-5", tools: [issue_refund])
|
|
155
108
|
|
|
156
|
-
|
|
157
|
-
result = agent.run("Book the corner suite for the Lisbon trip")
|
|
109
|
+
result = agent.run("Refund all 640 dollars of order 1042.")
|
|
158
110
|
result.awaiting_approval? # => true; the handler did not run
|
|
159
111
|
|
|
160
112
|
call = result.pending.fetch(0)
|
|
161
113
|
agent.session.approve(call.id, note: "Approved by finance")
|
|
162
|
-
|
|
114
|
+
agent.resume
|
|
163
115
|
```
|
|
164
116
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
117
|
+
With a durable store, the decision can come from a controller, a job, or a
|
|
118
|
+
console in a different process, days later, using only the session ID and the
|
|
119
|
+
call ID. A later process builds a fresh Agent with its current tools and
|
|
120
|
+
policy; `resume` then revalidates the exact call and carries on. See
|
|
121
|
+
[Sessions and control](docs/sessions.md#human-approval).
|
|
169
122
|
|
|
170
|
-
|
|
171
|
-
[Tool contracts](docs/tool-contracts.md) for schemas, validators, normalizers,
|
|
172
|
-
`Mistri::ToolResult`, hooks, and `ends_turn`.
|
|
123
|
+
## Why Mistri
|
|
173
124
|
|
|
174
|
-
|
|
125
|
+
- **Pause for a human, resume days later.** A gated call parks and the run
|
|
126
|
+
returns; any process can record the decision and resume.
|
|
127
|
+
- **One durable session model.** The same append-only log runs over memory,
|
|
128
|
+
JSONL, Active Record, or your own store: reload, resume, steer, and
|
|
129
|
+
compact without a second state model.
|
|
130
|
+
- **Three providers, no lowest common denominator.** Anthropic, OpenAI, and
|
|
131
|
+
Gemini keep their own reasoning, tool-pairing, and replay rules.
|
|
132
|
+
- **Tools cross a real boundary.** Model arguments are validated and frozen
|
|
133
|
+
before your policy or handlers see them; invalid calls fail loudly.
|
|
134
|
+
- **Your Gemfile.lock grows by one line.** Zero runtime gem dependencies;
|
|
135
|
+
Rails adapters load only when required.
|
|
136
|
+
- **Tested against the real APIs.** The live suite runs the control,
|
|
137
|
+
persistence, delegation, MCP, and structured-output paths against actual
|
|
138
|
+
Anthropic, OpenAI, and Gemini endpoints; the default CI suite is hermetic.
|
|
175
139
|
|
|
176
|
-
|
|
177
|
-
append-only record on local disk without a database:
|
|
140
|
+
## Choose the right layer
|
|
178
141
|
|
|
179
|
-
|
|
180
|
-
store = Mistri::Stores::JSONL.new("tmp/mistri-sessions")
|
|
181
|
-
session = Mistri::Session.new(store: store)
|
|
142
|
+
These projects solve different problems:
|
|
182
143
|
|
|
183
|
-
|
|
184
|
-
|
|
144
|
+
| Need | Start with |
|
|
145
|
+
| --- | --- |
|
|
146
|
+
| A durable, approvable agent loop in any Ruby application, on a session store you own, with no runtime dependencies | **Mistri** |
|
|
147
|
+
| A full AI framework: many providers, media, embeddings, and agents persisted through Rails | [RubyLLM](https://github.com/crmne/ruby_llm) |
|
|
148
|
+
| Agents expressed through Rails controllers, actions, callbacks, views, and Active Job | [Active Agent](https://github.com/activeagents/activeagent) |
|
|
185
149
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
150
|
+
Mistri is deliberately not a terminal UI, hosted agent service, media client,
|
|
151
|
+
or job system. It owns the model loop, the tool boundary, the event stream,
|
|
152
|
+
and the session record; your application owns authorization, policy,
|
|
153
|
+
presentation, and the meaning of its side effects.
|
|
190
154
|
|
|
191
|
-
|
|
192
|
-
use the optional Active Record adapter:
|
|
155
|
+
## Sessions, steering, and stores
|
|
193
156
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
157
|
+
Sessions persist every message as it completes, so a crash or an abort leaves
|
|
158
|
+
a resumable record with no repair step. Any process can append to a live
|
|
159
|
+
session:
|
|
197
160
|
|
|
198
161
|
```ruby
|
|
199
|
-
|
|
162
|
+
store = Mistri::Stores::JSONL.new("tmp/mistri-sessions")
|
|
163
|
+
session = Mistri::Session.new(store: store)
|
|
200
164
|
|
|
201
|
-
|
|
202
|
-
```
|
|
165
|
+
Mistri.agent("claude-opus-5-5", session: session).run("Start a haiku about the sea.")
|
|
203
166
|
|
|
204
|
-
|
|
205
|
-
|
|
167
|
+
# A later process reloads the same session by ID and continues it.
|
|
168
|
+
reloaded = Mistri::Session.new(store: store, id: session.id)
|
|
169
|
+
Mistri.agent("claude-opus-5-5", session: reloaded).run("Now finish it.")
|
|
206
170
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
)
|
|
171
|
+
# Steering queues a redirect from anywhere, without the Agent object; a
|
|
172
|
+
# run in flight folds it at its next turn.
|
|
173
|
+
reloaded.steer("Make it about the mountains instead.")
|
|
211
174
|
```
|
|
212
175
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
176
|
+
For a database-backed store, run `bin/rails generate mistri:install AgentEntry`
|
|
177
|
+
and use the Active Record adapter, or implement `append(id, entry)` and
|
|
178
|
+
`load(id)` on anything. Only one Agent may run a session at a time; approvals,
|
|
179
|
+
steering, and worker reports may append concurrently. See
|
|
180
|
+
[Sessions and control](docs/sessions.md).
|
|
217
181
|
|
|
218
182
|
## Streaming into any Ruby application
|
|
219
183
|
|
|
@@ -226,93 +190,27 @@ sink = Mistri::Sinks::Coalesced.new(sse) # merge token bursts to UI speed
|
|
|
226
190
|
agent.run(input, &sink)
|
|
227
191
|
```
|
|
228
192
|
|
|
229
|
-
`Mistri::Sinks::ActionCable` is available for Rails, but no Railtie is
|
|
230
|
-
The same event stream works in Sinatra, Rack, a WebSocket server, a
|
|
231
|
-
job, or a test.
|
|
232
|
-
the types they use and ignore the rest.
|
|
233
|
-
|
|
234
|
-
## Logging
|
|
235
|
-
|
|
236
|
-
One assignment makes every run tell its story in your log:
|
|
237
|
-
|
|
238
|
-
```ruby
|
|
239
|
-
Mistri.logger = Rails.logger # or any Logger-compatible object
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
```text
|
|
243
|
-
[mistri 0a1b2c3d] run "What is 2 plus 3?" (gpt-5.6, 3 tools)
|
|
244
|
-
[mistri 0a1b2c3d] turn 1 done tool_use (312 in / 48 out)
|
|
245
|
-
[mistri 0a1b2c3d] tool add#7f3a {"a":2,"b":3}
|
|
246
|
-
[mistri 0a1b2c3d] tool add#7f3a ok 12ms "5"
|
|
247
|
-
[mistri 0a1b2c3d] text "The sum is 5."
|
|
248
|
-
[mistri 0a1b2c3d] turn 2 done stop (410 in / 22 out)
|
|
249
|
-
[mistri 0a1b2c3d] done completed in 1.2s, 2 turns, 722 in / 70 out, $0.0042
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
A turn line lands when the model finishes speaking, so it precedes the tool
|
|
253
|
-
executions that turn requested. The short `#id` on tool lines pairs
|
|
254
|
-
concurrent same-name calls; an `approval needed` line carries the full call
|
|
255
|
-
id, which is what `session.approve` takes. Failed tools and retries log at
|
|
256
|
-
warn and provider errors at error, while expected stops (a cancel, a budget
|
|
257
|
-
ceiling) log calmly. Cached prompt tokens count toward "in" and are called
|
|
258
|
-
out, dollar cost appears whenever pricing is known (including a known
|
|
259
|
-
$0.0000), and hidden bytes in any value render as visible escapes.
|
|
260
|
-
Sub-agents log under their own worker label (`[mistri researcher#89bb20de]`)
|
|
261
|
-
exactly once, whichever process runs them; a `worker` report line appears
|
|
262
|
-
wherever a sink watched the spawn. Interleaved lines stay whole as long as
|
|
263
|
-
the logger serializes writes, which stdlib `Logger` and Rails' do. A `task`
|
|
264
|
-
logs one frame around all its fix passes.
|
|
265
|
-
|
|
266
|
-
By default the lines carry payloads: inputs, thinking, arguments, results.
|
|
267
|
-
That is the point in development, and it is fine in production too when
|
|
268
|
-
your log pipeline is where you want the story (shipping these lines to your
|
|
269
|
-
log platform gives you agent observability for free). When payloads must
|
|
270
|
-
stay out of a log, `content: false` keeps the whole story as metadata:
|
|
271
|
-
names, ids, durations, sizes, tokens, cost, and statuses, and error, crash,
|
|
272
|
-
and retry text reduces to its byte size while classes and reasons stay. `level: :debug`
|
|
273
|
-
floors the ordinary lines, `truncate` bounds rendered values, and a wrong
|
|
274
|
-
assignment raises at assignment time:
|
|
275
|
-
|
|
276
|
-
```ruby
|
|
277
|
-
Mistri.logger = Mistri::Sinks::Logger.new(logger, content: false, level: :debug)
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
Composing per run (`agent.run(input, &Mistri::Sinks::Logger.new(logger))`)
|
|
281
|
-
is deliberately smaller: event lines under a bare `[mistri]` tag, no
|
|
282
|
-
framing, and forwarded child events rendered with their origin, since no
|
|
283
|
-
child sink exists to log them. Logger calls are synchronous on
|
|
284
|
-
the run's own threads, so a slow logger slows the run: keep the destination
|
|
285
|
-
local (stdout, a file) and let your log shipper make the network hop, or
|
|
286
|
-
buffer at the logger layer. Logging never breaks a run: construction and
|
|
287
|
-
every write are contained, and a failing logger warns once per run and that
|
|
288
|
-
run's sink goes quiet. With no logger assigned the cost is one nil check
|
|
289
|
-
per run; with one assigned, delta events short-circuit without allocating
|
|
290
|
-
and per-line work is bounded by the truncation limit, not the payload.
|
|
193
|
+
`Mistri::Sinks::ActionCable` is available for Rails, but no Railtie is
|
|
194
|
+
required. The same event stream works in Sinatra, Rack, a WebSocket server, a
|
|
195
|
+
background job, or a test.
|
|
291
196
|
|
|
292
197
|
## Long conversations and structured tasks
|
|
293
198
|
|
|
294
|
-
Compaction is on by default for
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
199
|
+
Compaction is on by default for models with a known context window: near the
|
|
200
|
+
limit, a summary takes the place of the earlier turns and the run continues
|
|
201
|
+
from it, while the exact history stays in the store. On Claude and GPT the
|
|
202
|
+
provider's own compaction writes it, and elsewhere Mistri asks for it. Task
|
|
203
|
+
mode requires a final JSON value matching a schema, validated locally whenever
|
|
204
|
+
the run completes normally.
|
|
298
205
|
|
|
299
206
|
```ruby
|
|
300
207
|
agent.context_usage
|
|
301
|
-
# => { tokens: 141_000, window: 1_000_000, fraction: 0.141
|
|
302
|
-
|
|
303
|
-
agent.compact # explicit checkpoint; returns nil when nothing should compact
|
|
304
|
-
```
|
|
208
|
+
# => { tokens: 141_000, window: 1_000_000, fraction: 0.141, estimated: 0,
|
|
209
|
+
# threshold: 867_904, remaining: 726_904 }
|
|
305
210
|
|
|
306
|
-
Task mode requires a final JSON value matching a schema. Providers use native
|
|
307
|
-
constraints only when they can represent the contract; Mistri validates the
|
|
308
|
-
answer locally in every case.
|
|
309
|
-
|
|
310
|
-
```ruby
|
|
311
211
|
schema = {
|
|
312
212
|
type: "object",
|
|
313
|
-
properties: {
|
|
314
|
-
"tiers" => { type: "array", items: { type: "string" } },
|
|
315
|
-
},
|
|
213
|
+
properties: { "tiers" => { type: "array", items: { type: "string" } } },
|
|
316
214
|
required: ["tiers"],
|
|
317
215
|
}
|
|
318
216
|
|
|
@@ -320,41 +218,34 @@ result = agent.task("Extract the pricing tiers.", schema: schema)
|
|
|
320
218
|
result.output # parsed and validated
|
|
321
219
|
```
|
|
322
220
|
|
|
323
|
-
Task validation applies when that invocation completes normally. An approval
|
|
324
|
-
suspension or `ends_turn` handoff returns with `output` nil; after settlement or
|
|
325
|
-
the human answer, call `task` again if structured output is still required.
|
|
326
|
-
|
|
327
221
|
See [Sessions and control](docs/sessions.md) for compaction boundaries,
|
|
328
|
-
cross-provider replay,
|
|
222
|
+
cross-provider replay, and transcripts.
|
|
329
223
|
|
|
330
224
|
## Sub-agents
|
|
331
225
|
|
|
332
|
-
Delegate work into a child session so exploration does not consume the
|
|
333
|
-
context. Only the report returns
|
|
334
|
-
|
|
226
|
+
Delegate work into a child session so exploration does not consume the
|
|
227
|
+
parent's context. Only the report returns; the full child transcript stays
|
|
228
|
+
linked and inspectable.
|
|
335
229
|
|
|
336
230
|
```ruby
|
|
337
231
|
researcher = Mistri::SubAgent.new(
|
|
338
232
|
name: "researcher",
|
|
339
233
|
description: "Reads pages and answers factual questions.",
|
|
340
|
-
provider: Mistri.provider("claude-haiku-
|
|
341
|
-
system: "Research the question. Return findings and sources.",
|
|
234
|
+
provider: Mistri.provider("claude-haiku-5-5"),
|
|
342
235
|
tools: [fetch_page],
|
|
343
236
|
)
|
|
344
237
|
|
|
345
|
-
agent = Mistri.agent("claude-opus-
|
|
238
|
+
agent = Mistri.agent("claude-opus-5-5", tools: [researcher.tool])
|
|
346
239
|
```
|
|
347
240
|
|
|
348
|
-
Mistri also provides
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
[Sub-agents](docs/sub-agents.md), including the runtime, concurrency, and lease
|
|
352
|
-
limits a production dispatcher must understand.
|
|
241
|
+
Mistri also provides an open spawn tool, background dispatch through your own
|
|
242
|
+
queue, worker reports, steering, stopping, and a management console. See
|
|
243
|
+
[Sub-agents](docs/sub-agents.md).
|
|
353
244
|
|
|
354
245
|
## Model Context Protocol
|
|
355
246
|
|
|
356
|
-
Bridge tools over Streamable HTTP or stdio, then apply the same local
|
|
357
|
-
and validation boundary:
|
|
247
|
+
Bridge tools over Streamable HTTP or stdio, then apply the same local
|
|
248
|
+
approval and validation boundary:
|
|
358
249
|
|
|
359
250
|
```ruby
|
|
360
251
|
client = Mistri::MCP::Client.new(
|
|
@@ -362,58 +253,33 @@ client = Mistri::MCP::Client.new(
|
|
|
362
253
|
token: -> { connection.bearer_token },
|
|
363
254
|
)
|
|
364
255
|
|
|
365
|
-
tools = Mistri::MCP.tools(
|
|
366
|
-
client,
|
|
367
|
-
prefix: "linear",
|
|
368
|
-
gates: { "create_issue" => true },
|
|
369
|
-
)
|
|
256
|
+
tools = Mistri::MCP.tools(client, prefix: "linear", gates: { "create_issue" => true })
|
|
370
257
|
```
|
|
371
258
|
|
|
372
|
-
Remote URLs default to public HTTPS with validated, pinned DNS answers
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
optional host adapter.
|
|
377
|
-
|
|
378
|
-
Read [MCP](docs/mcp.md) for stdio, OAuth, private-network policy, schema
|
|
379
|
-
authority, response limits, and large-result resource links.
|
|
259
|
+
Remote URLs default to public HTTPS with validated, pinned DNS answers, and
|
|
260
|
+
an unconfirmed tool call is never replayed automatically. A server with a long
|
|
261
|
+
tool list can be bridged with `deferred: true`, and the model then finds and
|
|
262
|
+
loads the tools it needs. See [MCP](docs/mcp.md).
|
|
380
263
|
|
|
381
264
|
## Skills, definitions, and workspaces
|
|
382
265
|
|
|
383
|
-
- **Skills** expose one-line descriptions until the model
|
|
266
|
+
- **Skills** expose one-line descriptions until the model asks for the full
|
|
384
267
|
`SKILL.md`, keeping the system prompt small.
|
|
385
|
-
- **Definitions** load an agent's model,
|
|
386
|
-
|
|
268
|
+
- **Definitions** load an agent's model, tools, and prompt from Markdown with
|
|
269
|
+
YAML frontmatter.
|
|
387
270
|
- **Workspaces** give the built-in read, write, edit, find, and list tools a
|
|
388
|
-
directory, memory value, Active Record table, or single host-owned
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
changes. A Directory workspace rejects lexical escape and traversal through
|
|
393
|
-
existing symlinks in a stable, host-controlled tree; it is not an
|
|
394
|
-
operating-system sandbox. See
|
|
395
|
-
[Context and workspaces](docs/context-and-workspaces.md) and the runnable
|
|
271
|
+
directory, a memory value, an Active Record table, or a single host-owned
|
|
272
|
+
value; the edit engine refuses ambiguous matches.
|
|
273
|
+
|
|
274
|
+
See [Context and workspaces](docs/context-and-workspaces.md) and the runnable
|
|
396
275
|
[`page_editor.rb`](examples/page_editor.rb) example.
|
|
397
276
|
|
|
398
277
|
## Reliability contract
|
|
399
278
|
|
|
400
279
|
Mistri makes failures explicit, but it does not pretend distributed side
|
|
401
|
-
effects are exactly once:
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
replays an ambiguous tool call; the Agent bridge returns the uncertainty as
|
|
405
|
-
an error-marked tool result.
|
|
406
|
-
- A process can crash after a handler commits an external write but before the
|
|
407
|
-
result reaches the session. Tools with side effects must be idempotent or
|
|
408
|
-
reconcilable.
|
|
409
|
-
- Budgets are checked between model-visible turns, so they are soft ceilings.
|
|
410
|
-
- Provider and MCP records default to an 8 MiB per-record limit; streaming has
|
|
411
|
-
no total-size limit while each record remains safe.
|
|
412
|
-
- `Mistri::AbortSignal` is an in-process cooperative signal. Cross-process
|
|
413
|
-
worker control uses the configured lock adapter and is also cooperative.
|
|
414
|
-
|
|
415
|
-
The complete operational contract, event lifecycle, retry behavior, pricing
|
|
416
|
-
rules, and sink guidance live in [Reliability](docs/reliability.md).
|
|
280
|
+
effects are exactly once: tools with external side effects must be idempotent
|
|
281
|
+
or reconcilable, and budgets are soft ceilings checked between turns. The
|
|
282
|
+
complete operational contract lives in [Reliability](docs/reliability.md).
|
|
417
283
|
|
|
418
284
|
## Documentation
|
|
419
285
|
|
|
@@ -425,6 +291,7 @@ GitHub:
|
|
|
425
291
|
| [Documentation index](docs/README.md) | The complete task-oriented map |
|
|
426
292
|
| [Tool contracts](docs/tool-contracts.md) | Schemas, validation, approval, hooks, results, and handoff |
|
|
427
293
|
| [Sessions and control](docs/sessions.md) | Stores, replay, approvals, steering, compaction, and transcripts |
|
|
294
|
+
| [Logging](docs/logging.md) | The run log, its options, and its operational guarantees |
|
|
428
295
|
| [Context and workspaces](docs/context-and-workspaces.md) | Skills, definitions, context transforms, host-owned memory, and editable documents |
|
|
429
296
|
| [Sub-agents](docs/sub-agents.md) | Specialists, spawning, dispatch, locks, reports, and control |
|
|
430
297
|
| [MCP](docs/mcp.md) | HTTP and stdio, OAuth, egress policy, limits, and schema handling |
|
|
@@ -441,29 +308,23 @@ $ bundle exec rake test
|
|
|
441
308
|
$ bundle exec rubocop
|
|
442
309
|
```
|
|
443
310
|
|
|
444
|
-
Live tests read provider keys from the gitignored
|
|
445
|
-
`.env.development.local` file:
|
|
311
|
+
Live tests read provider keys from the gitignored `.env.development.local`:
|
|
446
312
|
|
|
447
313
|
```console
|
|
448
|
-
$
|
|
314
|
+
$ bundle exec rake live
|
|
449
315
|
$ bundle exec rake integration
|
|
450
|
-
$ MISTRI_INTEGRATION_MODELS=claude-opus-4-8 bundle exec rake integration
|
|
451
316
|
```
|
|
452
317
|
|
|
453
|
-
|
|
454
|
-
Anthropic, OpenAI, and Gemini model by default when the corresponding keys are
|
|
455
|
-
present. See
|
|
456
|
-
[CONTRIBUTING.md](CONTRIBUTING.md) for the project contract.
|
|
318
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for the project contract.
|
|
457
319
|
|
|
458
320
|
## Compatibility and support
|
|
459
321
|
|
|
460
322
|
Mistri supports Ruby 3.2 and newer. It is pre-1.0: minor releases may include
|
|
461
|
-
intentional contract changes with an explicit migration path
|
|
462
|
-
[UPGRADING.md](UPGRADING.md)
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
described in [SECURITY.md](SECURITY.md).
|
|
323
|
+
intentional contract changes with an explicit migration path; read
|
|
324
|
+
[UPGRADING.md](UPGRADING.md) before upgrading. Use
|
|
325
|
+
[GitHub issues](https://github.com/mcheemaa/mistri/issues) for reproducible
|
|
326
|
+
bugs and focused proposals, and report vulnerabilities privately as described
|
|
327
|
+
in [SECURITY.md](SECURITY.md).
|
|
467
328
|
|
|
468
329
|
## Credits
|
|
469
330
|
|