scout-ai 1.2.5 → 2.0.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 (164) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +111 -31
  3. data/README.md +171 -320
  4. data/Rakefile +17 -1
  5. data/VERSION +1 -1
  6. data/doc/Improvements.md +325 -0
  7. data/doc/StartHere.md +110 -0
  8. data/doc/developer/Architecture.md +126 -0
  9. data/doc/developer/Backends.md +199 -0
  10. data/doc/developer/ChatLifecycle.md +183 -0
  11. data/doc/developer/DelegationInternals.md +295 -0
  12. data/doc/developer/DesignPrinciples.md +245 -0
  13. data/doc/developer/PromptProcessing.md +292 -0
  14. data/doc/developer/Provenance.md +317 -0
  15. data/doc/user/BuildingAgents.md +345 -0
  16. data/doc/user/Cookbook.md +333 -0
  17. data/doc/user/CoreConcepts.md +181 -0
  18. data/doc/user/Delegation.md +191 -0
  19. data/doc/user/GettingStarted.md +159 -0
  20. data/doc/user/ManagingContext.md +163 -0
  21. data/doc/user/MultiAgentWorkflows.md +256 -0
  22. data/doc/user/Python.md +159 -0
  23. data/doc/user/RunningInference.md +200 -0
  24. data/doc/user/ToolCalling.md +193 -0
  25. data/doc/user/WritingChats.md +197 -0
  26. data/lib/scout/llm/agent/chat.rb +62 -12
  27. data/lib/scout/llm/agent/delegate.rb +274 -65
  28. data/lib/scout/llm/agent/iterate.rb +2 -2
  29. data/lib/scout/llm/agent/save.rb +273 -0
  30. data/lib/scout/llm/agent/workflow.rb +164 -0
  31. data/lib/scout/llm/agent.rb +86 -61
  32. data/lib/scout/llm/ask.rb +36 -6
  33. data/lib/scout/llm/backends/anthropic.rb +9 -1
  34. data/lib/scout/llm/backends/bedrock.rb +15 -3
  35. data/lib/scout/llm/backends/default.rb +129 -89
  36. data/lib/scout/llm/backends/glm.rb +58 -0
  37. data/lib/scout/llm/backends/huggingface.rb +13 -1
  38. data/lib/scout/llm/backends/ollama.rb +13 -0
  39. data/lib/scout/llm/backends/openwebui.rb +8 -3
  40. data/lib/scout/llm/chat/agent_meta.rb +264 -0
  41. data/lib/scout/llm/chat/annotation.rb +37 -14
  42. data/lib/scout/llm/chat/parse.rb +28 -6
  43. data/lib/scout/llm/chat/persist.rb +25 -0
  44. data/lib/scout/llm/chat/process/clear.rb +19 -1
  45. data/lib/scout/llm/chat/process/files.rb +16 -1
  46. data/lib/scout/llm/chat/process/meta.rb +422 -32
  47. data/lib/scout/llm/chat/process/options.rb +21 -1
  48. data/lib/scout/llm/chat/process/tools.rb +49 -12
  49. data/lib/scout/llm/chat/process.rb +4 -0
  50. data/lib/scout/llm/chat/prompt/shorten_tools.rb +125 -0
  51. data/lib/scout/llm/chat/prompt/shorten_tools_epoch.rb +365 -0
  52. data/lib/scout/llm/chat/prompt.rb +48 -0
  53. data/lib/scout/llm/chat/provenance.rb +775 -0
  54. data/lib/scout/llm/chat/tool_calls.rb +76 -0
  55. data/lib/scout/llm/chat.rb +18 -2
  56. data/lib/scout/llm/embed.rb +8 -3
  57. data/lib/scout/llm/image.rb +86 -0
  58. data/lib/scout/llm/rag.rb +3 -3
  59. data/lib/scout/llm/tools/call.rb +159 -10
  60. data/lib/scout/llm/tools/knowledge_base.rb +1 -1
  61. data/lib/scout/llm/tools/workflow.rb +13 -5
  62. data/lib/scout-ai.rb +1 -0
  63. data/research/ChatAnalyst-required-changes.md +167 -0
  64. data/research/agent-delegation-analysis.md +810 -0
  65. data/research/agent-meta-provenance-integration-plan.md +622 -0
  66. data/research/agent-workflow-analysis.md +1120 -0
  67. data/research/backends-analysis.md +836 -0
  68. data/research/chat-core-analysis.md +946 -0
  69. data/research/chatanalyst-provenance/00-baseline.md +30 -0
  70. data/research/chatanalyst-provenance/01-repo-map.md +60 -0
  71. data/research/chatanalyst-provenance/02-event-reconstruction.md +55 -0
  72. data/research/chatanalyst-provenance/03-duplication-evidence.md +45 -0
  73. data/research/chatanalyst-provenance/04-tooling-root-cause.md +57 -0
  74. data/research/chatanalyst-provenance/05-fix-plan.md +46 -0
  75. data/research/chatanalyst-provenance/07-critic-review.md +25 -0
  76. data/research/chatanalyst-provenance/final-report.md +45 -0
  77. data/research/chatanalyst-provenance/resumption.md +37 -0
  78. data/research/coding-philosophy-analysis.md +928 -0
  79. data/research/commands-analysis.md +947 -0
  80. data/research/multi-agent-patterns-analysis.md +853 -0
  81. data/research/prompt-strategies-analysis.md +630 -0
  82. data/research/prov-verbosity-fix-notes.md +77 -0
  83. data/research/provenance-analysis.md +469 -0
  84. data/research/provenance-navigation-design.md +640 -0
  85. data/research/synthesis-report.md +487 -0
  86. data/research/tools-system-analysis.md +779 -0
  87. data/scout-ai.gemspec +97 -13
  88. data/scout_commands/agent/ask +13 -3
  89. data/scout_commands/agent/kb +2 -0
  90. data/scout_commands/llm/ask +11 -4
  91. data/scout_commands/llm/md +76 -0
  92. data/scout_commands/llm/prov +602 -0
  93. data/scout_commands/llm/word +71 -0
  94. data/share/word/reference.docx +0 -0
  95. data/test/etc/AI/mock.yaml +11 -0
  96. data/test/fixtures/backends/anthropic.json +19 -0
  97. data/test/fixtures/backends/anthropic_tool_use.json +24 -0
  98. data/test/fixtures/backends/bedrock.json +8 -0
  99. data/test/fixtures/backends/bedrock_embedding.json +3 -0
  100. data/test/fixtures/backends/bedrock_tool_use.json +17 -0
  101. data/test/fixtures/backends/ollama.json +16 -0
  102. data/test/fixtures/backends/ollama_tool_call.json +27 -0
  103. data/test/fixtures/backends/openai_chat.json +21 -0
  104. data/test/fixtures/backends/openai_chat_tool_call.json +31 -0
  105. data/test/fixtures/backends/responses.json +33 -0
  106. data/test/fixtures/backends/responses_tool_call.json +28 -0
  107. data/test/integration/README.md +32 -0
  108. data/test/integration/scout/llm/backends/test_endpoints.rb +34 -0
  109. data/test/integration/scout/llm/backends/test_openwebui.rb +61 -0
  110. data/test/integration/scout/llm/backends/test_relay.rb +52 -0
  111. data/test/integration/scout/llm/test_infrastructure.rb +74 -0
  112. data/test/{scout → integration/scout}/llm/test_mcp.rb +1 -1
  113. data/test/integration/scout/llm/tools/test_mcp.rb +42 -0
  114. data/test/integration/scout/model/test_base.rb +91 -0
  115. data/test/scout/llm/agent/test_chat.rb +8 -2
  116. data/test/scout/llm/agent/test_save.rb +413 -0
  117. data/test/scout/llm/agent/test_workflow.rb +110 -0
  118. data/test/scout/llm/backends/test_anthropic.rb +93 -10
  119. data/test/scout/llm/backends/test_bedrock.rb +118 -2
  120. data/test/scout/llm/backends/test_ollama.rb +70 -20
  121. data/test/scout/llm/backends/test_openwebui.rb +42 -40
  122. data/test/scout/llm/backends/test_relay.rb +4 -2
  123. data/test/scout/llm/chat/agent_meta_fixtures.rb +131 -0
  124. data/test/scout/llm/chat/process/test_meta.rb +518 -0
  125. data/test/scout/llm/chat/process/test_normalize_usage.rb +183 -0
  126. data/test/scout/llm/chat/test_agent_meta.rb +357 -0
  127. data/test/scout/llm/chat/test_agent_meta_provenance.rb +467 -0
  128. data/test/scout/llm/chat/test_agent_meta_tokens.rb +594 -0
  129. data/test/scout/llm/chat/test_parse.rb +70 -15
  130. data/test/scout/llm/chat/test_prov_cli.rb +274 -0
  131. data/test/scout/llm/chat/test_provenance.rb +240 -0
  132. data/test/scout/llm/chat/test_tool_calls.rb +38 -0
  133. data/test/scout/llm/test_agent.rb +13 -36
  134. data/test/scout/llm/test_ask.rb +75 -52
  135. data/test/scout/llm/test_chat.rb +107 -13
  136. data/test/scout/llm/test_embed.rb +48 -0
  137. data/test/scout/llm/test_rag.rb +23 -16
  138. data/test/scout/llm/test_tools.rb +12 -1
  139. data/test/scout/llm/tools/test_knowledge_base.rb +0 -1
  140. data/test/scout/llm/tools/test_mcp.rb +5 -3
  141. data/test/scout/llm/tools/test_workflow.rb +23 -2
  142. data/test/scout/model/python/huggingface/causal/test_next_token.rb +11 -5
  143. data/test/scout/model/python/huggingface/test_causal.rb +9 -3
  144. data/test/scout/model/python/huggingface/test_classification.rb +11 -2
  145. data/test/scout/model/python/test_torch.rb +2 -0
  146. data/test/scout/model/python/torch/test_helpers.rb +4 -0
  147. data/test/scout/model/test_base.rb +4 -2
  148. data/test/support/availability.rb +231 -0
  149. data/test/support/fake_clients.rb +138 -0
  150. data/test/support/fixtures.rb +21 -0
  151. data/test/support/infrastructure_probes.rb +136 -0
  152. data/test/support/mock_backend.rb +215 -0
  153. data/test/test_helper.rb +32 -2
  154. metadata +96 -12
  155. data/doc/Agent.md +0 -354
  156. data/doc/Chat.md +0 -481
  157. data/doc/LLM.md +0 -356
  158. data/doc/PythonAgentTasks.md +0 -333
  159. data/doc/RAG.md +0 -129
  160. data/doc/USER_GUIDE.md +0 -572
  161. data/scout_commands/documenter +0 -148
  162. data/test/scout/llm/backends/test_openai.rb +0 -192
  163. data/test/scout/llm/backends/test_responses.rb +0 -238
  164. data/test/scout/llm/test_parse.rb +0 -98
