scout-ai 2.1.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.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +133 -58
  3. data/README.md +2 -1
  4. data/VERSION +1 -1
  5. data/doc/Improvements.md +490 -148
  6. data/doc/Model.md +53 -10
  7. data/doc/StartHere.md +44 -19
  8. data/doc/developer/Architecture.md +25 -6
  9. data/doc/developer/Backends.md +207 -48
  10. data/doc/developer/ChatLifecycle.md +121 -20
  11. data/doc/developer/DelegationInternals.md +319 -33
  12. data/doc/developer/DesignPrinciples.md +205 -16
  13. data/doc/developer/PathEngine.md +628 -0
  14. data/doc/developer/PromptProcessing.md +332 -82
  15. data/doc/developer/Provenance.md +388 -40
  16. data/doc/developer/Sandbox.md +213 -0
  17. data/doc/user/BuildingAgents.md +130 -18
  18. data/doc/user/Cookbook.md +29 -8
  19. data/doc/user/CoreConcepts.md +7 -6
  20. data/doc/user/Delegation.md +166 -15
  21. data/doc/user/GettingStarted.md +20 -16
  22. data/doc/user/ManagingContext.md +155 -17
  23. data/doc/user/MultiAgentWorkflows.md +105 -15
  24. data/doc/user/Python.md +11 -1
  25. data/doc/user/RunningInference.md +90 -47
  26. data/doc/user/ToolCalling.md +134 -29
  27. data/doc/user/WritingChats.md +56 -27
  28. data/lib/scout/llm/agent/attach.rb +13 -17
  29. data/lib/scout/llm/agent/chat.rb +32 -0
  30. data/lib/scout/llm/agent/construction.rb +64 -0
  31. data/lib/scout/llm/agent/conversation.rb +304 -0
  32. data/lib/scout/llm/agent/delegate.rb +56 -238
  33. data/lib/scout/llm/agent/path/edit.rb +230 -0
  34. data/lib/scout/llm/agent/path/patch.rb +252 -0
  35. data/lib/scout/llm/agent/path/workflow_kinds.rb +175 -0
  36. data/lib/scout/llm/agent/path.rb +1777 -0
  37. data/lib/scout/llm/agent/save.rb +11 -9
  38. data/lib/scout/llm/agent/workflow.rb +77 -16
  39. data/lib/scout/llm/agent.rb +147 -31
  40. data/lib/scout/llm/ask.rb +28 -17
  41. data/lib/scout/llm/backends/anthropic.rb +1 -1
  42. data/lib/scout/llm/backends/bedrock.rb +3 -2
  43. data/lib/scout/llm/backends/default.rb +127 -34
  44. data/lib/scout/llm/backends/glm.rb +28 -1
  45. data/lib/scout/llm/backends/huggingface.rb +1 -1
  46. data/lib/scout/llm/backends/ollama.rb +1 -1
  47. data/lib/scout/llm/backends/openai.rb +7 -6
  48. data/lib/scout/llm/backends/openwebui.rb +14 -7
  49. data/lib/scout/llm/backends/relay.rb +8 -2
  50. data/lib/scout/llm/chat/agent_meta.rb +24 -60
  51. data/lib/scout/llm/chat/parse.rb +1 -1
  52. data/lib/scout/llm/chat/process/files.rb +10 -0
  53. data/lib/scout/llm/chat/process/meta.rb +5 -7
  54. data/lib/scout/llm/chat/process/tools.rb +104 -49
  55. data/lib/scout/llm/chat/prompt/epoch_tool_compactation.rb +355 -0
  56. data/lib/scout/llm/chat/prompt/inbox.rb +188 -0
  57. data/lib/scout/llm/chat/prompt/shorten_tools.rb +797 -13
  58. data/lib/scout/llm/chat/prompt/shorten_tools_epoch.rb +1 -365
  59. data/lib/scout/llm/chat/prompt/shorten_tools_epoch_increment.rb +1 -0
  60. data/lib/scout/llm/chat/prompt.rb +24 -10
  61. data/lib/scout/llm/chat/provenance/live.rb +1080 -0
  62. data/lib/scout/llm/chat/provenance/tokens.rb +386 -0
  63. data/lib/scout/llm/chat/provenance.rb +343 -676
  64. data/lib/scout/llm/chat.rb +8 -2
  65. data/lib/scout/llm/embed.rb +15 -3
  66. data/lib/scout/llm/image.rb +4 -1
  67. data/lib/scout/llm/mcp.rb +4 -2
  68. data/lib/scout/llm/request_context.rb +234 -0
  69. data/lib/scout/llm/sandbox.rb +263 -0
  70. data/lib/scout/llm/tools/call.rb +163 -42
  71. data/lib/scout/llm/tools/definition.rb +48 -0
  72. data/lib/scout/llm/tools/knowledge_base.rb +1 -0
  73. data/lib/scout/llm/tools/mcp.rb +50 -43
  74. data/lib/scout/llm/tools/workflow.rb +90 -20
  75. data/lib/scout/llm/tools.rb +14 -41
  76. data/lib/scout/model/decision/base.rb +43 -0
  77. data/lib/scout/model/decision/jev.rb +161 -0
  78. data/lib/scout/model/python/torch.rb +1 -1
  79. data/research/clear-tools-inherit.md +171 -0
  80. data/research/path-engine-dc1-dc2-dc3-fixes.md +279 -0
  81. data/research/path-kind-chat-role.md +96 -0
  82. data/research/path-kind-contract-fixes-engine.md +307 -0
  83. data/research/scout-ai-runtime-availability.md +65 -0
  84. data/research/subsys/README.md +127 -0
  85. data/research/subsys/agent-delegation.md +201 -0
  86. data/research/subsys/agent-society.md +275 -0
  87. data/research/subsys/agentworkflow.md +233 -0
  88. data/research/subsys/backends.md +221 -0
  89. data/research/subsys/chat.md +314 -0
  90. data/research/subsys/embed-image.md +244 -0
  91. data/research/subsys/entry-cli.md +253 -0
  92. data/research/subsys/model-ml.md +326 -0
  93. data/research/subsys/provenance.md +290 -0
  94. data/research/subsys/tools.md +334 -0
  95. data/scout-ai.gemspec +71 -27
  96. data/scout_commands/agent/ask +8 -7
  97. data/scout_commands/llm/abridged +40 -0
  98. data/scout_commands/llm/ask +9 -9
  99. data/scout_commands/llm/md +2 -0
  100. data/scout_commands/llm/prov +724 -59
  101. data/scout_commands/llm/word +4 -0
  102. data/share/word/reference.docx +0 -0
  103. data/test/integration/scout/model/decision/test_jev.rb +144 -0
  104. data/test/scout/llm/agent/test_attach.rb +117 -0
  105. data/test/scout/llm/agent/test_conversation.rb +407 -0
  106. data/test/scout/llm/agent/test_delegate.rb +209 -0
  107. data/test/scout/llm/agent/test_path.rb +1812 -0
  108. data/test/scout/llm/agent/test_path_edit.rb +908 -0
  109. data/test/scout/llm/agent/test_path_errors.rb +390 -0
  110. data/test/scout/llm/agent/test_path_filesystem.rb +532 -0
  111. data/test/scout/llm/agent/test_path_patch.rb +233 -0
  112. data/test/scout/llm/agent/test_path_promotion.rb +386 -0
  113. data/test/scout/llm/agent/test_path_workflow_integration.rb +665 -0
  114. data/test/scout/llm/agent/test_save.rb +70 -15
  115. data/test/scout/llm/agent/test_workflow.rb +130 -4
  116. data/test/scout/llm/backends/test_anthropic.rb +4 -4
  117. data/test/scout/llm/backends/test_bedrock.rb +4 -4
  118. data/test/scout/llm/backends/test_format_other.rb +43 -0
  119. data/test/scout/llm/backends/test_ollama.rb +2 -2
  120. data/test/scout/llm/backends/test_openwebui.rb +12 -8
  121. data/test/scout/llm/backends/test_reasoning.rb +114 -0
  122. data/test/scout/llm/chat/agent_meta_fixtures.rb +28 -27
  123. data/test/scout/llm/chat/prompt/test_epoch_tool_compactation.rb +612 -0
  124. data/test/scout/llm/chat/prov_plot_fixtures.rb +131 -0
  125. data/test/scout/llm/chat/test_agent_meta.rb +40 -80
  126. data/test/scout/llm/chat/test_agent_meta_provenance.rb +67 -28
  127. data/test/scout/llm/chat/test_agent_meta_tokens.rb +59 -8
  128. data/test/scout/llm/chat/test_agent_view.rb +178 -0
  129. data/test/scout/llm/chat/test_live_report.rb +282 -0
  130. data/test/scout/llm/chat/test_live_workload.rb +193 -0
  131. data/test/scout/llm/chat/test_parse.rb +32 -2
  132. data/test/scout/llm/chat/test_prompt.rb +411 -0
  133. data/test/scout/llm/chat/test_prov_cli.rb +310 -15
  134. data/test/scout/llm/chat/test_prov_cli_live.rb +152 -0
  135. data/test/scout/llm/chat/test_prov_plot.rb +213 -0
  136. data/test/scout/llm/chat/test_prov_timeline.rb +355 -0
  137. data/test/scout/llm/chat/test_provenance.rb +67 -22
  138. data/test/scout/llm/chat/test_provenance_index.rb +479 -0
  139. data/test/scout/llm/chat/test_society_view.rb +159 -0
  140. data/test/scout/llm/test_agent.rb +1 -1
  141. data/test/scout/llm/test_embed.rb +103 -1
  142. data/test/scout/llm/test_request_context.rb +299 -0
  143. data/test/scout/llm/test_sandbox.rb +249 -0
  144. data/test/scout/llm/tools/test_agent_pairing.rb +150 -0
  145. data/test/scout/llm/tools/test_call_delegation_conflict.rb +316 -0
  146. data/test/scout/llm/tools/test_definition.rb +332 -0
  147. data/test/scout/llm/tools/test_jobs_file.rb +211 -0
  148. data/test/scout/llm/tools/test_mcp.rb +37 -8
  149. data/test/scout/llm/tools/test_workflow.rb +45 -1
  150. data/test/scout/model/decision/test_jev.rb +453 -0
  151. data/test/scout/model/python/huggingface/causal/test_next_token.rb +7 -10
  152. data/test/scout/model/python/huggingface/test_causal.rb +11 -2
  153. data/test/scout/model/python/huggingface/test_classification.rb +5 -3
  154. data/test/scout/model/python/test_availability.rb +116 -0
  155. data/test/scout/model/python/test_torch.rb +54 -2
  156. data/test/support/availability.rb +72 -174
  157. data/test/support/fake_clients.rb +18 -9
  158. data/test/support/fixtures.rb +75 -6
  159. data/test/support/mock_backend.rb +9 -1
  160. data/test/support/test_fixtures.rb +156 -0
  161. data/test/test_helper.rb +14 -4
  162. metadata +70 -26
  163. data/research/ChatAnalyst-required-changes.md +0 -167
  164. data/research/agent-delegation-analysis.md +0 -810
  165. data/research/agent-meta-provenance-integration-plan.md +0 -622
  166. data/research/agent-workflow-analysis.md +0 -1120
  167. data/research/backends-analysis.md +0 -836
  168. data/research/chat-core-analysis.md +0 -946
  169. data/research/chatanalyst-provenance/00-baseline.md +0 -30
  170. data/research/chatanalyst-provenance/01-repo-map.md +0 -60
  171. data/research/chatanalyst-provenance/02-event-reconstruction.md +0 -55
  172. data/research/chatanalyst-provenance/03-duplication-evidence.md +0 -45
  173. data/research/chatanalyst-provenance/04-tooling-root-cause.md +0 -57
  174. data/research/chatanalyst-provenance/05-fix-plan.md +0 -46
  175. data/research/chatanalyst-provenance/07-critic-review.md +0 -25
  176. data/research/chatanalyst-provenance/final-report.md +0 -45
  177. data/research/chatanalyst-provenance/resumption.md +0 -37
  178. data/research/coding-philosophy-analysis.md +0 -928
  179. data/research/commands-analysis.md +0 -947
  180. data/research/multi-agent-patterns-analysis.md +0 -853
  181. data/research/prompt-strategies-analysis.md +0 -630
  182. data/research/prov-verbosity-fix-notes.md +0 -77
  183. data/research/provenance-analysis.md +0 -469
  184. data/research/provenance-continuation-accounting.md +0 -255
  185. data/research/synthesis-report.md +0 -487
  186. data/research/tools-system-analysis.md +0 -779
