scout-ai 2.0.0 → 2.2.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/.vimproject +135 -55
- data/README.md +2 -1
- data/VERSION +1 -1
- data/doc/Improvements.md +490 -148
- data/doc/Model.md +53 -10
- data/doc/StartHere.md +44 -19
- data/doc/developer/Architecture.md +25 -6
- data/doc/developer/Backends.md +207 -48
- data/doc/developer/ChatLifecycle.md +121 -20
- data/doc/developer/DelegationInternals.md +320 -34
- data/doc/developer/DesignPrinciples.md +205 -16
- data/doc/developer/PathEngine.md +628 -0
- data/doc/developer/PromptProcessing.md +332 -82
- data/doc/developer/Provenance.md +402 -44
- data/doc/developer/Sandbox.md +213 -0
- data/doc/user/BuildingAgents.md +130 -18
- data/doc/user/Cookbook.md +29 -8
- data/doc/user/CoreConcepts.md +7 -6
- data/doc/user/Delegation.md +166 -15
- data/doc/user/GettingStarted.md +20 -16
- data/doc/user/ManagingContext.md +155 -17
- data/doc/user/MultiAgentWorkflows.md +105 -15
- data/doc/user/Python.md +11 -1
- data/doc/user/RunningInference.md +90 -47
- data/doc/user/ToolCalling.md +134 -29
- data/doc/user/WritingChats.md +56 -27
- data/lib/scout/llm/agent/attach.rb +64 -0
- data/lib/scout/llm/agent/chat.rb +32 -0
- data/lib/scout/llm/agent/construction.rb +64 -0
- data/lib/scout/llm/agent/conversation.rb +304 -0
- data/lib/scout/llm/agent/delegate.rb +56 -238
- data/lib/scout/llm/agent/path/edit.rb +230 -0
- data/lib/scout/llm/agent/path/patch.rb +252 -0
- data/lib/scout/llm/agent/path/workflow_kinds.rb +175 -0
- data/lib/scout/llm/agent/path.rb +1777 -0
- data/lib/scout/llm/agent/save.rb +11 -9
- data/lib/scout/llm/agent/workflow.rb +79 -17
- data/lib/scout/llm/agent.rb +151 -27
- data/lib/scout/llm/ask.rb +37 -27
- data/lib/scout/llm/backends/anthropic.rb +1 -1
- data/lib/scout/llm/backends/bedrock.rb +3 -2
- data/lib/scout/llm/backends/default.rb +131 -32
- data/lib/scout/llm/backends/glm.rb +28 -1
- data/lib/scout/llm/backends/huggingface.rb +1 -1
- data/lib/scout/llm/backends/ollama.rb +1 -1
- data/lib/scout/llm/backends/openai.rb +7 -6
- data/lib/scout/llm/backends/openwebui.rb +14 -7
- data/lib/scout/llm/backends/relay.rb +8 -2
- data/lib/scout/llm/chat/agent_meta.rb +24 -60
- data/lib/scout/llm/chat/parse.rb +1 -1
- data/lib/scout/llm/chat/process/files.rb +10 -0
- data/lib/scout/llm/chat/process/meta.rb +5 -7
- data/lib/scout/llm/chat/process/tools.rb +104 -52
- data/lib/scout/llm/chat/prompt/epoch_tool_compactation.rb +355 -0
- data/lib/scout/llm/chat/prompt/inbox.rb +188 -0
- data/lib/scout/llm/chat/prompt/shorten_tools.rb +797 -13
- data/lib/scout/llm/chat/prompt/shorten_tools_epoch.rb +1 -365
- data/lib/scout/llm/chat/prompt/shorten_tools_epoch_increment.rb +1 -0
- data/lib/scout/llm/chat/prompt.rb +24 -10
- data/lib/scout/llm/chat/provenance/live.rb +1080 -0
- data/lib/scout/llm/chat/provenance/tokens.rb +386 -0
- data/lib/scout/llm/chat/provenance.rb +352 -626
- data/lib/scout/llm/chat.rb +8 -2
- data/lib/scout/llm/embed.rb +15 -3
- data/lib/scout/llm/image.rb +4 -1
- data/lib/scout/llm/mcp.rb +4 -2
- data/lib/scout/llm/request_context.rb +234 -0
- data/lib/scout/llm/sandbox.rb +263 -0
- data/lib/scout/llm/tools/call.rb +163 -42
- data/lib/scout/llm/tools/definition.rb +48 -0
- data/lib/scout/llm/tools/knowledge_base.rb +1 -0
- data/lib/scout/llm/tools/mcp.rb +50 -43
- data/lib/scout/llm/tools/workflow.rb +90 -20
- data/lib/scout/llm/tools.rb +14 -41
- data/lib/scout/model/decision/base.rb +43 -0
- data/lib/scout/model/decision/jev.rb +161 -0
- data/lib/scout/model/python/torch.rb +1 -1
- data/research/clear-tools-inherit.md +171 -0
- data/research/path-engine-dc1-dc2-dc3-fixes.md +279 -0
- data/research/path-kind-chat-role.md +96 -0
- data/research/path-kind-contract-fixes-engine.md +307 -0
- data/research/scout-ai-runtime-availability.md +65 -0
- data/research/subsys/README.md +127 -0
- data/research/subsys/agent-delegation.md +201 -0
- data/research/subsys/agent-society.md +275 -0
- data/research/subsys/agentworkflow.md +233 -0
- data/research/subsys/backends.md +221 -0
- data/research/subsys/chat.md +314 -0
- data/research/subsys/embed-image.md +244 -0
- data/research/subsys/entry-cli.md +253 -0
- data/research/subsys/model-ml.md +326 -0
- data/research/subsys/provenance.md +290 -0
- data/research/subsys/tools.md +334 -0
- data/scout-ai.gemspec +72 -26
- data/scout_commands/agent/ask +8 -7
- data/scout_commands/llm/abridged +40 -0
- data/scout_commands/llm/ask +9 -9
- data/scout_commands/llm/md +2 -0
- data/scout_commands/llm/prov +845 -80
- data/scout_commands/llm/word +4 -0
- data/share/word/reference.docx +0 -0
- data/test/integration/scout/model/decision/test_jev.rb +144 -0
- data/test/scout/llm/agent/test_attach.rb +117 -0
- data/test/scout/llm/agent/test_conversation.rb +407 -0
- data/test/scout/llm/agent/test_delegate.rb +209 -0
- data/test/scout/llm/agent/test_path.rb +1812 -0
- data/test/scout/llm/agent/test_path_edit.rb +908 -0
- data/test/scout/llm/agent/test_path_errors.rb +390 -0
- data/test/scout/llm/agent/test_path_filesystem.rb +532 -0
- data/test/scout/llm/agent/test_path_patch.rb +233 -0
- data/test/scout/llm/agent/test_path_promotion.rb +386 -0
- data/test/scout/llm/agent/test_path_workflow_integration.rb +665 -0
- data/test/scout/llm/agent/test_save.rb +70 -15
- data/test/scout/llm/agent/test_workflow.rb +130 -4
- data/test/scout/llm/backends/test_anthropic.rb +4 -4
- data/test/scout/llm/backends/test_bedrock.rb +4 -4
- data/test/scout/llm/backends/test_format_other.rb +43 -0
- data/test/scout/llm/backends/test_ollama.rb +2 -2
- data/test/scout/llm/backends/test_openwebui.rb +12 -8
- data/test/scout/llm/backends/test_reasoning.rb +114 -0
- data/test/scout/llm/chat/agent_meta_fixtures.rb +109 -22
- data/test/scout/llm/chat/prompt/test_epoch_tool_compactation.rb +612 -0
- data/test/scout/llm/chat/prov_plot_fixtures.rb +131 -0
- data/test/scout/llm/chat/test_agent_meta.rb +40 -80
- data/test/scout/llm/chat/test_agent_meta_provenance.rb +200 -28
- data/test/scout/llm/chat/test_agent_meta_tokens.rb +112 -7
- data/test/scout/llm/chat/test_agent_view.rb +178 -0
- data/test/scout/llm/chat/test_live_report.rb +282 -0
- data/test/scout/llm/chat/test_live_workload.rb +193 -0
- data/test/scout/llm/chat/test_parse.rb +32 -2
- data/test/scout/llm/chat/test_prompt.rb +411 -0
- data/test/scout/llm/chat/test_prov_cli.rb +708 -13
- data/test/scout/llm/chat/test_prov_cli_live.rb +152 -0
- data/test/scout/llm/chat/test_prov_plot.rb +213 -0
- data/test/scout/llm/chat/test_prov_timeline.rb +355 -0
- data/test/scout/llm/chat/test_provenance.rb +67 -22
- data/test/scout/llm/chat/test_provenance_index.rb +479 -0
- data/test/scout/llm/chat/test_society_view.rb +159 -0
- data/test/scout/llm/test_agent.rb +1 -1
- data/test/scout/llm/test_embed.rb +103 -1
- data/test/scout/llm/test_request_context.rb +299 -0
- data/test/scout/llm/test_sandbox.rb +249 -0
- data/test/scout/llm/tools/test_agent_pairing.rb +150 -0
- data/test/scout/llm/tools/test_call_delegation_conflict.rb +316 -0
- data/test/scout/llm/tools/test_definition.rb +332 -0
- data/test/scout/llm/tools/test_jobs_file.rb +211 -0
- data/test/scout/llm/tools/test_mcp.rb +37 -8
- data/test/scout/llm/tools/test_workflow.rb +45 -1
- data/test/scout/model/decision/test_jev.rb +453 -0
- data/test/scout/model/python/huggingface/causal/test_next_token.rb +7 -10
- data/test/scout/model/python/huggingface/test_causal.rb +11 -2
- data/test/scout/model/python/huggingface/test_classification.rb +5 -3
- data/test/scout/model/python/test_availability.rb +116 -0
- data/test/scout/model/python/test_torch.rb +54 -2
- data/test/support/availability.rb +72 -174
- data/test/support/fake_clients.rb +18 -9
- data/test/support/fixtures.rb +75 -6
- data/test/support/mock_backend.rb +9 -1
- data/test/support/test_fixtures.rb +156 -0
- data/test/test_helper.rb +14 -4
- metadata +71 -25
- data/research/ChatAnalyst-required-changes.md +0 -167
- data/research/agent-delegation-analysis.md +0 -810
- data/research/agent-meta-provenance-integration-plan.md +0 -622
- data/research/agent-workflow-analysis.md +0 -1120
- data/research/backends-analysis.md +0 -836
- data/research/chat-core-analysis.md +0 -946
- data/research/chatanalyst-provenance/00-baseline.md +0 -30
- data/research/chatanalyst-provenance/01-repo-map.md +0 -60
- data/research/chatanalyst-provenance/02-event-reconstruction.md +0 -55
- data/research/chatanalyst-provenance/03-duplication-evidence.md +0 -45
- data/research/chatanalyst-provenance/04-tooling-root-cause.md +0 -57
- data/research/chatanalyst-provenance/05-fix-plan.md +0 -46
- data/research/chatanalyst-provenance/07-critic-review.md +0 -25
- data/research/chatanalyst-provenance/final-report.md +0 -45
- data/research/chatanalyst-provenance/resumption.md +0 -37
- data/research/coding-philosophy-analysis.md +0 -928
- data/research/commands-analysis.md +0 -947
- data/research/multi-agent-patterns-analysis.md +0 -853
- data/research/prompt-strategies-analysis.md +0 -630
- data/research/prov-verbosity-fix-notes.md +0 -77
- data/research/provenance-analysis.md +0 -469
- data/research/synthesis-report.md +0 -487
- data/research/tools-system-analysis.md +0 -779
data/doc/Model.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
The Model subsystem in scout-ai provides a small, composable framework to wrap machine‑learning models (pure Ruby, Python/PyTorch, and Hugging Face Transformers) with a consistent API for evaluation, training, feature extraction, post‑processing, and persistence.
|
|
4
4
|
|
|
5
|
+
> **Not about LLM endpoints.** This page is about the *ML model* subsystem
|
|
6
|
+
> (PyTorch/Hugging Face wrappers). For inference-provider endpoints
|
|
7
|
+
> (OpenAI, Anthropic, Ollama…), see
|
|
8
|
+
> [user/RunningInference.md](user/RunningInference.md) and
|
|
9
|
+
> [user/CoreConcepts.md](user/CoreConcepts.md).
|
|
10
|
+
|
|
5
11
|
It consists of a base class (ScoutModel) and higher-level implementations:
|
|
6
12
|
- PythonModel — instantiate and drive Python classes via ScoutPython.
|
|
7
13
|
- TorchModel — drive arbitrary PyTorch modules with simple training/eval loops, tensor helpers, and state save/load.
|
|
@@ -54,7 +60,7 @@ Execution helpers (util/run.rb):
|
|
|
54
60
|
- extract_features(sample=nil) { ... }, extract_features_list(list=nil) { ... } — define or run feature extraction.
|
|
55
61
|
|
|
56
62
|
Persistence (util/save.rb):
|
|
57
|
-
- save — writes options.json; saves each defined Proc to a .rb file beside the state (using method_source); calls save_state if @state exists.
|
|
63
|
+
- save — writes options.json; saves each defined Proc to a .rb file beside the state (using method_source); calls save_state if @state exists. (`save_method` has a String branch, but it tests an undefined local instead of `value` and would raise NameError if ever reached; Procs are the only supported form today.)
|
|
58
64
|
- restore — loads behavior (.rb), options, and sets up init/load_state/save_state blocks.
|
|
59
65
|
- save_state { |state_file, state| ... } — define or execute logic to persist the current @state.
|
|
60
66
|
- load_state { |state_file| ... } — define or execute logic to restore @state.
|
|
@@ -134,7 +140,9 @@ TmpFile.with_path do |dir|
|
|
|
134
140
|
model2.eval(1) # => 2
|
|
135
141
|
|
|
136
142
|
model3 = ScoutModel.new dir, delta: 2
|
|
137
|
-
model3.eval(1) # => 3
|
|
143
|
+
model3.eval(1) # => 3 — but only because `delta` was never
|
|
144
|
+
# saved into options.json above; see the
|
|
145
|
+
# restore-precedence note in §HuggingfaceModel
|
|
138
146
|
end
|
|
139
147
|
```
|
|
140
148
|
|
|
@@ -169,6 +177,10 @@ Highlights:
|
|
|
169
177
|
- Set criterion/optimizer or rely on defaults:
|
|
170
178
|
- TorchModel.optimizer(model, training_args) — default SGD(lr: 0.01).
|
|
171
179
|
- TorchModel.criterion(model, training_args) — default MSELoss.
|
|
180
|
+
- The default train path builds both for you (`@criterion ||=
|
|
181
|
+
TorchModel.criterion(...)`, `@optimizer ||=
|
|
182
|
+
TorchModel.optimizer(...)`); setting either by hand is only needed to
|
|
183
|
+
override the defaults.
|
|
172
184
|
- options[:training_args] may set epochs, batch_size, learning_rate, etc.
|
|
173
185
|
|
|
174
186
|
Example (from tests/test_torch.rb)
|
|
@@ -176,7 +188,7 @@ Example (from tests/test_torch.rb)
|
|
|
176
188
|
TorchModel.init_python
|
|
177
189
|
model = TorchModel.new dir
|
|
178
190
|
model.state = ScoutPython.torch.nn.Linear.new(1, 1)
|
|
179
|
-
|
|
191
|
+
# criterion is optional — the default train path uses MSELoss
|
|
180
192
|
|
|
181
193
|
model.extract_features { |f| [f] }
|
|
182
194
|
model.post_process { |v, list| list ? v.map(&:first) : v.first }
|
|
@@ -230,7 +242,7 @@ You typically use one of its specializations:
|
|
|
230
242
|
Purpose: text classification (logits to label).
|
|
231
243
|
|
|
232
244
|
Behavior:
|
|
233
|
-
- eval: calls Python eval_model(model, tokenizer, texts,
|
|
245
|
+
- eval: calls Python `eval_model(model, tokenizer, texts, return_logits=True)` to produce logits. Known mismatch: the Ruby layer passes `options[:locate_tokens]` in the fourth positional slot, which lands on the `return_logits` parameter — unset (nil) falls back to Python's `True` default, `locate_tokens: false` is the only way to change it, and a `return_logits:` option is both ignored here and excluded from the model-loader kwargs.
|
|
234
246
|
- post_process: argmax across logits, mapping to class labels if provided.
|
|
235
247
|
|
|
236
248
|
Training:
|
|
@@ -268,7 +280,7 @@ Training:
|
|
|
268
280
|
- labels: rewards for each pair.
|
|
269
281
|
- After training, it reloads state from disk.
|
|
270
282
|
|
|
271
|
-
Usage example (test/test_causal.rb):
|
|
283
|
+
Usage example (test/scout/model/python/huggingface/test_causal.rb):
|
|
272
284
|
```ruby
|
|
273
285
|
model = CausalModel.new 'mistralai/Mistral-7B-Instruct-v0.3'
|
|
274
286
|
model.init
|
|
@@ -318,13 +330,15 @@ A key pattern is to keep evaluation logic generic and tailor feature extraction
|
|
|
318
330
|
- extract_features(sample) and extract_features_list(list) let you shape inputs into the structure your model consumes.
|
|
319
331
|
- post_process(result) or post_process_list(list) convert raw outputs to your final format (e.g., argmax to label, logits to softmax).
|
|
320
332
|
|
|
321
|
-
ExTRI2 workflow example (SequenceClassification)
|
|
333
|
+
ExTRI2 workflow example (SequenceClassification) — the same example is expanded at the end of this document
|
|
322
334
|
```ruby
|
|
323
|
-
# tri_sentences task uses a Huggingface SequenceClassification model
|
|
324
|
-
tri_model
|
|
335
|
+
# tri_sentences task uses a Huggingface SequenceClassification model;
|
|
336
|
+
# tri_model points at a local model directory (a scout path or an
|
|
337
|
+
# absolute path, resolved by the caller)
|
|
338
|
+
tri_model = tri_model.find unless File.exist?(tri_model)
|
|
325
339
|
model = HuggingfaceModel.new 'SequenceClassification', tri_model, nil,
|
|
326
340
|
tokenizer_args: { model_max_length: 512, truncation: true },
|
|
327
|
-
return_logits: true
|
|
341
|
+
return_logits: true # NOTE: no-op today, see 'Known issues' below
|
|
328
342
|
|
|
329
343
|
# Convert the TSV row into the sequence model expects
|
|
330
344
|
model.extract_features do |_, feature_list|
|
|
@@ -387,6 +401,35 @@ Common methods:
|
|
|
387
401
|
- save — writes options, behavior files, and calls save_state if @state exists.
|
|
388
402
|
- restore — loads behavior files and options; state is lazy-initialized by calling init/load_state when used next.
|
|
389
403
|
|
|
404
|
+
**Restore precedence (actual behavior, and a known bug).** `load_options`
|
|
405
|
+
reads `options.json` when it exists and merges the *constructor* options into
|
|
406
|
+
it — the saved values win. In practice this means:
|
|
407
|
+
|
|
408
|
+
- Passing a different option to the constructor of a model whose directory
|
|
409
|
+
already has an `options.json` does **not** change the effective value.
|
|
410
|
+
- A fresh `checkpoint` argument is likewise ignored on `HuggingfaceModel`
|
|
411
|
+
when the directory exists: `#initialize` writes it into the options *after*
|
|
412
|
+
`super` has restored, and the `init` block then prefers `state_file` (an
|
|
413
|
+
existing saved-state directory) over `options[:checkpoint]`.
|
|
414
|
+
- When the directory has no `options.json` (a genuinely fresh model), the
|
|
415
|
+
constructor options — and a fresh `checkpoint` — are the effective ones.
|
|
416
|
+
|
|
417
|
+
Treat constructor options as first-run settings only. To change a persisted
|
|
418
|
+
option, edit `options.json` (or start from a clean directory). This inversion
|
|
419
|
+
is a known open bug, not a contract.
|
|
420
|
+
|
|
421
|
+
### Known issues (tracked in [Improvements.md](Improvements.md))
|
|
422
|
+
|
|
423
|
+
- `eval_model`'s fourth Python parameter is `return_logits`, but the Ruby
|
|
424
|
+
layer passes `options[:locate_tokens]` in that slot: unset falls back to
|
|
425
|
+
Python's `True` default, `locate_tokens: false` is the only effective
|
|
426
|
+
override, and a `return_logits:` option is never forwarded (it is in the
|
|
427
|
+
loader's `except` list) — which is why the `return_logits: true` lines in the
|
|
428
|
+
examples above are annotated as no-ops.
|
|
429
|
+
- `save_method`'s `String` branch tests an undefined local instead of `value`
|
|
430
|
+
and would raise `NameError` if ever reached; passing a Proc is the only
|
|
431
|
+
supported form today.
|
|
432
|
+
|
|
390
433
|
---
|
|
391
434
|
|
|
392
435
|
## Devices, tensors, and memory notes (PyTorch)
|
|
@@ -485,7 +528,7 @@ The ExTRI2 workflow builds sequence classification models to validate TRI senten
|
|
|
485
528
|
```ruby
|
|
486
529
|
model = HuggingfaceModel.new 'SequenceClassification', tri_model, nil,
|
|
487
530
|
tokenizer_args: { model_max_length: 512, truncation: true },
|
|
488
|
-
return_logits: true
|
|
531
|
+
return_logits: true # NOTE: no-op today, see 'Known issues' below
|
|
489
532
|
|
|
490
533
|
model.extract_features do |_, rows|
|
|
491
534
|
rows.map do |text, tf, tg|
|
data/doc/StartHere.md
CHANGED
|
@@ -18,6 +18,10 @@ The user documentation explains how to use Scout-AI to build agents, define
|
|
|
18
18
|
tools, configure inference, and orchestrate multi-agent workflows. It is
|
|
19
19
|
organized around concepts and tasks, not internal classes.
|
|
20
20
|
|
|
21
|
+
The ML model subsystem (`ScoutModel`, `TorchModel`, Hugging Face wrappers)
|
|
22
|
+
is documented separately in [Model.md](Model.md); it is intentionally
|
|
23
|
+
outside the agent/LLM layer.
|
|
24
|
+
|
|
21
25
|
**Start here:**
|
|
22
26
|
1. [user/GettingStarted.md](user/GettingStarted.md) — install, configure, first conversation.
|
|
23
27
|
2. [user/CoreConcepts.md](user/CoreConcepts.md) — the four building blocks.
|
|
@@ -41,9 +45,13 @@ delegation internals, and the provenance system. It is concise and links to
|
|
|
41
45
|
|
|
42
46
|
→ Go to **[../research/](../research/)** investigation documents.
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
The maintained set is `research/subsys/` — one probe-verified study per
|
|
49
|
+
subsystem (chat, backends, tools, agent delegation, agent directories,
|
|
50
|
+
AgentWorkflow, provenance, embeddings/RAG, model, CLI entry). Each is an
|
|
51
|
+
investigation record, not normative documentation: it may state sharp edges
|
|
52
|
+
and open questions that `doc/` does not. One design file is additionally
|
|
53
|
+
retained — `provenance-navigation-design.md`, the rationale tracked by
|
|
54
|
+
[Improvements.md](Improvements.md) A1.
|
|
47
55
|
|
|
48
56
|
---
|
|
49
57
|
|
|
@@ -56,9 +64,12 @@ call graphs, implementation discoveries, and design rationale.
|
|
|
56
64
|
| **Add tool support** | user/ToolCalling → (user/Python if needed) |
|
|
57
65
|
| **Configure inference** | user/RunningInference → user/ManagingContext |
|
|
58
66
|
| **Understand the internals** | developer/Architecture → developer/ChatLifecycle → developer/Backends |
|
|
59
|
-
| **
|
|
60
|
-
| **
|
|
61
|
-
| **
|
|
67
|
+
| **Extend the agent Path engine** | developer/PathEngine |
|
|
68
|
+
| **Understand the sandbox / execution boundaries** | developer/Sandbox |
|
|
69
|
+
| **Track and inspect provenance** | developer/Provenance |
|
|
70
|
+
| **Write idiomatic code** | developer/DesignPrinciples |
|
|
71
|
+
| **Use the ML/PyTorch model subsystem** | Model.md |
|
|
72
|
+
| **Use the CLI** | user/Cookbook (CLI quick reference) |
|
|
62
73
|
|
|
63
74
|
---
|
|
64
75
|
|
|
@@ -88,19 +99,13 @@ doc/
|
|
|
88
99
|
│ ├── PromptProcessing.md
|
|
89
100
|
│ ├── Backends.md
|
|
90
101
|
│ ├── DelegationInternals.md
|
|
91
|
-
│
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
├──
|
|
96
|
-
├──
|
|
97
|
-
|
|
98
|
-
├── tools-system-analysis.md
|
|
99
|
-
├── provenance-analysis.md
|
|
100
|
-
├── multi-agent-patterns-analysis.md
|
|
101
|
-
├── coding-philosophy-analysis.md
|
|
102
|
-
├── commands-analysis.md
|
|
103
|
-
└── synthesis-report.md
|
|
102
|
+
│ ├── Provenance.md
|
|
103
|
+
│ ├── PathEngine.md
|
|
104
|
+
│ └── Sandbox.md
|
|
105
|
+
└── ../research/ ← probe-verified subsystem studies
|
|
106
|
+
├── subsys/ ← one study per subsystem
|
|
107
|
+
├── scout-ai-runtime-availability.md
|
|
108
|
+
└── provenance-navigation-design.md ← retained for Improvements.md A1
|
|
104
109
|
```
|
|
105
110
|
|
|
106
111
|
Each layer becomes progressively more detailed and less stable:
|
|
@@ -108,3 +113,23 @@ Each layer becomes progressively more detailed and less stable:
|
|
|
108
113
|
```
|
|
109
114
|
Code → Investigation (research/) → Developer docs (doc/developer/) → User docs (doc/user/)
|
|
110
115
|
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## The three layers and their authority
|
|
120
|
+
|
|
121
|
+
- **`doc/` is authoritative.** If a page here states a contract, behavior,
|
|
122
|
+
or limit, that statement is the current truth for Scout-AI. When code
|
|
123
|
+
changes, the page changes with it; docs lagging code is a defect, not a
|
|
124
|
+
preference.
|
|
125
|
+
- **`research/` holds investigation records, not authority.** A research
|
|
126
|
+
file documents the rationale, evidence, and open questions behind a
|
|
127
|
+
decision at the time it was made. It may state sharp edges and
|
|
128
|
+
uncertainty, but it never silently overrides `doc/`: on conflict,
|
|
129
|
+
`doc/` wins, and the research file should be updated or retired.
|
|
130
|
+
- **`var/cortex/` is mutable working state.** The agent workspace —
|
|
131
|
+
conversations, briefs, artifacts — is scratch space for active
|
|
132
|
+
investigation. Anything durable that came out of it must be promoted
|
|
133
|
+
into `doc/` or `research/`; nothing under `var/` is citable as
|
|
134
|
+
authoritative.
|
|
135
|
+
|
|
@@ -55,8 +55,10 @@ For deeper investigation of any subsystem, see the corresponding
|
|
|
55
55
|
```
|
|
56
56
|
scout-ai.rb
|
|
57
57
|
└─ scout/llm/ask.rb (requires scout, chat)
|
|
58
|
-
└─ scout/llm/chat.rb (requires chat/annotation, parse, process,
|
|
59
|
-
|
|
58
|
+
└─ scout/llm/chat.rb (requires utils, tools, chat/{annotation, parse, process,
|
|
59
|
+
persist, prompt, provenance, tool_calls, agent_meta})
|
|
60
|
+
└─ scout/llm/agent.rb (requires ask, agent/{chat, iterate, conversation,
|
|
61
|
+
delegate, attach, save, workflow})
|
|
60
62
|
└─ scout/llm/embed.rb
|
|
61
63
|
└─ scout/llm/image.rb
|
|
62
64
|
└─ scout/llm/tools/ (workflow, knowledge_base, mcp, call)
|
|
@@ -83,8 +85,10 @@ A single inference request flows through the layers as follows:
|
|
|
83
85
|
into a canonical Array of Hashes via `Chat.parse`. Options embedded in the
|
|
84
86
|
chat (via `option:`, `model:`, `endpoint:` directives) are extracted into
|
|
85
87
|
the options hash.
|
|
86
|
-
3. **Tool extraction**: Tool/
|
|
87
|
-
messages. Workflow tasks and KB databases are converted to tool definitions
|
|
88
|
+
3. **Tool extraction**: Tool/mcp/kb/association roles are extracted from
|
|
89
|
+
messages. Workflow tasks and KB databases are converted to tool definitions;
|
|
90
|
+
`introduce:` roles are rewritten into `user:` documentation messages and
|
|
91
|
+
create no tools.
|
|
88
92
|
4. **Prompt preparation**: The message array passes through
|
|
89
93
|
`Chat.prepare_prompt` which applies context-management strategies
|
|
90
94
|
(e.g., `shorten_tools`). This is **ephemeral** — the stored chat is never
|
|
@@ -107,7 +111,7 @@ A single inference request flows through the layers as follows:
|
|
|
107
111
|
|---|---|---|
|
|
108
112
|
| A new LLM provider | `lib/scout/llm/backends/<provider>.rb` | Define a module that `prepend`s `<Provider>Methods` and `include`s `Backend::ClassMethods`. Override `query`, `process_response`, `format_messages` as needed. |
|
|
109
113
|
| A new tool type | `lib/scout/llm/tools/<type>.rb` | Define a module method that returns `{ name => [executor, definition] }` hashes. |
|
|
110
|
-
| A new prompt strategy |
|
|
114
|
+
| A new prompt strategy | `lib/scout/llm/chat/prompt/<strategy>.rb` (add the `require_relative` in `chat/prompt.rb`): either add a `when` arm to the `case` in `Chat.prepare_prompt`, register a proc in `Chat::REGISTERED_STRATEGIES` (populated by callers, not by the built-ins), or fall back to a public `Chat.<strategy>` method, which the `else` branch calls by name. Select with the `prompt_strategies:` option or `PROMPT_STRATEGY` env/config key, or bypass entirely with a `Proc`. See [PromptProcessing.md](PromptProcessing.md). |
|
|
111
115
|
| A new agent type | `Agent/<Name>/` directory with `start_chat`, `agent.rb`, or `workflow.rb`. | Conventional discovery. |
|
|
112
116
|
| A new chat-task workflow | `include_workflow AgentWorkflow` in your Workflow module. | Use `chat_task`, `helper :agent`, etc. |
|
|
113
117
|
|
|
@@ -119,8 +123,23 @@ A single inference request flows through the layers as follows:
|
|
|
119
123
|
- [PromptProcessing.md](PromptProcessing.md) — Context management internals.
|
|
120
124
|
- [Backends.md](Backends.md) — Backend abstraction and inference loop.
|
|
121
125
|
- [DelegationInternals.md](DelegationInternals.md) — Multi-agent mechanics.
|
|
122
|
-
- [Provenance.md](Provenance.md) — Provenance data model and traversal.
|
|
126
|
+
- [Provenance.md](Provenance.md) — Provenance data model, compact index, and traversal.
|
|
123
127
|
- [DesignPrinciples.md](DesignPrinciples.md) — Coding philosophy and idioms.
|
|
128
|
+
- [Sandbox.md](Sandbox.md) — Which tools are sandboxed, the two-layer
|
|
129
|
+
allowlist model, and the path-visibility recovery procedure.
|
|
124
130
|
|
|
125
131
|
> For detailed code investigations of each subsystem, browse the
|
|
126
132
|
> [research/](../../research/) directory.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Tests that pin this
|
|
137
|
+
|
|
138
|
+
There is no unit test for the dependency graph itself; the layering claims
|
|
139
|
+
above are pinned indirectly by what loads standalone in the suites. The
|
|
140
|
+
prompt-strategy registry mechanism (`REGISTERED_STRATEGIES` + the
|
|
141
|
+
`prepare_prompt` case dispatch) is directly pinned by
|
|
142
|
+
`test/scout/llm/chat/test_prompt.rb`
|
|
143
|
+
(`test_prepare_prompt_forwards_save_file_only_to_strategies_that_accept_it`,
|
|
144
|
+
`test_prompt_strategies_survive_tool_call_re_entry`). Per-subsystem test
|
|
145
|
+
anchors are listed in each subsystem document.
|
data/doc/developer/Backends.md
CHANGED
|
@@ -6,8 +6,9 @@ provider differences. It is intended for framework contributors.
|
|
|
6
6
|
|
|
7
7
|
> For the user-facing guide on configuring inference endpoints and providers,
|
|
8
8
|
> see [../user/RunningInference.md](../user/RunningInference.md).
|
|
9
|
-
> For
|
|
10
|
-
>
|
|
9
|
+
> For the probe-verified subsystem study (backend registry, the shared loop,
|
|
10
|
+
> provider adapters, sharp edges), see
|
|
11
|
+
> [../../research/subsys/backends.md](../../research/subsys/backends.md) under `research/`.
|
|
11
12
|
|
|
12
13
|
---
|
|
13
14
|
|
|
@@ -96,25 +97,62 @@ Each iteration:
|
|
|
96
97
|
|
|
97
98
|
### Implicit iteration limiting
|
|
98
99
|
|
|
99
|
-
There is no hard loop counter.
|
|
100
|
-
bounds
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
There is no hard loop counter. The loop ends when `query()` returns no tool
|
|
101
|
+
calls; what bounds it is context size, not a round limit. The default
|
|
102
|
+
`epoch_tool_compactation` strategy (see
|
|
103
|
+
[PromptProcessing.md](PromptProcessing.md)) no-ops at or below **50** total
|
|
104
|
+
tool calls, keeps the most recent **20** at full fidelity, may keep up to
|
|
105
|
+
**80** compacted, and replaces an oversized pair (output over
|
|
106
|
+
`DEFAULT_SHORT_STRING_LENGTH * 2` — 400 characters — or a string argument over
|
|
107
|
+
`DEFAULT_SHORT_STRING_LENGTH` — 200) with a metadata record. These are
|
|
108
|
+
strategy bounds on the *prompt*,
|
|
109
|
+
not a request round limit — there is no `MAX_TOOL_CALLS` in the loop.
|
|
104
110
|
|
|
105
111
|
---
|
|
106
112
|
|
|
107
113
|
## Error handling and retries
|
|
108
114
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
The shared loop never retries a failed `query`: a raise propagates out of
|
|
116
|
+
`ask` unchanged (no backoff, no retry). Before re-raising it is tagged with
|
|
117
|
+
`Backend::BackendException` and given a `.chat` accessor pointing at a saved
|
|
118
|
+
debug copy of the failing messages/options/meta (`Backend::ClassMethods.ask`,
|
|
119
|
+
`lib/scout/llm/backends/default.rb`).
|
|
120
|
+
|
|
121
|
+
Two retry constructs exist in this repository, and neither lives in the
|
|
122
|
+
shared `query` loop:
|
|
123
|
+
|
|
124
|
+
- **OpenWebUI `query`** wraps its HTTP POST in `Misc.insist` — by default
|
|
125
|
+
**4 attempts** (`times = 4`) with sub-second sleeps drawn from
|
|
126
|
+
`[0] + [0.001, 0.01, 0.1, 0.5]` (scout-essentials `Misc.insist`), so the
|
|
127
|
+
total backoff is well under a second.
|
|
128
|
+
- **Relay polling** loops `sleep 1; retry` while a reply file has not landed
|
|
129
|
+
(`LLM::Relay.gather` in `backends/relay.rb`; the shared-loop path uses
|
|
130
|
+
`Backend::ClassMethods.gather_response` in `backends/default.rb`).
|
|
131
|
+
This is a transport-level wait, not an error retry.
|
|
132
|
+
|
|
133
|
+
- **Agent-level exception handling** — `LLM::Agent#chat`
|
|
134
|
+
(`lib/scout/llm/agent.rb`) rescues a backend raise and calls the
|
|
135
|
+
user-supplied `process_exception` Proc (an accessor on the agent);
|
|
136
|
+
returning truthy triggers a `retry`, anything else re-raises. Without the
|
|
137
|
+
Proc the agent saves its chat (non-fatally) and re-raises.
|
|
138
|
+
|
|
139
|
+
### Parallel agent fan-out
|
|
140
|
+
|
|
141
|
+
`LLM.process_calls` (`lib/scout/llm/tools/call.rb`) is the shared tool
|
|
142
|
+
executor, so it also collects tool results that are `LLM::Agent` objects and
|
|
143
|
+
runs their `agent.chat (return_messages: true)` rounds concurrently through
|
|
144
|
+
`Open.traverse`. The concurrency is
|
|
145
|
+
`Scout::Config.get(:cpus, :agent_ask, :agents, env: 'ASK_AGENTS', default: 3)`.
|
|
146
|
+
Each answer is paired back with the tool call that produced it by position
|
|
147
|
+
(a duplicate agent in one round gets its own answer, not the first one's).
|
|
148
|
+
Workflow `Step` results are produced first (`Workflow.produce`, with the
|
|
149
|
+
live-workload `jobs_file` sidecar described in
|
|
150
|
+
[Provenance.md](Provenance.md)); agent fan-out runs after that, so an agent
|
|
151
|
+
tool result never blocks on unrelated workflow jobs.
|
|
152
|
+
|
|
153
|
+
There is no streaming either (`stream_results` does not exist): every request
|
|
154
|
+
is blocking and returns once complete. The only `stream` token in the
|
|
155
|
+
subsystem is ollama's `stream: false`.
|
|
118
156
|
|
|
119
157
|
---
|
|
120
158
|
|
|
@@ -122,13 +160,26 @@ Backends wrap the API call in `begin/rescue`:
|
|
|
122
160
|
|
|
123
161
|
`LLM.ask` selects a backend via:
|
|
124
162
|
|
|
125
|
-
1. **
|
|
126
|
-
|
|
127
|
-
`
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
163
|
+
1. **Endpoint configuration** — `options[:endpoint]`; when set, its options
|
|
164
|
+
are defaulted from `Scout.etc.AI[<endpoint>].yaml` (which may specify a
|
|
165
|
+
`backend`). A non-empty endpoint with no YAML raises
|
|
166
|
+
`Endpoint not found <name>`. Writing those files is the user-facing
|
|
167
|
+
mechanism; see [../user/RunningInference.md](../user/RunningInference.md)
|
|
168
|
+
for the hand-written YAML and `-ck key=value` forms.
|
|
169
|
+
2. **Explicit `:backend` option** — `options[:backend]` selects the module.
|
|
170
|
+
3. **Config default** — `Scout::Config.get(:backend, :ask, :llm, env:
|
|
171
|
+
'ASK_BACKEND,LLM_BACKEND')`, defaulting to `:responses`.
|
|
172
|
+
4. **Hard-coded dispatch** — A `case` statement maps `:openai`, `:anthropic`,
|
|
173
|
+
`:responses`, `:ollama`, `:vllm`, `:openwebui`, `:huggingface`, `:relay`,
|
|
174
|
+
`:bedrock`, `:glm` to their modules, requiring each file lazily.
|
|
175
|
+
5. **Plugin registry** — Anything else is looked up in `LLM::BACKENDS`
|
|
176
|
+
(populated by `LLM.register_backend(name, module)`), else it raises
|
|
177
|
+
`RuntimeError: Unknown backend: <name>`.
|
|
178
|
+
|
|
179
|
+
**Model configuration is shared, not per-provider.** `client_options` pulls
|
|
180
|
+
`Scout::Config.get(:model, ...)` through a single `key:model` token, so a
|
|
181
|
+
`model` set for one backend leaks to all of them unless the endpoint YAML
|
|
182
|
+
pins it per backend.
|
|
132
183
|
|
|
133
184
|
---
|
|
134
185
|
|
|
@@ -136,44 +187,128 @@ Backends wrap the API call in `begin/rescue`:
|
|
|
136
187
|
|
|
137
188
|
### OpenAI (`LLM::OpenAI`)
|
|
138
189
|
|
|
139
|
-
- **API client**: `OpenAI::Client` (ruby-openai gem).
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
- **
|
|
190
|
+
- **API client**: `OpenAI::Client` (ruby-openai gem). The
|
|
191
|
+
`request_timeout` default differs by construction path: `client_options`
|
|
192
|
+
defaults it to **1200** and `client` to **12000** — and since
|
|
193
|
+
`prepare_client` merges `client_options` into the options before calling
|
|
194
|
+
`client`, the 1200 default wins in practice unless overridden (the gem's
|
|
195
|
+
own default is 120).
|
|
196
|
+
- **Tool format**: `type: 'function'` with nested `function:` key; the
|
|
197
|
+
`format_tool_call`/`format_tool_output` pair emits assistant
|
|
198
|
+
`tool_calls` and `role: 'tool'` + `tool_call_id` messages.
|
|
199
|
+
- **Usage meta**: `pt/ct/tt` plus `inference_id`, `provider_response_id`,
|
|
200
|
+
cumulative `_s` and per-conversation `_c` counters; `cct/cwt/rt` come from
|
|
201
|
+
the `*_details` sub-hashes when present.
|
|
202
|
+
- **Images**: No override — inherits the default `input_image` shape
|
|
203
|
+
(`{type: :input_image, image_url: <data-uri-or-url>}`), which is what the
|
|
204
|
+
OpenAI/Responses/ollama family uses. `encode_image` maps only
|
|
205
|
+
jpg/jpeg/png to a correct MIME type; webp/gif/tiff fall through to the
|
|
206
|
+
literal `image/extension` MIME and produce a malformed data URI.
|
|
207
|
+
- **Defaults subschema**: its `parameters[:defaults]` delete looks at the
|
|
208
|
+
wrapper level, where `:parameters` is always nil, so the scout-specific
|
|
209
|
+
`defaults` subschema still reaches the provider (dead code — see
|
|
210
|
+
[Improvements.md](../Improvements.md) issue 8).
|
|
146
211
|
|
|
147
212
|
### Anthropic (`LLM::Anthropic`)
|
|
148
213
|
|
|
149
|
-
- **API client**:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
214
|
+
- **API client**: `Anthropic::Client`; `extra_options` forces a `max_tokens`
|
|
215
|
+
default of 1000.
|
|
216
|
+
- **Tool format**: Flat `name`, `description`, `input_schema` (renamed from
|
|
217
|
+
`parameters`; no `function:` nesting); `type: 'function'` is rewritten to
|
|
218
|
+
`type: 'custom'`. Tool outputs go back as a user-role
|
|
219
|
+
`tool_result` content block, not an assistant `tool_calls` message.
|
|
220
|
+
- **Usage meta**: `input_tokens`/`output_tokens` → `pt`/`ct`,
|
|
221
|
+
`cache_read_input_tokens` → `cct`, `cache_creation_input_tokens` → `cwt`;
|
|
222
|
+
`tt` is computed (input+output).
|
|
223
|
+
- **Images**: `LLM::Anthropic` defines no image handling of its own, so it
|
|
224
|
+
inherits the default `input_image` shape — there is **no** Anthropic
|
|
225
|
+
base64 `image` block. `embed_query` raises
|
|
226
|
+
`'Anthropic does not offer embeddings'`.
|
|
153
227
|
- **System messages**: Extracted from the message list and sent as a separate
|
|
154
228
|
parameter.
|
|
155
229
|
- **Reasoning**: Extracts `thinking` content blocks.
|
|
156
230
|
|
|
157
231
|
### Ollama (`LLM::OLlama`)
|
|
158
232
|
|
|
159
|
-
- **API client**:
|
|
233
|
+
- **API client**: `Ollama.new(credentials: {address:, bearer_token:})` from
|
|
234
|
+
the `ollama-ai` gem; when `url` is unset the *gem* defaults the address to
|
|
235
|
+
`http://localhost:11434`.
|
|
160
236
|
- **Tool format**: Uses OpenAI-compatible format.
|
|
161
|
-
- **
|
|
162
|
-
|
|
237
|
+
- **Requests**: `query` sets `stream: false` explicitly — the only explicit
|
|
238
|
+
stream token in the subsystem; responses arrive as an Array of chunks that
|
|
239
|
+
`process_response` flattens.
|
|
240
|
+
- **Usage meta**: `update_meta` returns `{}` (no usage available).
|
|
241
|
+
- **Embedding**: `embed_query` posts to `api/embed`.
|
|
242
|
+
|
|
243
|
+
### Responses API (`LLM::Responses`) — the default backend
|
|
163
244
|
|
|
164
|
-
|
|
245
|
+
- **The config default**: when neither `endpoint`, nor an explicit
|
|
246
|
+
`:backend`, nor a config `backend` selects anything, this is what runs
|
|
247
|
+
(`DEFAULT_MODEL = 'gpt-5-nano'`).
|
|
248
|
+
- **Session state**: threads `previous_response_id` between rounds so context
|
|
249
|
+
stays server-side; a `previous_response: 'false'` option disables the
|
|
250
|
+
threading.
|
|
251
|
+
- **Tool calls** arrive as `output[]` entries of type `function_call` /
|
|
252
|
+
`mcp_call`.
|
|
165
253
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
254
|
+
### vLLM (`LLM::VLLM`)
|
|
255
|
+
|
|
256
|
+
- Includes `ResponsesMethods`; the **only** override is `parse_tool_call`,
|
|
257
|
+
which strips a `channel…<word>` fragment that vLLM injects into tool names.
|
|
258
|
+
Everything else (client, messages, usage) is the Responses API.
|
|
170
259
|
|
|
171
260
|
### Bedrock (`LLM::Bedrock`)
|
|
172
261
|
|
|
173
262
|
- **Multi-provider**: Routes to different providers (Anthropic, Meta, etc.) via
|
|
174
|
-
the AWS Bedrock API
|
|
175
|
-
-
|
|
176
|
-
|
|
263
|
+
the AWS Bedrock API, using provider-prefixed model IDs
|
|
264
|
+
(`anthropic.claude-3-sonnet`, …) configured through `BEDROCK_MODEL_ID`;
|
|
265
|
+
credentials come from `AWS_REGION` / `AWS_ACCESS_KEY_ID` /
|
|
266
|
+
`AWS_SECRET_ACCESS_KEY`. A `type:` option (default `:messages`) switches
|
|
267
|
+
between a Messages-style body and a flat prompt body.
|
|
268
|
+
- **Standalone**: does not compose `Backend::ClassMethods` — it defines its
|
|
269
|
+
own `ask` with no meta, no prompt strategies and no `save_file`, returning
|
|
270
|
+
joined text. `LLM::Bedrock.embed` exists but no `LLM.embed` dispatch branch
|
|
271
|
+
reaches it; embeddings must be requested from it directly.
|
|
272
|
+
- **Tool-call concurrency**: its private tool loop executes the tool calls of
|
|
273
|
+
one model round through `Open.traverse` with
|
|
274
|
+
`Scout::Config.get(:cpus, :tool_calling, default: 3)` — a Bedrock-local
|
|
275
|
+
knob, distinct from the shared agent fan-out below.
|
|
276
|
+
|
|
277
|
+
### GLM (`LLM::GLM`)
|
|
278
|
+
|
|
279
|
+
- A Chat-Completions backend (`DEFAULT_MODEL = 'glm-turbo'`) that prepends
|
|
280
|
+
`GLMAIMethods` over `OpenAIMethods` and overrides only `format_other`: it
|
|
281
|
+
adds `image` (base64 `image_url`), `pdf` (`input_file` with
|
|
282
|
+
`file_data`/`file_url`) and `websearch` roles, and drops
|
|
283
|
+
`previous_response_id` messages. It is the one backend that sends images as
|
|
284
|
+
a true nested `image_url` block rather than the default `input_image`
|
|
285
|
+
shape. Dispatched from `LLM.ask` but **not** from `LLM.embed`.
|
|
286
|
+
|
|
287
|
+
### HuggingFace (`LLM::Huggingface`)
|
|
288
|
+
|
|
289
|
+
- Prepends `HuggingfaceMethods` over `OpenAIMethods` (chat-completions shape).
|
|
290
|
+
**Not an HTTP API**: `prepare_client` builds a `CausalModel` through Scout's
|
|
291
|
+
Python support, with the model/checkpoint/generation options taken from
|
|
292
|
+
`HUGGINGFACE_MODEL`/`HF_MODEL` (`DEFAULT_MODEL` is nil). `query` converts
|
|
293
|
+
PyCall results back with `ScoutPython.dict2hash`.
|
|
294
|
+
- It is the only adapter that actually strips
|
|
295
|
+
`parameters[:defaults]` out of a tool definition before sending (OpenAI's
|
|
296
|
+
equivalent line looks at the wrapper level, where `:parameters` is nil —
|
|
297
|
+
see [Improvements.md](../Improvements.md) issue 8).
|
|
298
|
+
|
|
299
|
+
### Relay (`LLM::Relay`)
|
|
300
|
+
|
|
301
|
+
- Fire-and-poll over `scp`: `options[:relay]` in the shared `ask` uploads the
|
|
302
|
+
messages to `<server>:.scout/var/query/` and gathers the reply; standalone
|
|
303
|
+
`LLM::Relay.ask` scps options+question to `var/ask/` and polls for
|
|
304
|
+
`reply/<id>.json` with `sleep 1; retry`. Not streaming.
|
|
305
|
+
|
|
306
|
+
### OpenWebUI (`LLM::OpenWebUI`)
|
|
307
|
+
|
|
308
|
+
- Includes `OpenAIMethods`; `client()` returns a plain Hash spec rather than
|
|
309
|
+
an SDK client, and `query()` posts `parameters.to_json` with a bearer
|
|
310
|
+
header. Its HTTP POST is the one place a backend retries
|
|
311
|
+
(`Misc.insist`, ~4 sub-second attempts).
|
|
177
312
|
|
|
178
313
|
---
|
|
179
314
|
|
|
@@ -187,8 +322,32 @@ Backends wrap the API call in `begin/rescue`:
|
|
|
187
322
|
| `lib/scout/llm/backends/anthropic.rb` | Anthropic provider |
|
|
188
323
|
| `lib/scout/llm/backends/ollama.rb` | Ollama provider |
|
|
189
324
|
| `lib/scout/llm/backends/responses.rb` | OpenAI Responses API |
|
|
190
|
-
| `lib/scout/llm/backends/vllm.rb` | vLLM provider |
|
|
191
|
-
| `lib/scout/llm/backends/
|
|
325
|
+
| `lib/scout/llm/backends/vllm.rb` | vLLM provider (Responses + tool-name unmangling) |
|
|
326
|
+
| `lib/scout/llm/backends/openwebui.rb` | OpenWebUI provider (Hash client, `Misc.insist` retry) |
|
|
327
|
+
| `lib/scout/llm/backends/huggingface.rb` | HuggingFace provider |
|
|
328
|
+
| `lib/scout/llm/backends/relay.rb` | Relay (scp round-trip) provider |
|
|
329
|
+
| `lib/scout/llm/backends/bedrock.rb` | AWS Bedrock provider (standalone `ask`) |
|
|
330
|
+
| `lib/scout/llm/backends/glm.rb` | GLM provider (image/pdf/websearch formatting) |
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
## Tests that pin this
|
|
335
|
+
|
|
336
|
+
No unit test pins the shared `chain_tools` loop or the backend-selection
|
|
337
|
+
ladder directly; they are exercised end-to-end by the per-backend suites.
|
|
338
|
+
`LLM::Relay` has no unit test at all — it shells out to `scp` and has no
|
|
339
|
+
client seam, so its unit test stays disabled (see the comment at the top of
|
|
340
|
+
`test/scout/llm/backends/test_relay.rb`).
|
|
341
|
+
|
|
342
|
+
| Area | Test file | Representative cases |
|
|
343
|
+
|---|---|---|
|
|
344
|
+
| Backend selection / tool chains | `test/scout/llm/test_ask.rb` | `test_knowledge_base_ask_tool_chain`, `test_knowledge_base_association_tool_chain` |
|
|
345
|
+
| Anthropic | `test/scout/llm/backends/test_anthropic.rb` | `test_tool`, `test_tool_call_output_weather`, `test_json_output` |
|
|
346
|
+
| Bedrock | `test/scout/llm/backends/test_bedrock.rb` | `test_ask`, `test_ask_prompt_type`, `test_tool_loop` |
|
|
347
|
+
| HuggingFace | `test/scout/llm/backends/test_huggingface.rb` | `test_format_tool_call`, `test_ask_with_fake_client`, `test_ask_tool_loop_with_fake_client` |
|
|
348
|
+
| Ollama | `test/scout/llm/backends/test_ollama.rb` | `test_ask`, `test_tool`, `test_embeddings` |
|
|
349
|
+
| OpenWebUI | `test/scout/llm/backends/test_openwebui.rb` | `test_ask_request_construction` |
|
|
350
|
+
| Reasoning blocks | `test/scout/llm/backends/test_reasoning.rb` | 12 cases over provider `reasoning`/`thinking` extraction |
|
|
192
351
|
|
|
193
352
|
---
|
|
194
353
|
|
|
@@ -196,4 +355,4 @@ Backends wrap the API call in `begin/rescue`:
|
|
|
196
355
|
|
|
197
356
|
- [../user/RunningInference.md](../user/RunningInference.md) — User guide for endpoints and providers.
|
|
198
357
|
- [PromptProcessing.md](PromptProcessing.md) — Context management integrated into the backend.
|
|
199
|
-
- [../../research/backends
|
|
358
|
+
- [../../research/subsys/backends.md](../../research/subsys/backends.md) — Probe-verified subsystem study (registry, shared loop, provider adapters).
|