@@ -0,0 +1,487 @@
1
+ > **Disclaimer:** This is an architectural investigation, not normative
2
+ > documentation. It was produced during a documentation-revamp effort and may
3
+ > be outdated relative to the current codebase. Treat it as supporting
4
+ > reference material. For maintained documentation, see
5
+ > [../../doc/](../../doc/).
6
+ >
7
+
8
+
9
+ # Synthesis Report: Scout-AI Documentation Revamp
10
+
11
+ **Purpose:** Identify consistency issues, gaps, overlaps, and produce a concrete
12
+ mapping from the 10 research artifacts (SHARED/01–10) to the new documentation
13
+ structure. Also flag information from existing docs that must be preserved.
14
+
15
+ ---
16
+
17
+ ## 1. Consistency Issues Between Artifacts
18
+
19
+ ### 1.1 SOCIAL_INHERIT_MODES — Terminology Consistent ✅
20
+
21
+ All artifacts that mention social inheritance (03, 04, 08, search_brief) agree on
22
+ **3 modes**: `none`, `tools` (default), `conversation`. The earlier concern about
23
+ "4 modes" was resolved during research and is consistently reported as 3. No
24
+ contradiction.
25
+
26
+ **Action for docs:** State clearly there are exactly 3 modes. Note the legacy
27
+ `chat` parameter compatibility shim (`current` → `conversation: current, inherit:
28
+ conversation`; bare `none` → no conversation).
29
+
30
+ ### 1.2 Tool-Call Pruning Thresholds — Terminology Drift ⚠️
31
+
32
+ | Artifact | Term used | Value |
33
+ |----------|-----------|-------|
34
+ | 02 (Prompt Strategies) | `full_tool_calls` (keep fully) | default 0 |
35
+ | 02 (Prompt Strategies) | `max_tool_calls` (remove entirely) | default 40 |
36
+ | search_brief | "pruned after 10, removed after 40" | 10 / 40 |
37
+ | 04 (AgentWorkflow) | "pruned after 10, removed after 40" | 10 / 40 |
38
+ | 05 (Backends) | references `prepare_prompt` and `shorten_tools` | — |
39
+
40
+ **Issue:** The search_brief and artifact 04 state "pruned after **10**", but
41
+ artifact 02 (which is the authoritative source for `prompt.rb`) lists
42
+ `full_tool_calls = 0` and `max_tool_calls = 40`. The "10" appears to come from
43
+ `full_tool_outputs` (default 10), which is about tool **outputs**, not tool
44
+ **calls**. The artifacts conflate two separate thresholds:
45
+
46
+ - `full_tool_calls` (0): number of recent tool *call* messages kept fully
47
+ - `full_tool_outputs` (10): number of recent tool *output* messages kept fully
48
+ - `max_tool_calls` (40): hard limit on tool *call* messages before removal
49
+ - `max_tool_outputs` (40): hard limit on tool *output* messages before removal
50
+
51
+ **Action for docs:** `PromptStrategies.md` must clearly distinguish tool calls
52
+ from tool outputs and list all four thresholds with their defaults. Do not
53
+ repeat the "pruned after 10" shorthand without qualification.
54
+
55
+ ### 1.3 `prepare_prompt` Integration Point — Consistent ✅
56
+
57
+ Artifacts 02, 04, and 05 all agree that `Chat.prepare_prompt` is called inside
58
+ `Backend::Default#ask`, just before the actual API call. The prompt strategies
59
+ are ephemeral (not persisted to chat files). No contradiction.
60
+
61
+ ### 1.4 Backend List — Minor Discrepancy
62
+
63
+ | Source | Backends listed |
64
+ |--------|----------------|
65
+ | search_brief | openai, anthropic, bedrock, huggingface, ollama, openwebui, relay, responses, vllm |
66
+ | doc/LLM.md | responses, openai, anthropic, ollama, vllm, openwebui, bedrock, relay |
67
+ | Artifact 05 | (detailed per-provider analysis) |
68
+
69
+ **Issue:** `huggingface` appears in the search_brief/codebase listing but is NOT
70
+ mentioned in the existing `doc/LLM.md`. Artifact 05 covers all providers in
71
+ detail. The `responses` backend is described as "default" in LLM.md but this
72
+ should be verified against artifact 05.
73
+
74
+ **Action for docs:** `Backends.md` should have a complete provider table sourced
75
+ from artifact 05, including `huggingface`. Mark which are fully featured vs.
76
+ thin wrappers.
77
+
78
+ ### 1.5 `info` vs `prov` Command Status — Consistent ✅
79
+
80
+ Artifacts 07 and 10 both independently confirm that `scout-ai llm info` is the
81
+ current, recommended provenance command, and `scout-ai llm prov` is superseded
82
+ (uses monkey-patches, has hardcoded fallback path). No contradiction.
83
+
84
+ ### 1.6 ChatAnalyst Location — Ambiguity
85
+
86
+ Artifact 07 documents ChatAnalyst as part of the SC26 workflow
87
+ (`~/git/workflows/SC26/Agent/ChatAnalyst/`), not in the core library. Artifact
88
+ 08 also references it. The search_brief flags this as an uncertainty.
89
+
90
+ **Action for docs:** `Provenance.md` should document ChatAnalyst as an
91
+ SC26-specific agent, not a core library feature. Note that it may be promoted to
92
+ core in the future.
93
+
94
+ ### 1.7 Tool Definition Format — Consistent ✅
95
+
96
+ Artifacts 05 and 06 agree: tools are represented as `{name => [handler,
97
+ definition]}` hashes. Handler can be a Workflow, KnowledgeBase, or Proc.
98
+ Definition is an OpenAI-style function schema. No contradiction.
99
+
100
+ ### 1.8 Agent `ask` vs `chat` Method Semantics — Consistent ✅
101
+
102
+ Artifacts 03 and 04 agree:
103
+ - `ask(messages, options)` → low-level, returns string (or message trace with
104
+ `return_messages: true`)
105
+ - `chat(options)` → high-level, calls `ask(current_chat, return_messages: true)`,
106
+ appends messages to `current_chat`, returns assistant content
107
+
108
+ No contradiction. This matches the existing `doc/Agent.md`.
109
+
110
+ ---
111
+
112
+ ## 2. Gaps Identified
113
+
114
+ ### 2.1 Installation and Setup (HIGH priority gap)
115
+
116
+ **Gap:** None of the 10 artifacts cover installation, Gemfile setup, or initial
117
+ endpoint configuration. This content exists only in `doc/USER_GUIDE.md` and
118
+ `doc/LLM.md`.
119
+
120
+ **Action:** `README.md` and/or `Overview.md` must include a "Getting Started"
121
+ section with Gemfile, bundle install, and first endpoint creation. Source from
122
+ existing `USER_GUIDE.md` §2 and `LLM.md` §1.
123
+
124
+ ### 2.2 Python Integration (MEDIUM priority gap)
125
+
126
+ **Gap:** Python-backed agent tasks (auto-loading `python/*.py` files) and the
127
+ Python SDK (`../python/README.md`) are NOT covered in any artifact. This content
128
+ exists only in `doc/PythonAgentTasks.md`.
129
+
130
+ **Action:** Add a section to `Agent.md` or a dedicated `Python.md` doc. Source
131
+ from existing `PythonAgentTasks.md`. The proposed structure does not include a
132
+ Python doc — recommend adding one or folding into `Agent/Agent.md`.
133
+
134
+ ### 2.3 Model Subsystem (LOW priority gap)
135
+
136
+ **Gap:** The `ScoutModel` / `PythonModel` / `TorchModel` / `HuggingfaceModel`
137
+ subsystem (documented in `doc/Model.md`) is NOT covered in any artifact. This is
138
+ a separate concern from LLM backends — it's about wrapping ML models for
139
+ evaluation/training.
140
+
141
+ **Action:** This is tangential to the agent/LLM documentation revamp. Recommend
142
+ keeping `Model.md` as-is or moving to a separate `doc/Model/` area. Do NOT merge
143
+ into the new structure unless explicitly requested.
144
+
145
+ ### 2.4 Endpoint Configuration Details (HIGH priority gap)
146
+
147
+ **Gap:** Detailed endpoint YAML configuration (keys, examples for different
148
+ backends, `~/.scout/etc/AI/<name>` format, config defaults via
149
+ `~/.scout/etc/config`) is NOT fully covered in any artifact. Artifact 05 covers
150
+ backend internals but not the user-facing endpoint setup.
151
+
152
+ **Action:** `Backends/Backends.md` or a dedicated section in `Overview.md` must
153
+ include endpoint configuration. Source from existing `LLM.md` §1 and §4.
154
+
155
+ ### 2.5 Caching / Persistence Behavior (MEDIUM priority gap)
156
+
157
+ **Gap:** `LLM.ask` caching behavior (`persist: true` by default, cache key
158
+ composition, `persist: false` to disable) is mentioned in existing `LLM.md` §2.3
159
+ but NOT in any artifact.
160
+
161
+ **Action:** Include in `Backends/Backends.md` or `Chat/Persistence.md`.
162
+
163
+ ### 2.6 `LLM.workflow_ask` and `LLM.knowledge_base_ask` Helpers (LOW priority gap)
164
+
165
+ **Gap:** Convenience helpers documented in existing `LLM.md` §6 are not in any
166
+ artifact.
167
+
168
+ **Action:** Include in `Tools/WorkflowTools.md` and `Tools/KnowledgeBase.md`.
169
+
170
+ ### 2.7 `previous_response_id` Session Continuation (LOW priority gap)
171
+
172
+ **Gap:** Responses backend session continuation behavior is in existing `LLM.md`
173
+ §4.2 but not in any artifact.
174
+
175
+ **Action:** Include in `Backends/Backends.md`.
176
+
177
+ ### 2.8 Agent Error Handling (`process_exception`) (LOW priority gap)
178
+
179
+ **Gap:** The `agent.process_exception` Proc for retry-on-exception is in existing
180
+ `Agent.md` §11 but not deeply covered in any artifact.
181
+
182
+ **Action:** Include in `Agent/Agent.md`.
183
+
184
+ ### 2.9 Agent Structured Output Methods (LOW priority gap)
185
+
186
+ **Gap:** `agent.json`, `agent.json_format(schema)`, `agent.iterate`,
187
+ `agent.iterate_dictionary` are documented in existing `Agent.md` §6–7 but not
188
+ deeply covered in any artifact (artifact 03 mentions `iterate` but not
189
+ `json_format`).
190
+
191
+ **Action:** Include in `Agent/Agent.md`.
192
+
193
+ ### 2.10 Chat Server / Web UI (LOW priority gap)
194
+
195
+ **Gap:** The `scout-ai llm server` Sinatra web UI is documented in artifact 10
196
+ but not in any other artifact. It is a user-facing feature.
197
+
198
+ **Action:** Include in `Commands/Commands.md`.
199
+
200
+ ### 2.11 Inline Question Processing (`# ask:` comments) (LOW priority gap)
201
+
202
+ **Gap:** The `--inline` mode for `scout-ai llm ask` (processing `# ask:`
203
+ comments in source files) is documented in artifact 10 but could use a
204
+ standalone example.
205
+
206
+ **Action:** Include in `Commands/Commands.md`.
207
+
208
+ ---
209
+
210
+ ## 3. Overlaps to Consolidate
211
+
212
+ ### 3.1 Chat Processing Pipeline (Artifacts 01, 02, 06)
213
+
214
+ The chat processing pipeline (meta → tools → files → options → clear) is
215
+ described from different angles in:
216
+ - **01 (Chat Core):** Full processing pipeline order, role families
217
+ - **02 (Prompt Strategies):** The `prepare_prompt` step (pre-inference)
218
+ - **06 (Tools System):** Tool extraction from chat (`Chat.associations`)
219
+
220
+ **Consolidation:** `Chat/Chat.md` should own the processing pipeline narrative.
221
+ `PromptStrategies.md` should focus only on the `prepare_prompt` step and
222
+ reference `Chat.md` for the overall pipeline. `Tools/Tools.md` should reference
223
+ `Chat.md` for how tools are declared in chat files.
224
+
225
+ ### 3.2 Tool Calling Loop (Artifacts 05, 06)
226
+
227
+ The `chain_tools` recursive loop is described in:
228
+ - **05 (Backends):** `Backend::Default#chain_tools` — the inference-side loop
229
+ - **06 (Tools System):** `LLM.process_calls` — the execution pipeline
230
+
231
+ **Consolidation:** `Tools/Tools.md` should own the tool-calling protocol
232
+ description (definition → model calls → execution → re-ask).
233
+ `Backends/Backends.md` should reference `Tools.md` rather than duplicating the
234
+ loop mechanics. The boundary: Backends.md owns "how the backend orchestrates
235
+ inference + tool calls"; Tools.md owns "how tools are defined, called, and
236
+ executed."
237
+
238
+ ### 3.3 Agent Delegation (Artifacts 03, 04, 08)
239
+
240
+ Delegation mechanics appear in:
241
+ - **03 (Agent & Delegation):** `SOCIAL_INHERIT_MODES`, `socialize`, `delegate`,
242
+ `ask_agent`, `hand_off_to_<name>`
243
+ - **04 (AgentWorkflow):** How `chat_task` uses agents, `log_agent`
244
+ - **08 (Multi-Agent Patterns):** Planned, Manager, Branched, Refined patterns
245
+
246
+ **Consolidation:** Three docs with clear boundaries:
247
+ - `Agent/Delegation.md` — the mechanics (socialize, delegate, inherit modes,
248
+ ask tool, hand_off tool). Source: artifact 03.
249
+ - `Agent/AgentWorkflow.md` — the workflow bridge (chat_task, agent helper,
250
+ log_agent, tooling extraction). Source: artifact 04.
251
+ - `Agent/MultiAgentPatterns.md` — the patterns (Planned, Manager, Branched,
252
+ Refined, InterpretData). Source: artifact 08. References Delegation.md for
253
+ mechanics.
254
+
255
+ ### 3.4 Provenance (Artifacts 07, 10)
256
+
257
+ Provenance appears in:
258
+ - **07 (Provenance):** `Chat.provenance`, `trace_chats`, `prov`/`info` commands,
259
+ ChatAnalyst
260
+ - **10 (Commands):** Detailed `prov` and `info` command documentation
261
+
262
+ **Consolidation:** `Provenance/Provenance.md` should own the provenance data
263
+ model and concepts. `Commands/Commands.md` should have concise command
264
+ references that link to `Provenance.md` for concepts. Do not duplicate the full
265
+ command documentation in both places.
266
+
267
+ ### 3.5 Prompt Strategies (Artifacts 02, 04, 05)
268
+
269
+ `prepare_prompt` / `shorten_tools` is mentioned in:
270
+ - **02 (Prompt Strategies):** Full implementation detail
271
+ - **04 (AgentWorkflow):** System message injection about pruning
272
+ - **05 (Backends):** Integration point in `Backend::Default#ask`
273
+
274
+ **Consolidation:** `Chat/PromptStrategies.md` is the single source. Other docs
275
+ reference it. The system message injection (from 04) belongs in
276
+ `PromptStrategies.md` as a "How agents learn about pruning" subsection.
277
+
278
+ ---
279
+
280
+ ## 4. Artifact-to-Doc Mapping Table
281
+
282
+ | New Doc File | Primary Artifacts | Secondary Sources | Gaps to Fill |
283
+ |---|---|---|---|
284
+ | `doc/README.md` | 00, 09 | search_brief §Themes | Entry point, audience guide, TOC. Pull philosophy from 09. Write from scratch. |
285
+ | `doc/Overview.md` | 00, 09, 01 (§architecture) | search_brief §Themes, existing USER_GUIDE §1 | High-level architecture diagram (text), key abstractions, design philosophy. Installation/setup from USER_GUIDE §2. |
286
+ | `doc/Chat/Chat.md` | 01 | 06 (tool roles), existing Chat.md | Core data model, all roles, message types, builder DSL. Processing pipeline narrative owner. |
287
+ | `doc/Chat/PromptStrategies.md` | 02 | 04 (system msg injection), 05 (integration point) | `prepare_prompt`, `shorten_tools`, all thresholds (calls vs outputs), custom strategies, ephemeral nature. Fix the "10 vs 40" confusion. |
288
+ | `doc/Chat/Persistence.md` | 01 (§persistence), 07 (§annotations) | existing Chat.md, existing LLM.md §2.3 | `.chat` file format, provenance annotations (`meta:` roles), caching/persist behavior. |
289
+ | `doc/Agent/Agent.md` | 03 (§Agent class) | existing Agent.md §1–7,9,11 | Agent class lifecycle, `start_chat`/`current_chat`, DSL forwarding, tool wiring, `ask` vs `chat`, structured outputs (`json`, `json_format`, `iterate`), error handling, agent loading. |
290
+ | `doc/Agent/AgentWorkflow.md` | 04 | 03 (§delegation ref) | `chat_task` pattern, `agent`/`chat`/`tooling`/`log_agent` helpers, `require_workflow` fallback, workflow-provided `ask` task. |
291
+ | `doc/Agent/Delegation.md` | 03 (§delegation) | search_brief §Delegation | `SOCIAL_INHERIT_MODES` (3 modes), `socialize`/`ask` tool, `delegate`/`hand_off_to_<name>`, `ask_agent`, socialized chat files, legacy `chat` param. |
292
+ | `doc/Agent/MultiAgentPatterns.md` | 08 | 04 (chat_task ref) | Planned, Manager, Branched, Refined, InterpretData patterns. Budget management. Branch-specific chats. |
293
+ | `doc/Backends/Backends.md` | 05 | existing LLM.md §1,4 | Backend abstraction, `chain_tools` loop (reference Tools.md), provider table (all 9+), endpoint YAML config, `previous_response_id`, caching. |
294
+ | `doc/Tools/Tools.md` | 06 | 05 (chain_tools ref) | Tool definition format, `{name => [handler, definition]}`, calling protocol, `process_calls`, output limits (`max_content_length`). |
295
+ | `doc/Tools/WorkflowTools.md` | 06 (§workflow tools) | existing LLM.md §5.2, §6.1 | `LLM.workflow_tools`, `LLM.workflow_ask`, `tool:` chat role, task/exec_task/inline_task/job roles. |
296
+ | `doc/Tools/MCP.md` | 06 (§MCP) | 10 (`workflow mcp` cmd) | MCP integration, `mcp:` chat role, `workflow.mcp_stdio`, MCP tool wrapping. |
297
+ | `doc/Tools/KnowledgeBase.md` | 06 (§KB tools) | existing LLM.md §5.3, §6.2, existing RAG.md | KB as tool, `association:`/`kb:` roles, `LLM.knowledge_base_ask`, RAG (`LLM::RAG.index`, embeddings). Merge existing RAG.md content. |
298
+ | `doc/Provenance/Provenance.md` | 07 | 10 (`info`/`prov` cmds) | `Chat.provenance`, `trace_chats`, `job_agent_chat_files`, token accounting, `info` vs `prov` comparison, ChatAnalyst (SC26-specific). |
299
+ | `doc/Commands/Commands.md` | 10 | existing LLM.md §7 | All CLI commands with concise reference. Link to detail docs. Cover: `llm ask`, `llm info`, `llm prov` (deprecated), `llm json`, `llm md`, `llm word`, `llm template`, `llm server`, `llm process`/`process_queries` (legacy), `agent ask`, `agent find`, `agent kb`, `workflow mcp`, `documenter` (prototype). |
300
+ | `doc/Improvements.md` | 09 (§recommendations), 10 (§issues) | 07 (prov monkey-patches) | Code improvement recommendations: hardcoded paths in `prov`, monkey-patching, `documenter` prototype issues, `llm server` fallback behavior, inline mode inconsistency, `agent kb` missing require. |
301
+
302
+ ### Docs Missing from Proposed Structure
303
+
304
+ The proposed structure does NOT include:
305
+ 1. **Python integration** — Recommend adding `doc/Agent/Python.md` or a section
306
+ in `Agent/Agent.md`. Source: existing `PythonAgentTasks.md`.
307
+ 2. **Getting Started / Installation** — Recommend a section in `Overview.md`
308
+ or a standalone `doc/GettingStarted.md`. Source: existing `USER_GUIDE.md` §2.
309
+ 3. **Model subsystem** — Tangential. Keep `doc/Model.md` as-is or move to
310
+ `doc/Model/` separately. Do NOT merge into this structure.
311
+
312
+ ---
313
+
314
+ ## 5. Information from Existing Docs to Preserve
315
+
316
+ ### From `doc/USER_GUIDE.md`
317
+
318
+ | Content | Status in Artifacts | Action |
319
+ |---|---|---|
320
+ | §1 "What Scout-AI is" (conceptual overview) | ✅ Covered in 00, 09 | Rewrite for `Overview.md` |
321
+ | §2 Installation (Gemfile, bundle install) | ❌ NOT in artifacts | **PRESERVE** → `Overview.md` or `GettingStarted.md` |
322
+ | §3 Endpoint setup walkthrough | ❌ NOT in artifacts | **PRESERVE** → `Backends/Backends.md` |
323
+ | §4 Chat file tutorial | ✅ Covered in 01 | Rewrite for `Chat/Chat.md` |
324
+ | §5 Agent tutorial | ✅ Covered in 03 | Rewrite for `Agent/Agent.md` |
325
+ | §6 Workflow tools tutorial | ✅ Covered in 06 | Rewrite for `Tools/WorkflowTools.md` |
326
+ | §7 Multi-agent patterns | ✅ Covered in 08 | Rewrite for `Agent/MultiAgentPatterns.md` |
327
+ | Step-by-step learning sequence | ❌ NOT in artifacts | **PRESERVE** → `README.md` (audience guide / reading path) |
328
+
329
+ ### From `doc/Agent.md`
330
+
331
+ | Content | Status in Artifacts | Action |
332
+ |---|---|---|
333
+ | §1–2 Quick start, factory shortcut | ✅ Covered in 03 | Rewrite for `Agent/Agent.md` |
334
+ | §3 DSL forwarding (`method_missing`) | ⚠️ Mentioned in 03 but not detailed | **PRESERVE** → `Agent/Agent.md` |
335
+ | §4 Tool wiring (merge rules) | ✅ Covered in 06 | Rewrite for `Agent/Agent.md` + `Tools/Tools.md` |
336
+ | §4.4 "Skills" vs Workflow distinction | ❌ NOT in artifacts | **PRESERVE** → `Overview.md` or `Agent/Agent.md` |
337
+ | §5 `ask` vs `chat` | ✅ Covered in 03 | Rewrite for `Agent/Agent.md` |
338
+ | §6 Structured outputs (`json`, `json_format`) | ❌ NOT deeply in artifacts | **PRESERVE** → `Agent/Agent.md` |
339
+ | §7 Iteration helpers (`iterate`, `iterate_dictionary`) | ⚠️ Partially in 03 | **PRESERVE** → `Agent/Agent.md` |
340
+ | §8 Delegation (basic example) | ✅ Covered in 03 | Rewrite for `Agent/Delegation.md` |
341
+ | §8.1 Socialized chats | ✅ Covered in 03, 04 | Rewrite for `Agent/Delegation.md` |
342
+ | §9 Agent loading / directory layout | ✅ Covered in 03 | Rewrite for `Agent/Agent.md` |
343
+ | §10 Workflow-provided `ask` task | ✅ Covered in 04 | Rewrite for `Agent/AgentWorkflow.md` |
344
+ | §11 Error handling (`process_exception`) | ❌ NOT in artifacts | **PRESERVE** → `Agent/Agent.md` |
345
+ | §12 CLI integration | ✅ Covered in 10 | Rewrite for `Commands/Commands.md` |
346
+
347
+ ### From `doc/Chat.md`
348
+
349
+ | Content | Status in Artifacts | Action |
350
+ |---|---|---|
351
+ | §0 Mental model (chat as conversation + control surface) | ✅ Covered in 01 | Rewrite for `Chat/Chat.md` |
352
+ | §1 Data model | ✅ Covered in 01 | Rewrite for `Chat/Chat.md` |
353
+ | Full role reference (all roles with syntax) | ✅ Covered in 01 | Rewrite for `Chat/Chat.md` |
354
+ | `option:` / `sticky_option:` behavior | ⚠️ Partially in 01 | **PRESERVE** details → `Chat/Chat.md` |
355
+
356
+ ### From `doc/LLM.md`
357
+
358
+ | Content | Status in Artifacts | Action |
359
+ |---|---|---|
360
+ | §1 Endpoint configuration (YAML examples) | ❌ NOT in artifacts | **PRESERVE** → `Backends/Backends.md` |
361
+ | §2 `LLM.ask` input types, option resolution | ✅ Covered in 05 | Rewrite for `Backends/Backends.md` |
362
+ | §2.3 Caching (`persist`) | ❌ NOT in artifacts | **PRESERVE** → `Chat/Persistence.md` or `Backends/Backends.md` |
363
+ | §3 Chat compilation (`LLM.chat`) | ✅ Covered in 01 | Reference `Chat/Chat.md` |
364
+ | §4 Backend list and options | ✅ Covered in 05 | Rewrite for `Backends/Backends.md` |
365
+ | §4.2 `previous_response_id` | ❌ NOT in artifacts | **PRESERVE** → `Backends/Backends.md` |
366
+ | §5 Tools and function calling | ✅ Covered in 06 | Rewrite for `Tools/Tools.md` |
367
+ | §6 Convenience helpers (`workflow_ask`, `knowledge_base_ask`) | ❌ NOT in artifacts | **PRESERVE** → `Tools/WorkflowTools.md` and `Tools/KnowledgeBase.md` |
368
+ | §7 CLI usage | ✅ Covered in 10 | Rewrite for `Commands/Commands.md` |
369
+ | §9 Minimal end-to-end example | ❌ NOT in artifacts | **PRESERVE** → `Overview.md` or `GettingStarted.md` |
370
+
371
+ ### From `doc/RAG.md`
372
+
373
+ | Content | Status in Artifacts | Action |
374
+ |---|---|---|
375
+ | `LLM::RAG.index` (HNSW index building) | ❌ NOT in artifacts | **PRESERVE** → `Tools/KnowledgeBase.md` |
376
+ | Embedding flow (`LLM.embed`) | ❌ NOT in artifacts | **PRESERVE** → `Tools/KnowledgeBase.md` |
377
+ | End-to-end RAG example | ❌ NOT in artifacts | **PRESERVE** → `Tools/KnowledgeBase.md` |
378
+
379
+ ### From `doc/PythonAgentTasks.md`
380
+
381
+ | Content | Status in Artifacts | Action |
382
+ |---|---|---|
383
+ | Python task auto-loading (`python/*.py`) | ❌ NOT in artifacts | **PRESERVE** → `Agent/Agent.md` (section) or new `Agent/Python.md` |
384
+ | `PythonWorkflow.load_directory` integration | ❌ NOT in artifacts | **PRESERVE** → same |
385
+ | When to use Python vs Ruby guidance | ❌ NOT in artifacts | **PRESERVE** → same |
386
+
387
+ ### From `doc/Model.md`
388
+
389
+ | Content | Status in Artifacts | Action |
390
+ |---|---|---|
391
+ | Entire Model subsystem (ScoutModel, PythonModel, etc.) | ❌ NOT in artifacts | **OUT OF SCOPE** — keep as separate doc, do not merge |
392
+
393
+ ---
394
+
395
+ ## 6. Priority Order for Writing New Docs
396
+
397
+ ### Phase 1: Foundation (write first — everything else references these)
398
+
399
+ | Priority | Doc | Rationale |
400
+ |---|---|---|
401
+ | 1 | `doc/Overview.md` | Sets the conceptual frame. All other docs are read in its context. Needs installation + setup from existing USER_GUIDE. |
402
+ | 2 | `doc/Chat/Chat.md` | The Chat data model is the foundation of everything. Must define roles, message types, and the processing pipeline before Agent/Tools/Backends can reference them. |
403
+ | 3 | `doc/README.md` | Entry point with TOC. Can only be written once the doc structure is populated. Write a draft now, finalize last. |
404
+
405
+ ### Phase 2: Core Systems (depend on Chat)
406
+
407
+ | Priority | Doc | Rationale |
408
+ |---|---|---|
409
+ | 4 | `doc/Agent/Agent.md` | Central to the agent story. Depends on Chat.md for role definitions. Must preserve structured outputs, error handling, DSL forwarding from existing Agent.md. |
410
+ | 5 | `doc/Tools/Tools.md` | Tool definition and calling protocol. Depends on Chat.md for tool roles. Referenced by Backends, WorkflowTools, KB, MCP. |
411
+ | 6 | `doc/Backends/Backends.md` | Backend abstraction and inference loop. Depends on Tools.md (chain_tools) and Chat.md (prepare_prompt). Must preserve endpoint config from existing LLM.md. |
412
+
413
+ ### Phase 3: Specialized Topics (depend on Agent + Tools)
414
+
415
+ | Priority | Doc | Rationale |
416
+ |---|---|---|
417
+ | 7 | `doc/Chat/PromptStrategies.md` | Focused topic. Depends on Chat.md and Backends.md (integration point). Must fix the threshold confusion. |
418
+ | 8 | `doc/Agent/Delegation.md` | Depends on Agent.md. Key differentiator for Scout-AI. |
419
+ | 9 | `doc/Agent/AgentWorkflow.md` | Depends on Agent.md and Delegation.md. The workflow bridge. |
420
+ | 10 | `doc/Chat/Persistence.md` | Depends on Chat.md. Provenance annotations bridge to Provenance.md. |
421
+ | 11 | `doc/Tools/WorkflowTools.md` | Depends on Tools.md. Straightforward extraction from artifact 06. |
422
+ | 12 | `doc/Tools/KnowledgeBase.md` | Depends on Tools.md. Must merge existing RAG.md content. |
423
+ | 13 | `doc/Tools/MCP.md` | Depends on Tools.md. Shortest doc, can be written quickly. |
424
+
425
+ ### Phase 4: Patterns and Provenance (depend on multiple core docs)
426
+
427
+ | Priority | Doc | Rationale |
428
+ |---|---|---|
429
+ | 14 | `doc/Agent/MultiAgentPatterns.md` | Depends on Agent.md, Delegation.md, AgentWorkflow.md. Synthesizes artifact 08. |
430
+ | 15 | `doc/Provenance/Provenance.md` | Depends on Chat/Persistence.md, AgentWorkflow.md. Covers artifact 07 + command details. |
431
+
432
+ ### Phase 5: Reference and Meta (write last)
433
+
434
+ | Priority | Doc | Rationale |
435
+ |---|---|---|
436
+ | 16 | `doc/Commands/Commands.md` | Reference doc. Best written last when all concepts are defined. Concise entries with links to detail docs. |
437
+ | 17 | `doc/Improvements.md` | Meta doc. Synthesize issues found across all artifacts. Source from 09 (recommendations) and 10 (command issues). |
438
+ | 18 | `doc/README.md` (finalize) | Finalize TOC, reading paths, and cross-references now that all docs exist. |
439
+
440
+ ### Summary Priority Order
441
+
442
+ ```
443
+ 1. Overview.md
444
+ 2. Chat/Chat.md
445
+ 3. Agent/Agent.md
446
+ 4. Tools/Tools.md
447
+ 5. Backends/Backends.md
448
+ 6. Chat/PromptStrategies.md
449
+ 7. Agent/Delegation.md
450
+ 8. Agent/AgentWorkflow.md
451
+ 9. Chat/Persistence.md
452
+ 10. Tools/WorkflowTools.md
453
+ 11. Tools/KnowledgeBase.md
454
+ 12. Tools/MCP.md
455
+ 13. Agent/MultiAgentPatterns.md
456
+ 14. Provenance/Provenance.md
457
+ 15. Commands/Commands.md
458
+ 16. Improvements.md
459
+ 17. README.md (finalize)
460
+ ```
461
+
462
+ **Parallelization opportunity:** Docs 10–12 (WorkflowTools, KnowledgeBase, MCP)
463
+ can be written in parallel once Tools.md (priority 4) is complete. Similarly,
464
+ docs 6–8 (PromptStrategies, Delegation, AgentWorkflow) can be parallelized once
465
+ Agent.md (priority 3) and Backends.md (priority 5) are complete.
466
+
467
+ ---
468
+
469
+ ## Appendix: Artifact Quality Assessment
470
+
471
+ | Artifact | Completeness | Code-Verified | Ready for Doc Writing |
472
+ |---|---|---|---|
473
+ | 00 (Scope) | ✅ Full | N/A (meta) | ✅ Yes |
474
+ | 01 (Chat Core) | ✅ Full | ✅ Yes | ✅ Yes |
475
+ | 02 (Prompt Strategies) | ✅ Full | ✅ Yes | ✅ Yes (fix threshold naming) |
476
+ | 03 (Agent & Delegation) | ✅ Full | ✅ Yes | ✅ Yes |
477
+ | 04 (AgentWorkflow) | ✅ Full | ✅ Yes | ✅ Yes |
478
+ | 05 (Backends) | ✅ Full | ✅ Yes | ✅ Yes |
479
+ | 06 (Tools System) | ✅ Full | ✅ Yes | ✅ Yes |
480
+ | 07 (Provenance) | ✅ Full | ✅ Yes | ✅ Yes |
481
+ | 08 (Multi-Agent Patterns) | ✅ Full | ✅ Yes | ✅ Yes |
482
+ | 09 (Coding Philosophy) | ✅ Full | ✅ Yes | ✅ Yes |
483
+ | 10 (Commands) | ✅ Full | ✅ Yes | ✅ Yes |
484
+
485
+ All 10 research artifacts are complete and code-verified. No re-investigation
486
+ is needed before writing documentation. The main work is synthesis, gap-filling
487
+ (from existing docs), and ensuring consistent terminology.