@@ -0,0 +1,314 @@
1
+ # 01 - Chat data model and compilation pipeline
2
+
3
+ > Investigation, not normative documentation. Verified behavior of the chat
4
+ > data model, the `LLM.chat` compilation pipeline, prompt strategies and
5
+ > `.chat` persistence, recorded as subsystem knowledge for maintainers.
6
+ > Normative reference: `doc/developer/ChatLifecycle.md`,
7
+ > `doc/developer/PromptProcessing.md`, `doc/user/WritingChats.md`.
8
+
9
+ ## Scope
10
+
11
+ `lib/scout/llm/chat.rb` and `lib/scout/llm/chat/`:
12
+ `annotation.rb`, `parse.rb`, `process.rb` + `process/{tools,files,clear,options,meta}.rb`,
13
+ `prompt.rb` + `prompt/{shorten_tools,shorten_tools_epoch,shorten_tools_epoch_increment,inbox}.rb`,
14
+ `persist.rb`. `chat/{provenance,tool_calls,agent_meta}.rb` are loaded by
15
+ `chat.rb` but owned by the provenance study (`research/subsys/provenance.md`).
16
+ The utility modules live at `lib/scout/llm/utils.rb` and `lib/scout/llm/tools.rb`
17
+ (siblings of `chat.rb`), not under `chat/`.
18
+
19
+ ## Verified behavior
20
+
21
+ ### Data model
22
+
23
+ `Chat` is a module that does `extend Annotation`, not a class.
24
+ `Chat.setup(array)` annotates the Array's singleton class; the object stays an
25
+ `Array` (`chat.class == Array`), `Chat === chat` holds, and
26
+ `Annotation.is_annotated?(chat)` is true.
27
+
28
+ **The annotation is not carried through Array operations.** `dup`, `+`, `-`,
29
+ `select`, `reject`, `flatten`, `concat` all return plain Arrays. Only the
30
+ `replace`-based DSL methods (`append`, `follow`, `prepend`) and `Chat.setup`
31
+ re-annotate. Every strategy or caller that rebuilds a message list must
32
+ re-`Chat.setup` (the default strategy ends with `Chat.setup(kept_messages)`;
33
+ `LLM.ask` re-annotates its result). This is documented nowhere except an inline
34
+ comment at `prompt/inbox.rb:120-121`.
35
+
36
+ DSL surface (annotation.rb, 270 lines): message constructors `user system
37
+ assistant import import_last file introduce pdf directory continue format tool
38
+ task exec_task inline_task job inline_job association tag option endpoint model
39
+ image message`; conversation ops `ask chat json json_format follow append
40
+ prepend remove_role branch`; reporting `print final purge shed answer
41
+ print_brief`; persistence `save write write_answer`; meta helpers
42
+ `role_messages last_job add_meta meta job_paths`.
43
+
44
+ ### `LLM.chat` - compilation pipeline
45
+
46
+ `LLM.chat(file = [], original = nil)` (`chat.rb:30-62`), exact order:
47
+
48
+ 1. `original` defaults to the chat file if it exists, else `$0`.
49
+ 2. `caller_lib_dir = Path.caller_lib_dir(nil, 'chats')`; if
50
+ `ENV['SCOUT_CHAT_DIR']` is unset and a libdir was found it is set to
51
+ `Path.caller_lib_dir(original)` - the per-project library-store anchor.
52
+ An explicit value is never clobbered (chat.rb:34-42).
53
+ 3. `LLM.messages` -> `Chat.parse` for text, or wraps an Array.
54
+ 4. `Chat.indiferent` -> `Chat.imports` (`import`/`continue`/`last`) ->
55
+ `Chat.clear` -> `Chat.clean(messages, :skip)` -> `Chat.config` (applies
56
+ `config:` roles through `Scout::Config.set`) -> `Chat.tasks`
57
+ (task/inline_task/exec_task) -> `Chat.jobs` (job/inline_job) ->
58
+ `Chat.files` (file/directory/pdf/image/step/allow_path/allow_read_path) ->
59
+ `Chat.setup`.
60
+
61
+ `LLM.options` / `LLM.tools` / `LLM.associations` are *not* in this list: they
62
+ are extracted on the backend path (`backends/default.rb:320-341`, inside
63
+ `tools(messages, options)` and `messages()`).
64
+
65
+ ### Roles
66
+
67
+ Conversational (kept): `user`, `system`, `assistant`, `function_call`,
68
+ `function_call_output`, `image`, `pdf` (resolved to a path, role unchanged),
69
+ `websearch`.
70
+
71
+ Side-channel roles consumed during compilation:
72
+
73
+ - `option`, `sticky_option`, `endpoint`, `model`, `backend`, `agent`,
74
+ `persist`, `format`, `previous_response_id` -> `Chat.options`
75
+ (`process/options.rb:20-71`). Sticky: `endpoint`, `model`, `backend`,
76
+ `agent`, `previous_response_id`; ordinary options are cleared by the next
77
+ `assistant` message; `persist` is neither sticky nor cleared. `format:` may
78
+ load a JSON schema file.
79
+ - `config: <key> <value> <tokens...>` -> `Scout::Config.set` with the trailing
80
+ tokens as scopes.
81
+ - `tool`, `introduce`, `mcp`, `kb`, `association`, `clear_tools`,
82
+ `clear_associations` -> `Chat.tools` / `Chat.associations`
83
+ (`process/tools.rb:136-255`). See the tools study.
84
+ - `import`, `continue`, `last` -> `Chat.imports` (`process/files.rb:38-60`):
85
+ inline the whole chat, only its last non-empty message, or its last purged
86
+ message. File resolution: relative to the chat dir, caller libdir, literal
87
+ path, remote URL, then `Scout.chats`.
88
+ - `file`, `directory` -> `<file name="...">`-tagged user messages / recursive
89
+ per-file expansion. `step` -> loads the job named in chat meta and substitutes
90
+ the step's answer as an assistant message.
91
+ - `allow_path`, `allow_read_path` -> thread-local path whitelists; the message
92
+ is dropped.
93
+ - `clear`, `clear_tools`, `clear_role`/`clean_role` -> `Chat.clear`
94
+ (`process/clear.rb:2-31`): reverse scan stops at the last `clear:`;
95
+ `clear_tools:` drops `function_call*` pairs from that point back;
96
+ `clear_role`/`clean_role` name roles to drop. Ephemeral with respect to the
97
+ saved file.
98
+ - `meta` -> provenance bookkeeping, stripped by `Chat.meta` before inference.
99
+ - `job`, `inline_job`, `task`, `inline_task`, `exec_task` -> `Chat.jobs` /
100
+ `Chat.tasks` (`process/tools.rb:43-135`): produce function_call/output pairs
101
+ (job/task) or inline file content (inline_*); `exec_task` runs synchronously.
102
+ `Chat.jobs` error handling honours `ENV['SCOUT_CHAT_JOB_EXCEPTION']`
103
+ (tools.rb:113-119).
104
+ - `cmd` (`llm/tools.rb:58-71`) converts to a `tool` message with command
105
+ output.
106
+
107
+ `Chat.clean` default dropped roles are `['skip','previous_response_id']`, plus
108
+ empty-content messages. `Chat.purge(chat, role = :previous_response_id)`
109
+ strips only that role; the backend's non-`return_messages` path produces the
110
+ final string as `Chat.clean` + `Chat.purge(...).last['content']`
111
+ (default.rb:610-617).
112
+
113
+ ### Parse / print round-trip
114
+
115
+ `Chat.parse` (parse.rb:10-141):
116
+
117
+ - Header regex `^([a-z0-9_]+):(.*)$` (parse.rb:99). An inline header
118
+ (`user: hello`) makes the message inline and resets the *next* block's role
119
+ to `user` (also for `previous_response_id` and `agent`).
120
+ - **No blank line is required** between header and content. The blank line in
121
+ `doc/user/WritingChats.md` is a convention, not a parser requirement.
122
+ - Escaping: a line matching `^\\([a-z0-9_]+):` is taken literally minus the
123
+ leading backslash; `Chat.print` escapes `^([a-z]+:)(\s)` in content.
124
+ - Protected blocks (headers inside them are not recognized): fenced ` ``` `
125
+ blocks, `[[ ... ]]`, `<tag>...</tag>` XML blocks whose closing tag appears
126
+ somewhere in the text, and the scout `name :-- cmd {{{` / `... }}}`
127
+ command-output markers, rewritten to `<cmd_output cmd="...">`.
128
+ - `option/previous_response_id/function_call/function_call_output/meta` print
129
+ inline (`role: content`); Hash/Array content prints as JSON; empty content
130
+ prints a bare `role:`.
131
+ - `Chat.parse_json` unwraps a ` ```json ` fence then `JSON.parse`.
132
+ - Round-trip invariant `Chat.parse(Chat.print(m))` is covered by
133
+ `test/scout/llm/chat/test_parse.rb` and holds for the conversational and
134
+ control roles.
135
+
136
+ ### Meta messages and token accounting
137
+
138
+ - Canonical short keys `pt ct tt cct cwt rt` with `_s` (session) and `_c`
139
+ (chat-cumulative) variants (meta.rb:14-18). `USAGE_FIELD_MAP` normalizes
140
+ OpenAI Chat/Responses, GLM and Anthropic usage spellings; `normalize_usage`
141
+ recomputes `tt` as `pt+ct` when both are present but `tt` is missing. The
142
+ map is the inclusivity boundary: unknown spellings leave `cct/cwt/rt` nil
143
+ while `pt/ct/tt` still count.
144
+ - `serialize_meta` sorts keys by value length and quotes values containing
145
+ `=`; `parse_meta` reverses it exactly.
146
+ - `update_meta` (default.rb:415-448) stamps `inference_id` (UUID per request),
147
+ `provider_response_id`, per-request token fields, `_s` session cumulatives
148
+ and `_c` chat cumulatives computed as `current_meta[k_c] + tokens[k]` -
149
+ deliberately not the session total.
150
+ - The backend appends a `{role: :meta, ...}` message after each logged
151
+ response, marks `orphan=true` on reasoning-only rounds, and `Chat.project`
152
+ prepends exactly one `meta: job=<short path>` producer marker.
153
+ - `Chat.meta(messages)` strips meta messages (mutating) and returns the last
154
+ meta with the last `_c` checkpoint restored. Lineage/tracing helpers skip
155
+ metas carrying `job`.
156
+
157
+ ### Prompt strategies
158
+
159
+ `Chat.prepare_prompt(prompt, strategies = nil, save_file: nil)`
160
+ (prompt.rb:37-63):
161
+
162
+ - `Proc` strategies short-circuit everything.
163
+ - Default `DEFAULT_CONTEXT_STRATEGY = %w(shorten_tools_epoch_increment inbox)`
164
+ (prompt.rb:9); resolved from `Scout::Config.get(:prompt_strategies, :chat,
165
+ :scout_ai, env: 'PROMPT_STRATEGY', default: ...)` when nil; comma-split
166
+ strings supported. A user-supplied list replaces the default; strategies
167
+ apply in list order.
168
+ - Dispatch: hard-coded `case` for `shorten_tools`, `shorten_tools_epoch`,
169
+ `shorten_tools_epoch_increment`, `inbox` (with `save_file:`), `none`; then
170
+ `REGISTERED_STRATEGIES[strategy]`; then `Chat.send(strategy, prompt)` as
171
+ fallback. `REGISTERED_STRATEGIES = {}` starts empty and nothing in-repo
172
+ populates it.
173
+ - Called inside `Backend::ClassMethods#ask` in the non-relay path, i.e.
174
+ **after** `LLM.ask`'s `Persist` cache, so a cache hit never runs strategies.
175
+ The list is re-threaded through `chain_tools` (default.rb:584-588) so it
176
+ applies on every tool-call round.
177
+ - Thresholds are `Scout::Config.get`-backed and **memoized in class
178
+ variables** - setting the env var after the first read does not change the
179
+ value. Defaults in this checkout:
180
+
181
+ | strategy | constants (shorten_tools_*.rb) |
182
+ |---|---|
183
+ | `shorten_tools` | full_tool_calls 0, full_tool_outputs 10, max_tool_calls 40, max_tool_outputs 40, max_tool_chars 100000 |
184
+ | `shorten_tools_epoch` | epoch_tool_call_threshold 50, epoch_full_tool_calls 20, epoch_compacted_tool_calls 80, epoch_size 20 |
185
+ | `shorten_tools_epoch_increment` | threshold 50, full 20, compacted 80, initial size 20, epochs_per_increase 3, size_increase 10, repeat_increase 10, max_size 60, growth ratio 2.0, max compacted 160 |
186
+
187
+ `shorten_string` builds the `[CONTEXT-COMPACTED ...]` envelope with a preview
188
+ and an optional job pointer; `Log.truncate_string` adds an MD5 fingerprint.
189
+ When compaction actually drops something, `shorten_tools_epoch_increment`
190
+ inserts a `=== Context Management ===` user message after the first kept
191
+ message ("Compacted tool messages: N / Removed tool messages: M").
192
+
193
+ ### `inbox` strategy
194
+
195
+ - Paths derived from `save_file` (`inbox.rb:133-185`): inbox dir, `.inbox_removed`
196
+ dir, and a `.jobs` sibling file for live workload tracking. The stem strips
197
+ only the last extension (`agent.chat` -> `agent`, `a.b.chat` -> `a.b`).
198
+ - Pickup (inbox.rb:64-131): no `save_file` or missing dir is a silent no-op;
199
+ otherwise top-level regular files are listed sorted by name and **moved into
200
+ `.inbox_removed` (created lazily, mtime preserved, numeric suffix on
201
+ collision) before being read**, then appended as `{role:'user', content:}` -
202
+ at-most-once delivery.
203
+ - Reserved `abort` file: consumed once, its content never reaches the model,
204
+ raises the framework-native `Aborted` (StandardError subclass) with the
205
+ stripped content as reason. Files sorted before it were already consumed;
206
+ files sorted after remain.
207
+ - Per-file failures are logged at low severity and skipped; they never break
208
+ the ask path.
209
+ - Provenance globs (`DIRECT_LOG_CHAT_GLOBS` = `['*.chat', '*.society/**/*.chat']`)
210
+ do not match inbox siblings.
211
+
212
+ ### Persistence
213
+
214
+ `chat/persist.rb` (25 lines):
215
+
216
+ - `Persist.save_drivers[:chat]`: an `LLM::Agent` saves the `current_chat -
217
+ start_chat` diff; a `Chat`-annotated array saves `Chat.print`; anything else
218
+ saves `content.to_s`. Writes go through `Open.sensible_write`.
219
+ - `Persist.load_drivers[:chat]` is `LLM.chat(file)` - loading **recompiles**
220
+ (imports/tasks/jobs/files re-run). `Chat.load(file)` (meta.rb:185-189) is
221
+ the parse-only, non-compiling loader used by provenance inspection.
222
+ - `Workflow::TYPE_EXTENSIONS[:chat] = :chat` registers the type extension, so
223
+ a job of type `:chat` produces `.chat` files driven by these procs.
224
+ - Instance `save/write/write_answer` (annotation.rb:222-247) resolve
225
+ non-existent relative paths through `Scout.chats.find` and write
226
+ `LLM.print(self)`.
227
+
228
+ ### LLM facade
229
+
230
+ `LLM.messages/chat/options/print/tools/associations/purge` delegate to the
231
+ `Chat` module functions (chat.rb:64-82); `LLM.ask` wraps chat construction +
232
+ the `Persist` cache + backend dispatch and re-annotates Array results with
233
+ `Chat.setup`.
234
+
235
+ On a query failure the backend writes `<save_file>.error` plus a tmpdir trio
236
+ (`.chat`, `.options`, `.meta`) and attaches it to the exception via
237
+ `e.extend LLM::Backend::BackendException; e.chat tmpfile` (default.rb:506-517,
238
+ 566-579).
239
+
240
+ ## Sharp edges and known issues
241
+
242
+ No code-side bugs were found in this subsystem; all mismatches below are
243
+ documentation staleness.
244
+
245
+ - **Comments do not exist in the chat format** (F12). `doc/user/WritingChats.md`
246
+ documents `#` comment lines; the parser has no comment branch - a `#` line
247
+ becomes a user message, and a `#` line after `user:` merely joins the
248
+ content.
249
+ - **Stale default-strategy snippet** in `doc/developer/PromptProcessing.md`
250
+ (`%w(shorten_tools_epoch_increment)`); the code default includes `inbox`.
251
+ - **Stale `shorten_tools_epoch` config table** in PromptProcessing.md
252
+ (10/40/10); the constants are 20/80/20. Related: Backends.md still cites the
253
+ `shorten_tools` MAX_TOOL_CALLS 40 bound, which is not the default strategy
254
+ (see the backends study, F14).
255
+ - **Compilation pipeline listing incomplete** in ChatLifecycle.md: it omits
256
+ `indiferent`, `imports`, `config`, `tasks`, `jobs`, `files` and places
257
+ options/tools extraction inside `LLM.chat`.
258
+ - **Annotation fragility** (code behavior, undocumented): any Array-derived
259
+ copy of a Chat is a plain Array; only `replace`-based DSL methods preserve
260
+ the annotation. A silent class of bugs for code that does
261
+ `chat.select {...}`.
262
+ - **Protected-block inventory** (fences, `[[ ]]`, XML tags with a closing tag
263
+ present, `{{{ }}}` command markers) is not enumerated in any doc; a
264
+ `<tag>`-looking line without a matching closer is parsed as content with a
265
+ recognized header.
266
+ - `Chat.jobs` honours `ENV['SCOUT_CHAT_JOB_EXCEPTION']`; not mentioned in any
267
+ maintained doc.
268
+ - `Chat.associations` hard-codes the inline KB to
269
+ `Scout.var.Agent.Chat.knowledge_base` (process/tools.rb:237).
270
+
271
+ ## Open questions
272
+
273
+ - Whether `epoch_increment`'s repeat protection ("the most recent instance of
274
+ each repeated (name,arguments) pair is protected from dropping") interacts
275
+ with the epoch-growth accounting exactly as read; only sanity-checked with a
276
+ 120-pair probe, not with repeated identical calls.
277
+ - The interleaving of `shorten_tools`'s character budget with its call budget
278
+ was read but not exercised end-to-end with a real backend. Low risk.
279
+ - The `agent:` role is sticky in `Chat.options` and recognized by the parser;
280
+ its consumer (`LLM.load_agent`) is covered by the agent studies.
281
+
282
+ ## Evidence
283
+
284
+ Provenance: derived from the 2026-09-10/11 Cortex subsystem studies, probed
285
+ against this checkout at HEAD `a992a33` plus the uncommitted 2026-09-11 fix
286
+ sweep (attach/MCP/embed/torch); no fix in this sweep touches this subsystem.
287
+
288
+ Code anchors (line numbers as of that tree):
289
+
290
+ - `lib/scout/llm/chat.rb:14-28` (messages), `:30-62` (pipeline),
291
+ `:64-82` (facade)
292
+ - `lib/scout/llm/chat/annotation.rb:1-270`
293
+ - `lib/scout/llm/chat/parse.rb:2-8,10-141,143-163,165-189`
294
+ - `lib/scout/llm/chat/process.rb:1-21`; `process/clear.rb:2-31,32-42,44-64`;
295
+ `process/options.rb:2-18,20-71`; `process/tools.rb:3-41,43-135,136-229,231-255`;
296
+ `process/files.rb:2-36,38-60,62-109`;
297
+ `process/meta.rb:14-71,73-134,135-175,177-241,243-340,342-379,381-434`
298
+ - `lib/scout/llm/chat/prompt.rb:8-11,15-27,37-63`;
299
+ `prompt/shorten_tools.rb:5-110`; `prompt/shorten_tools_epoch.rb:8-40`;
300
+ `prompt/shorten_tools_epoch_increment.rb:13-132,135-749`;
301
+ `prompt/inbox.rb:18-52,64-131,133-185`
302
+ - `lib/scout/llm/chat/persist.rb:4-25`
303
+ - `lib/scout/llm/backends/default.rb:273-289,300-341,415-448,481-528,540-617`
304
+ - `lib/scout/llm/ask.rb:5-11,12+`; `lib/scout/llm/tools.rb:8-71`
305
+ - Tests: `test/scout/llm/test_chat.rb`,
306
+ `test/scout/llm/chat/{test_parse,test_process,test_prompt,test_tool_calls}.rb`
307
+
308
+ Probe receipts (offline, no repository modifications): annotation
309
+ identity/dup/select behaviour; parse round-trips (comments, blank-line,
310
+ inline headers, protected blocks, escaping); options stickiness;
311
+ clear/clean/purge; meta serialize/parse round-trip and `_c` checkpoint;
312
+ live strategy-config default reads; a 120-pair
313
+ `shorten_tools_epoch_increment` compaction probe; inbox delivery, ordering,
314
+ consume-once, abort-file and removed-dir naming (inside `Dir.mktmpdir`).
@@ -0,0 +1,244 @@
1
+ # 07 - Embeddings, RAG, images and multimodal input
2
+
3
+ > Investigation, not normative documentation. This subsystem is almost
4
+ > entirely undocumented at user level (`doc/user/RunningInference.md` has no
5
+ > embeddings or images sections; `doc/user/Cookbook.md` has no RAG examples);
6
+ > the study below is the main record. Normative fragments:
7
+ > `doc/developer/Backends.md` capability bullets, `doc/user/ToolCalling.md`
8
+ > (knowledge-base tools).
9
+
10
+ ## Scope
11
+
12
+ `lib/scout/llm/embed.rb` (`LLM.embed`), `lib/scout/llm/rag.rb` (`LLM::RAG`),
13
+ `lib/scout/llm/image.rb` (`LLM.image`), the embed/image methods of the
14
+ backends, multimodal message assembly (the `image`/`pdf` chat roles,
15
+ `Chat.find_file`, `format_other`, `encode_image`/`encode_pdf`), the agent
16
+ `attach` tool, and the knowledge-base/RAG seam.
17
+
18
+ ## Verified behavior
19
+
20
+ ### `LLM.embed`
21
+
22
+ - Signature `LLM.embed(text, options = {})` -> Array of Floats; Array text ->
23
+ Array of vectors when the backend batches (Mock and Ollama do; Bedrock does
24
+ not).
25
+ - Resolution: `options[:endpoint]` else
26
+ `Scout::Config.get(:endpoint, :embed, :llm, env: 'EMBED_ENDPOINT,LLM_ENDPOINT',
27
+ default: :embed)`; when an endpoint is set and
28
+ `Scout.etc.AI[endpoint].find_with_extension(:yaml)` exists, that yaml is
29
+ merged into the options. A missing *requested* endpoint (options / env /
30
+ config) raises `"Endpoint not found <name>"`, like ask/image; the
31
+ synthesized `:embed` fallback name never raises but is still merged if an
32
+ `etc/AI/embed.yaml` exists.
33
+ - Backend: `options[:backend]` else
34
+ `Scout::Config.get(:backend, :embed, :llm, env: 'EMBED_BACKEND,LLM_BACKEND',
35
+ default: :embed)`. Dispatch: `:openai` and `:responses` -> `LLM::OpenAI.embed`;
36
+ `:ollama`, `:openwebui`, `:huggingface`, `:relay`; else the
37
+ `LLM::BACKENDS` registry, else `RuntimeError: Unknown backend: <name>`.
38
+ - **No caching** - embed.rb contains no `Persist` call; every call hits the
39
+ backend (contrast `LLM.ask` and `LLM.image`). **No agent branch** either
40
+ (unlike image/ask).
41
+ - Out of the box, with no config at all: endpoint `:embed`, backend `:embed`
42
+ -> registry miss -> `RuntimeError: Unknown backend: embed`. `LLM.embed`
43
+ needs an endpoint yaml, an explicit `backend:`, or a registered backend.
44
+
45
+ Per-backend implementations:
46
+
47
+ | backend | implementation | status |
48
+ |---|---|---|
49
+ | OpenAI (`openai`, `responses`) | `ClassMethods#embed` -> `prepare_client` -> `embed_query`: `parameters[:text] = text; client.embeddings(parameters:)`, returns `response.dig('data',0,'embedding')` | usable; Array text passes through verbatim (provider-dependent) |
50
+ | Ollama | own `embed_query`: `client.request('api/embed', {input: text})`; Array -> all embeddings, String -> first | usable |
51
+ | OpenWebUI | no `embed` of its own; `client` returns a plain Hash, so `ClassMethods#embed` -> `client.embeddings` -> NoMethodError | broken branch |
52
+ | Huggingface | own `embed`: builds a local `CausalModel` with `task: 'Embedding'` and calls `model.eval`/`eval_list` | local PyTorch eval wrapper; the task string is never translated, so whether it yields embeddings depends entirely on the checkpoint |
53
+ | Relay | dispatch branch exists but `LLM::Relay` defines no `embed` | dead branch |
54
+ | Bedrock | `LLM::Bedrock.embed` exists (`invoke_model` on the model id from `:bedrock_embed/:embed/:bedrock` config, env `BEDROCK_EMBED_MODEL_ID`, default `amazon.titan-embed-text-v1`; body `{inputText:}`; single text only) | implemented but **unreachable from dispatch** - only by direct call |
55
+ | Anthropic | `embed_query` raises `'Anthropic does not offer embeddings'`; no dispatch branch | unreachable |
56
+ | Mock (test) | deterministic bag-of-words hash: each word `word.sum % 64` counted, L2-normalized | identical texts -> identical vectors; shared words -> cosine-near |
57
+
58
+ ### `LLM::RAG`
59
+
60
+ - `LLM::RAG.index(vectors)` -> `require 'hnswlib'`; `HierarchicalNSW` with
61
+ `space: 'l2'`, `dim = data.first.length`, `init_index(max_elements:
62
+ data.length)`; `add_point` per vector. No persistence - the index lives in
63
+ memory; `LLM::RAG.load(path, dim)` rehydrates via `load_index`.
64
+ - `LLM::RAG.top(texts, prompt, num = 10, ...)` embeds every text
65
+ (`LLM.embed(text, ...)` - Ruby 3 `...` forwarding, so any embed option
66
+ passes through), indexes, `search_knn`s the embedded prompt and returns
67
+ `texts.values_at(*pos.reverse)`.
68
+ - **Ordering quirk**: `search_knn` returns node ids ascending with distance
69
+ (best match *last*); `pos.reverse` makes `RAG.top` return most-relevant
70
+ first. `scores` are unnormalized L2 distances in far-to-near order.
71
+ - `rag.rb` is the **only** `LLM.embed` consumer inside `lib/` - RAG is the
72
+ framework's only embedding consumer.
73
+
74
+ ### `LLM.image`
75
+
76
+ - Signature `LLM.image(question, options = {}, &block)`; `messages =
77
+ LLM.chat(question)`; options = `LLM.options(messages)` + the given options.
78
+ - Endpoint resolution mirrors ask: `find_with_extension(:yaml)` merge plus
79
+ `"Endpoint not found <name>"` for a non-empty unknown endpoint (env chain
80
+ `IMAGE_ENDPOINT,ASK_ENDPOINT,LLM_ENDPOINT,ENDPOINT,LLM,ASK,IMAGE`).
81
+ - **Agent branch**: `options[:agent]` (none/false/nil disabled) ->
82
+ `LLM::Agent.load_agent(agent).follow(messages).ask(options)`.
83
+ - Backend default `:responses` (env `ASK_BACKEND,LLM_BACKEND`). Dispatch:
84
+ `:openai, :anthropic, :responses, :ollama, :vllm, :openwebui, :huggingface,
85
+ :relay, :bedrock` -> `<Mod>.image(...)`; **no `:glm` branch**. The registry
86
+ fallback calls `<mod>.ask(messages, options)` - plain ask, no
87
+ image_generation tool, for plugin backends.
88
+ - **Caching**: the dispatch is wrapped in `Persist.persist(endpoint, :json,
89
+ prefix: "LLM image", other: options.merge(messages:), persist:,
90
+ dir: Scout.var.cache.ask)` with `persist` defaulting to true; the key is
91
+ endpoint + all options + the full messages, so any option change
92
+ recomputes. A cache hit skips backend selection entirely.
93
+ - Return: `Chat.setup res if Array === res`.
94
+
95
+ Backend side: `ClassMethods#image` (default.rb:619-628) is inherited by every
96
+ ClassMethods-including backend - `ask(question, options.merge(tools:
97
+ [{type: 'image_generation'}], return_messages: true))` then
98
+ `messages.select{|i| i[:role]=='image'}.first['content']['result']`. The
99
+ `image_generation` "tool" is a type-only provider tool (Responses API), no
100
+ function name or parameters; the output item type `'image_generation_call'`
101
+ maps to `{role: 'image', content: output}` and `image()` digs out the base64
102
+ `result`. Provider reachability: modules with an inherited `image` are
103
+ OpenAI, Anthropic, Responses, OLlama, VLLM, OpenWebUI, Huggingface and GLM
104
+ (none overrides it); **Bedrock and Relay define no `image` at all**, yet
105
+ image.rb routes `:bedrock`/`:relay` to `Mod.image`.
106
+
107
+ Convenience: `Chat#create_image(file, ...)` =
108
+ `base64 = LLM.image(LLM.chat(self), ...); Open.write(file,
109
+ Base64.decode64(base64), mode: 'wb')` - the whole chat is the image prompt.
110
+ `Agent#create_image` merges `@other_options` and forwards.
111
+
112
+ ### Vision input (multimodal message assembly)
113
+
114
+ 1. `chat.image(path)` / `chat.pdf(path)` append `{role: 'image'|'pdf',
115
+ content: <path>}` to the current chat (`Agent` forwards through
116
+ `method_missing` to `current_chat`).
117
+ 2. Path resolution happens in `Chat.files`, the last step of `Chat.process`,
118
+ via `Chat.find_file(file, original, caller_lib_dir)`: relative to the
119
+ original chat file, then the caller libdir join, then a cwd file, then
120
+ remote passthrough (http/https kept verbatim), then the `Scout.chats`
121
+ pathmap. The content becomes an absolute path; the role is unchanged. A
122
+ missing file raises `"File not found: <name>"`.
123
+ 3. Encoding happens at format time, not annotation time. `format_other`
124
+ (default.rb:180+) cases on the role string:
125
+ - `'image'`: `Chat.find_file` again (idempotent); a remote URL becomes a
126
+ provider URL block, otherwise `encode_image(path)` -> data URI; raises
127
+ `"Image does not exist in <path>"` when missing.
128
+ - `'pdf'`: `encode_pdf` -> `data:application/pdf;base64,...` ->
129
+ `input_file`/`file_data` block.
130
+ - `encode_image` (default.rb:155-171): base64 `strict_encode64`; MIME by
131
+ extension - `jpg|jpeg` -> `image/jpeg`, `png` -> `image/png`,
132
+ **everything else -> the literal string `"image/extension"`**.
133
+ 4. Per-provider shape: only `glm.rb` overrides `format_other` - image ->
134
+ `{type: :image_url, image_url: {url: <path-or-dataURI>}}` (bare hash for
135
+ remote, array-wrapped for local). Every other backend (openai, anthropic,
136
+ responses, ollama, vllm, openwebui, huggingface) inherits the default
137
+ Responses-style `{type: :input_image, image_url: <data-uri-or-url>}`.
138
+ 5. One image message -> exactly one provider content block; images ride as
139
+ `user`-role content arrays.
140
+
141
+ ### Knowledge base / RAG seam
142
+
143
+ - **No embeddings in the KB path at all.** `LLM.knowledge_base_tool_definition`
144
+ builds per database a `children`/`parents` traversal tool (params
145
+ `entities` (+ `reverse` for directed DBs), output `source~target`) and,
146
+ when the index has fields, a `<db>_association_details` tool (params
147
+ `associations` (+ `fields`); `fields` is dropped when the database has
148
+ exactly one field). Execution is pure TSV index lookup.
149
+ - Chat wiring: the `association:` role registers a TSV inline via
150
+ `kb.register`; the `kb:` role points at an existing KB by name;
151
+ `Chat.associations` consumes both. Driving the `association` role
152
+ end-to-end with a minimal flat TSV raises inside **scout-gear**
153
+ (`Association#index` -> `undefined method 'include?' for nil`) - the role
154
+ is a thin registration; indexing semantics and TSV-shape requirements live
155
+ in scout-gear's KnowledgeBase.
156
+ - `LLM.knowledge_base_ask(kb, question, options)` wires a tools block that
157
+ answers only the `children` lookup, not the details tool.
158
+ - **The two "RAG" meanings are disjoint**: `LLM::RAG` (hnswlib over
159
+ `LLM.embed` vectors) never touches KnowledgeBase; KB tools never touch
160
+ embeddings.
161
+
162
+ ## Sharp edges and known issues
163
+
164
+ - **Dead/broken embed and image branches** (F11, open): embed `:relay` ->
165
+ NoMethodError; embed `:openwebui` -> NoMethodError (Hash client); image
166
+ `:relay` and `:bedrock` -> NoMethodError (`Mod.image` does not exist);
167
+ `:glm` missing from the image dispatch although `LLM::GLM.image` works when
168
+ called directly; bedrock embed implemented but unreachable from
169
+ `LLM.embed`.
170
+ - **`encode_image` MIME table maps only jpg/jpeg/png** (F18, open): any other
171
+ extension yields the literal `data:image/extension;base64,...` - webp, gif
172
+ and tiff are silently malformed.
173
+ - **Anthropic image support does not exist** (F18, open): despite
174
+ `doc/developer/Backends.md` describing base64 `image` content blocks with
175
+ media type, `LLM::Anthropic` defines no image handling and inherits the
176
+ default `input_image` shape; only GLM uses a true nested `image_url`.
177
+ - **ToolCalling.md's details-tool parameter is wrong** (doc bug, open): the
178
+ parameter is `associations` (optionally `fields`), never `entities`.
179
+ - **No user-level documentation** of embeddings, images, vision or RAG
180
+ anywhere in `doc/user/` (RunningInference.md has no sections; Cookbook.md
181
+ has no examples).
182
+ - **Fixed 2026-09-11, uncommitted:** F1 - the `attach` tool never attached
183
+ PDFs (normalization overwrote an explicit `file_type: 'pdf'` to `'image'`
184
+ and the dispatcher's bare `case` matched the first branch unconditionally,
185
+ so `when 'pdf'` was unreachable; every attach routed to `self.image(path)`).
186
+ Now only `auto` is normalized (pdf by `.pdf` extension, else `image`), the
187
+ dispatcher is `case file_type`, and an unknown type raises. Regression
188
+ tests in `test/scout/llm/agent/test_attach.rb` (8/0). The `ATACH_TYPES`
189
+ typo and the schema/code default divergence it exposed (schema
190
+ `default: 'auto'`, code default now `'auto'`) were reconciled in the same
191
+ fix; the constant name typo remains.
192
+ - **Fixed 2026-09-11, uncommitted:** F5 - `LLM.embed` never merged endpoint
193
+ YAML (extensionless `Scout.etc.AI[endpoint].exists?` instead of
194
+ `find_with_extension(:yaml).exists?`), and a missing endpoint failed
195
+ silently instead of raising like ask/image. Now the yaml merge and the
196
+ requested-endpoint raise match the ask/image contract (see
197
+ `lib/scout/llm/embed.rb`'s comment). Regression tests in
198
+ `test/scout/llm/test_embed.rb` (6/0). A behaviour change to note: an
199
+ explicitly requested endpoint with no yaml now raises instead of silently
200
+ using the config defaults.
201
+ - `test_rag.rb#_test_rag` is underscore-disabled; only `test_rag_insitu`
202
+ runs.
203
+
204
+ ## Open questions
205
+
206
+ - Does `CausalModel` with `task: 'Embedding'` return usable vectors for a
207
+ real checkpoint? (Not probed - no downloads.)
208
+ - Are the unreachable-but-implemented paths (bedrock embed, glm image)
209
+ deliberate omissions from the dispatch or oversights?
210
+ - Should `LLM.embed` cache? Embeddings are the classic cache-friendly
211
+ workload (deterministic per text+model); `ask`/`image` both cache.
212
+ - Whether any provider rejects the `input_image` default shape on
213
+ Chat-Completions-only deployments - untestable offline.
214
+
215
+ ## Evidence
216
+
217
+ Provenance: derived from the 2026-09-10/11 Cortex subsystem studies, probed
218
+ against this checkout at HEAD `a992a33` plus the uncommitted 2026-09-11 fix
219
+ sweep. The attach fix (F1) and the embed endpoint-YAML fix (F5) in that sweep
220
+ are in scope here and are described as current behavior above.
221
+
222
+ - Code: `lib/scout/llm/embed.rb` (54 lines, current fixed form with the
223
+ ScoutCoder comment documenting the F5 fix); `lib/scout/llm/rag.rb` (33
224
+ lines); `lib/scout/llm/image.rb`; `lib/scout/llm/agent/attach.rb` (current
225
+ fixed form with the ScoutCoder comment documenting the F1 fix);
226
+ `lib/scout/llm/backends/default.rb:155-178` (`encode_image`/`encode_pdf`),
227
+ `:180-214` (`format_other`), `:398-400` (image output mapping),
228
+ `:619-637` (`image`, `embed_query`, `embed`); `backends/{ollama,openwebui,
229
+ huggingface,bedrock,anthropic,glm}.rb`; `lib/scout/llm/chat/annotation.rb:250-253`
230
+ (`create_image`); `lib/scout/llm/chat/process/files.rb:17-36,83-89`;
231
+ `lib/scout/llm/tools/knowledge_base.rb`; `lib/scout/llm/ask.rb:132-140`.
232
+ - Tests: `test/scout/llm/test_embed.rb` (6/0 after the F5 fix),
233
+ `test/scout/llm/test_rag.rb` (one test disabled),
234
+ `test/scout/llm/agent/test_attach.rb` (8/0 after the F1 fix).
235
+ - Probe receipts: ~57 offline probes under `tmp/probe_embed_image/` covering
236
+ the embed API surface and default failure mode, no-Persist, RAG
237
+ index/load/top and the ordering quirk, per-backend embed implementations
238
+ and dead branches, the huggingface local-eval path, `LLM.image` dispatch
239
+ and provider reachability, the `image_generation` tool shape and response
240
+ mapping, image caching key inputs, annotation -> files -> absolute-path
241
+ resolution and the `find_file` order, per-provider content-block shapes
242
+ and `format_other` ownership, the MIME table bug, the attach dispatch bug
243
+ and its re-confirmation, config/endpoint-yaml precedence and the
244
+ asymmetry, and the KB tool parameter shapes.