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.
Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +135 -55
  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 +320 -34
  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 +402 -44
  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 +64 -0
  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 +79 -17
  39. data/lib/scout/llm/agent.rb +151 -27
  40. data/lib/scout/llm/ask.rb +37 -27
  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 +131 -32
  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 -52
  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 +352 -626
  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 +72 -26
  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 +845 -80
  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 +109 -22
  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 +200 -28
  127. data/test/scout/llm/chat/test_agent_meta_tokens.rb +112 -7
  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 +708 -13
  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 +71 -25
  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/synthesis-report.md +0 -487
  185. data/research/tools-system-analysis.md +0 -779
@@ -15,14 +15,25 @@ available, the model sees its name, description, and parameter schema. If the
15
15
  model decides to call the tool, Scout-AI executes it, appends the result to the
16
16
  conversation, and re-sends the conversation so the model can use the result.
17
17
 
18
- Scout-AI supports three kinds of tools:
18
+ Chat files declare three kinds of tools:
19
19
 
20
20
  | Kind | How to declare | What it provides |
21
21
  |------|---------------|-----------------|
22
- | **Workflow tools** | `tool:` / `introduce:` in chat, or auto-wired from agent workflow | Typed tasks from a Scout Workflow |
22
+ | **Workflow tools** | `tool:` in chat, or auto-wired from agent workflow | Typed tasks from a Scout Workflow |
23
23
  | **Knowledge base tools** | `kb:` in chat | Database lookups |
24
24
  | **MCP tools** | `mcp:` in chat | Any MCP-compatible external server |
25
25
 
26
+ `introduce:` is **not** a tool declaration: it injects the workflow's
27
+ documentation as a `user:` message and generates **zero** tool definitions
28
+ (deduplicated per workflow). Use it to explain a workflow to the model; use
29
+ `tool:` to give the model its tasks.
30
+
31
+ Internally every registered tool is a `{name => [executor, definition]}`
32
+ pair, and the executor is one of four kinds: a raw `Proc` (used by
33
+ agent-layer tools such as `ask`, `attach` and `hand_off_to_<name>`, and by MCP
34
+ client tools), a workflow module, a workflow name (`String`), or a
35
+ `KnowledgeBase`.
36
+
26
37
  ---
27
38
 
28
39
  ## Workflow tools
@@ -32,20 +43,40 @@ expose a workflow as tools, each task becomes a callable function.
32
43
 
33
44
  ### Exposing an entire workflow
34
45
 
46
+ ```text
47
+ tool: MyWorkflow
48
+ ```
49
+
50
+ This generates one tool per exported task (or, when the workflow has no
51
+ exports, one tool per task). The model can call any of them, providing inputs
52
+ as arguments. Agents that have a workflow with tasks get this wiring
53
+ automatically.
54
+
55
+ ### Introducing a workflow without tools
56
+
35
57
  ```text
36
58
  introduce: MyWorkflow
37
59
  ```
38
60
 
39
- This auto-generates a tool definition for every task in the workflow. The model
40
- can call any task, providing inputs as arguments.
61
+ Injects the workflow's title and description as a `user:` message. No tool is
62
+ created — pair it with `tool:` if the model also needs the tasks.
41
63
 
42
64
  ### Exposing a specific task
43
65
 
44
66
  ```text
45
- tool: MyWorkflow my_task input1=value1 input2=value2
67
+ tool: MyWorkflow my_task input1 input2=value1
46
68
  ```
47
69
 
48
- This exposes only `my_task` from `MyWorkflow`, with some inputs pre-filled.
70
+ This exposes only `my_task` from `MyWorkflow`. Two input forms exist:
71
+
72
+ - bare names (`input1`) restrict which inputs appear in the tool's schema;
73
+ - `name=value` tokens (`input2=value1`) pre-fill an input **and hide it from
74
+ the model-visible schema**.
75
+
76
+ Pre-filled values are *definition defaults*, and defaults take precedence:
77
+ when the call is executed, the saved value is merged over whatever the model
78
+ sent for that argument, so the model cannot override it. Treat `name=value` as
79
+ a fixed parameter, not a suggestion.
49
80
 
50
81
  ### How it works
51
82
 
@@ -56,6 +87,29 @@ When the model calls a workflow tool:
56
87
  3. The result is converted to text and returned as a tool output message.
57
88
  4. The model sees the result and continues.
58
89
 
90
+ Three call parameters are not part of the task schema but steer how the job
91
+ is produced (they are consumed by the dispatch, never forwarded as inputs):
92
+
93
+ - `jobname` — pins the job name instead of the content-derived default, so a
94
+ specific job can be re-invoked by name.
95
+ - `return_path` — runs the job in the background and answers the model with
96
+ the job *path* on disk (also whitelisted for the chat read access) rather
97
+ than waiting for the result.
98
+ - `exec_type=exec` — runs the job in-process and synchronously with
99
+ `job.exec`, without persisting a Step. Tasks exported as `exec` exports
100
+ behave this way regardless of the parameter.
101
+
102
+ A recursion guard backs the normal path: if the requested job is already
103
+ running in the same process (same pid), the call raises
104
+ `ScoutException: Potential recursive call` unless the model passes
105
+ `allow_recursive=true`; the guard exists so a workflow tool cannot
106
+ indirectly re-enter itself.
107
+
108
+ Tool calls that return a **Step** are deferred, not run one by one: all the
109
+ steps of a round are collected and batch-produced together
110
+ (`Workflow.produce`), so several workflow tools called in the same turn
111
+ can execute concurrently.
112
+
59
113
  ### Inline workflow definition
60
114
 
61
115
  In Ruby, you can define a workflow inline on an agent:
@@ -84,12 +138,22 @@ If your agent or chat has a knowledge base, its databases become tools the
84
138
  model can query.
85
139
 
86
140
  ```text
87
- kb: my_database [genes proteins interactions]
141
+ kb: my_kb genes proteins interactions
88
142
  ```
89
143
 
90
- This exposes two tools per database:
91
- - `my_database(entities: [...])` — find related entities.
92
- - `my_database_association_details(entities: [...])` — get association details.
144
+ `my_kb` is a knowledge-base path or an agent name; the database names are
145
+ optional and select a subset.
146
+
147
+ One *association* tool is exposed per database, plus — only when the database
148
+ source has fields (a third column) — a details tool:
149
+
150
+ - `my_database(entities: [...])` — find related entities. Directed databases
151
+ also take `reverse` to look up targets instead of sources; undirected ones
152
+ take only `entities`.
153
+ - `my_database_association_details(associations: [...])` — return the fields
154
+ of given `source~target` pairs, optionally restricted to a subset with
155
+ `fields: [...]`. Exists only when the database has fields; a single-field
156
+ database drops the `fields` argument.
93
157
 
94
158
  ### From an agent
95
159
 
@@ -99,6 +163,20 @@ agent = LLM::Agent.new(knowledge_base: 'my_kb')
99
163
 
100
164
  The KB's databases are automatically wired as tools.
101
165
 
166
+ ### Registering a TSV as a database mid-conversation
167
+
168
+ The `association:` chat role registers a TSV file as a knowledge-base
169
+ database on the fly and immediately exposes the same two tools for it:
170
+
171
+ ```text
172
+ association: my_db /path/to/data.tsv fields=col1,col2 type=double
173
+ ```
174
+
175
+ The first token is the database name, the second the TSV path;
176
+ `fields=` and `type=` become the database options (`fields=` takes a
177
+ comma-separated list). `clear_associations:` drops everything registered
178
+ this way (it does not touch `kb:`-declared databases).
179
+
102
180
  ---
103
181
 
104
182
  ## MCP tools
@@ -115,16 +193,25 @@ mcp: https://api.example.com/mcp/
115
193
  ### Stdio MCP server
116
194
 
117
195
  ```text
118
- mcp: stdio my-mcp-command arg1 arg2
196
+ mcp: stdio my-mcp-command
119
197
  ```
120
198
 
121
199
  ### Selecting specific tools
122
200
 
123
201
  ```text
124
- mcp: https://api.example.com/mcp/ [search write_file]
202
+ mcp: https://api.example.com/mcp/ search write_file
125
203
  ```
126
204
 
127
- Only the named tools will be available.
205
+ Only the named tools will be available. Note that with `mcp: stdio <command>`,
206
+ **every token after the command is a tool-name filter**, not an argument to the
207
+ command — `mcp: stdio echo x` runs `echo` and selects the tool named `x`.
208
+
209
+ ### Serving a Scout workflow over MCP
210
+
211
+ The other direction exists too: `Workflow#mcp` wraps a workflow's tasks as
212
+ MCP tools (one per exported task, or one per task named explicitly) and
213
+ returns an `MCP::Server`; `mcp_stdio` mounts it on the stdio transport.
214
+ The CLI entry point is `scout-ai workflow mcp [tasks...]`.
128
215
 
129
216
  ---
130
217
 
@@ -134,9 +221,17 @@ When a tool is called, the conversation grows with two messages:
134
221
 
135
222
  ```text
136
223
  function_call: {"name":"search","arguments":{"query":"ruby blocks"},"id":"call_1"}
137
- function_call_output: {"id":"call_1","content":"Ruby blocks are..."}
224
+ function_call_output: {"id":"call_1","name":"search","content":"Ruby blocks are..."}
138
225
  ```
139
226
 
227
+ The output envelope also carries `error`, `stack`, `meta`, `step`,
228
+ `start_timestamp` and `timestamp` when applicable, and oversized results are
229
+ replaced by a truncation notice that points at the persisted step. The
230
+ threshold is `LLM.max_content_length` (config key `max_content_length`,
231
+ scopes `:llm_tools`, `:tools`, `:llm`, `:ask`; default 100,000 characters);
232
+ the replacement is a JSON error object with a `Log.fingerprint` of the content
233
+ so the model can still identify what it lost.
234
+
140
235
  The tool-calling loop is automatic. If the model calls multiple tools in one
141
236
  turn, or calls a tool and then needs to call another, Scout-AI handles the
142
237
  iteration until the model responds with plain text.
@@ -147,10 +242,16 @@ iteration until the model responds with plain text.
147
242
 
148
243
  ### Forcing a tool call
149
244
 
245
+ `tool_choice` is passed through to the provider verbatim, so it takes the
246
+ provider's own spelling:
247
+
150
248
  ```ruby
151
249
  agent.option :tool_choice, {type: 'function', function: {name: 'search'}}
152
250
  ```
153
251
 
252
+ It is dropped after the first tool round (each re-entry of the loop starts
253
+ from the model's own choice).
254
+
154
255
  ### Clearing tools
155
256
 
156
257
  ```text
@@ -162,32 +263,36 @@ clear_tools: true
162
263
  ## When to use tools vs. direct code
163
264
 
164
265
  Tools are for things the **model** should decide to do. If you know you need a
165
- piece of data before inference, just put it in the chat as a file or user
166
- message. Use tools when:
266
+ piece of data before inference, put it in the chat as a file or user message.
167
267
 
168
- - The model needs to **decide** whether to look something up.
169
- - The model needs to **iterate** — call a tool, see results, call another.
268
+ - The model must **decide** whether to look something up.
269
+ - The model must **iterate** — call a tool, see results, call another.
170
270
  - The operation is **expensive** and should only run when needed.
171
271
  - You want the **provenance** of tool calls recorded in the chat history.
172
272
 
273
+ Otherwise prefer direct code: it is cheaper, deterministic, and cacheable.
274
+
173
275
  ---
174
276
 
175
277
  ## Common mistakes
176
278
 
177
- - **Declaring tools but forgetting the workflow**: If you write
178
- `introduce: MyWorkflow` but the workflow is not on the agent's load path,
179
- the tools won't resolve.
180
- - **Expecting tool results to be structured**: Tool results are always
181
- converted to text before being shown to the model. If you need structured
182
- data, use JSON format and tell the model to expect it.
183
- - **Overloading the model with too many tools**: Each tool adds to the context
184
- size. Introduce only the workflows relevant to the task.
279
+ - **Writing `introduce: MyWorkflow` and expecting tools**: `introduce:` injects
280
+ documentation only. Use `tool: MyWorkflow` to generate tools.
281
+ - **Expecting a `name=value` pre-fill to be overridable**: pre-filled inputs
282
+ are hidden from the model and their values win over model arguments.
283
+ - **Expecting two KB tools per database**: the `_association_details` tool only
284
+ exists when the database source has fields.
285
+ - **Expecting tool results to be structured**: results are converted to text
286
+ before being shown to the model. Use JSON format if you need structure.
287
+ - **Overloading the model with too many tools**: each tool adds to the context
288
+ size. Expose only the workflows relevant to the task.
185
289
 
186
290
  ---
187
291
 
188
- ## Next steps
292
+ ## See also
189
293
 
190
- - [BuildingAgents.md](BuildingAgents.md) — how agents auto-wire tools.
191
- - [RunningInference.md](RunningInference.md) — endpoint and model configuration.
192
294
  - [ManagingContext.md](ManagingContext.md) — what happens when tool calls
193
295
  accumulate and the context gets long.
296
+ - [../developer/Backends.md](../developer/Backends.md) — the inference loop
297
+ that drives tool calls.
298
+ - [RunningInference.md](RunningInference.md) — endpoint and model configuration.
@@ -10,8 +10,9 @@ or construct chat inputs for agents and workflows.
10
10
 
11
11
  ## The basic format
12
12
 
13
- A chat file is plain text. Each message is a **role name** followed by a colon,
14
- a blank line, then the content:
13
+ A chat file is plain text. Each message is a **role name** followed by a
14
+ colon, then the content (a blank line in between is the convention, not a
15
+ parser requirement):
15
16
 
16
17
  ```text
17
18
  system:
@@ -29,8 +30,22 @@ assistant:
29
30
 
30
31
  Rules:
31
32
  - The role name is the first non-blank token on the line, followed by `:`.
32
- - A blank line separates the role header from the content.
33
+ - A blank line separates the role header from the content (a readability
34
+ convention; the parser does not require it).
33
35
  - Content continues until the next role header or end of file.
36
+ - There is **no comment syntax**: a `#` line is message content.
37
+ - A line matching a role header can be escaped with a leading backslash
38
+ (`\user: literal text`); the backslash is dropped and the rest is kept
39
+ as literal content.
40
+
41
+ Some blocks are protected from role-header parsing, so a line inside them
42
+ that happens to look like `something: text` stays content:
43
+
44
+ - triple-backtick code fences;
45
+ - `[[ ... ]]` bracket blocks;
46
+ - an XML-ish tag opened as `<tag ...>` with a matching closing tag;
47
+ - command-output markers, written `name:-- command {{{` … `name:-- command }}}`
48
+ and normalized to `<cmd_output cmd="command">` … `</cmd_output>`.
34
49
 
35
50
  ---
36
51
 
@@ -68,15 +83,43 @@ endpoint: anthropic
68
83
  model: claude-sonnet-4-20250514
69
84
  ```
70
85
 
86
+ The full option-related set, and how each behaves:
87
+
88
+ | Role | Sticky? | Notes |
89
+ |---|---|---|
90
+ | `option` | no | cleared by the next `assistant` reply |
91
+ | `sticky_option` | yes | survives assistant replies |
92
+ | `endpoint`, `model`, `backend`, `agent` | yes | removed from the chat once read |
93
+ | `previous_response_id` | yes | kept in the chat (it is also the Responses-API continuation record) |
94
+ | `persist` | no | ordinary option: cleared by the next `assistant` reply |
95
+ | `format` | no | a JSON-schema response format; a value that is an existing filename is loaded and its JSON used |
96
+
71
97
  ### Declaring tools
72
98
 
73
99
  ```text
100
+ tool: MyWorkflow
74
101
  tool: MyWorkflow task_name input1=value1 input2=value2
75
102
  introduce: MyWorkflow
103
+ path_kind: MyWorkflow
104
+ path_kind: MyWorkflow path_kind_name
76
105
  ```
77
106
 
78
- - `tool:` exposes a specific workflow task.
79
- - `introduce:` exposes an entire workflow (all its tasks).
107
+ - `tool: MyWorkflow` exposes the whole workflow (its exports, or all its
108
+ tasks if it has none exported). It registers path kinds only for an
109
+ agent without a start_chat file (back-compat default; see below).
110
+ - `tool: MyWorkflow task_name ...` exposes one task; `name=value` tokens
111
+ pre-fill and hide that input. This form never registers path kinds.
112
+ - `introduce:` injects the workflow's documentation only; it generates no
113
+ tools. Combine it with `tool:` when you want both.
114
+ - `path_kind: MyWorkflow` enables every path kind the workflow declares;
115
+ `path_kind: MyWorkflow path_kind_name` enables exactly that kind, and
116
+ several kinds can be named on one line or across several lines.
117
+ Explicit `path_kind:` lines are honored wherever they appear, in the
118
+ start_chat or in the live chat. An agent with a start_chat file gets
119
+ no path kinds unless a `path_kind:` line says so; an agent without
120
+ one defaults to loading every kind of its own workflow. The full
121
+ loading rules live in the
122
+ [Path engine](../developer/PathEngine.md) developer document (§4.1).
80
123
 
81
124
  ### Importing files
82
125
 
@@ -119,20 +162,6 @@ see them in saved agent sessions.
119
162
 
120
163
  ---
121
164
 
122
- ## Comments
123
-
124
- Lines starting with `#` are comments and are ignored:
125
-
126
- ```text
127
- # This is a comment
128
- system:
129
-
130
- # So is this
131
- You are a helpful assistant.
132
- ```
133
-
134
- ---
135
-
136
165
  ## Metadata and provenance
137
166
 
138
167
  When Scout-AI saves a conversation (e.g., as a workflow job output), it
@@ -151,26 +180,23 @@ trees.
151
180
  ## Complete example
152
181
 
153
182
  Here is a realistic chat file that configures an endpoint, declares tools,
154
- imports a file, and asks a question:
183
+ imports a file, and asks a question. There is **no comment syntax**: a
184
+ line starting with `#` is parsed as a user message.
155
185
 
156
186
  ```text
157
- # Configuration
158
187
  endpoint: anthropic
159
188
  model: claude-sonnet-4-20250514
160
189
 
161
- # System prompt
162
190
  system:
163
191
 
164
192
  You are a code analyst. Use the provided tools to answer questions about
165
193
  the codebase.
166
194
 
167
- # Give the model a workflow as tools
168
195
  introduce: CodeAnalyzer
196
+ tool: CodeAnalyzer
169
197
 
170
- # Import context
171
198
  file: src/main.rb
172
199
 
173
- # The question
174
200
  user:
175
201
 
176
202
  What design patterns are used in main.rb?
@@ -180,8 +206,11 @@ What design patterns are used in main.rb?
180
206
 
181
207
  ## Common mistakes
182
208
 
183
- - **Forgetting the blank line** between the role header and content. Without
184
- it, the role header and content may merge.
209
+ - **Using `#` as a comment marker.** There is no comment syntax; a `#` line
210
+ is a user message and will be sent to the model.
211
+ - **Forgetting the blank line** between the role header and content. This is
212
+ the established convention in Scout-AI's own files; keep it for
213
+ readability, but the parser does not require it.
185
214
  - **Using unknown role names.** Only recognized roles are processed; unknown
186
215
  ones are treated as literal user messages.
187
216
  - **Expecting configuration roles to appear in the model's prompt.** Roles
@@ -0,0 +1,64 @@
1
+ module LLM
2
+ class Agent
3
+
4
+ ATACH_TYPES = %w(auto image pdf png jpeg)
5
+ def attachments(options = {})
6
+ @other_options[:tools] ||= {}
7
+
8
+ task_name = :attach
9
+ block = Proc.new do |_name, parameters|
10
+ begin
11
+ path = Path.setup(parameters[:file]).find
12
+ raise ScoutException, "Path not found: #{path}" unless path.exists?
13
+
14
+ # ScoutCoder: bug B1. Two stacked defects made the pdf branch
15
+ # unreachable: (a) the normalization else-branch overwrote an
16
+ # explicit file_type 'pdf' (and every other value) with 'image';
17
+ # (b) the dispatcher below was a bare `case` with no subject, so
18
+ # the first when-list matched unconditionally. Normalize ONLY the
19
+ # 'auto' value (the schema default) and dispatch on the subject.
20
+ file_type = (parameters[:file_type] || 'auto').to_s
21
+ if file_type == 'auto' && path.get_extension.downcase == 'pdf'
22
+ file_type = 'pdf'
23
+ elsif file_type == 'auto'
24
+ file_type = 'image'
25
+ end
26
+
27
+ case file_type
28
+ when 'image', 'png', 'jpeg'
29
+ self.image path
30
+ when 'pdf'
31
+ self.pdf path
32
+ else
33
+ raise ScoutException, "Unkown file type: #{parameters[:file_type]}"
34
+ end
35
+ "File attached."
36
+ rescue ScoutException => e
37
+ e
38
+ end
39
+ end
40
+
41
+ properties = {
42
+ file: {
43
+ type: 'string',
44
+ description: 'Path to the file'
45
+ },
46
+ file_type: {
47
+ type: 'string',
48
+ description: 'File type of the file (e.g image, pdf), auto by default',
49
+ enum: ATACH_TYPES,
50
+ default: 'auto'
51
+ },
52
+ }
53
+
54
+ description = <<-EOF
55
+ Attach a file to the current chat, supports images and pdfs.
56
+ EOF
57
+
58
+ definition = LLM.tool_definition(task_name, description, properties,
59
+ required: [:file])
60
+ @other_options[:tools][task_name] = [block, definition]
61
+ end
62
+ end
63
+ end
64
+
@@ -18,12 +18,44 @@ module LLM
18
18
  (@current_chat || start_chat).annotate chat unless Chat === chat
19
19
  @current_chat = chat
20
20
  else
21
+ # Restart: keep the displaced conversation (exact object, including
22
+ # every accumulated turn) available to `restore_restarted_chat` so a
23
+ # round rejected before inference can undo this restart precisely.
24
+ @restart_undo_stash = @current_chat if Chat === @current_chat && @current_chat.any?
21
25
  start_chat = self.start_chat
22
26
  Chat.setup(start_chat) unless Chat === start_chat
23
27
  @current_chat = start_chat.branch
24
28
  end
25
29
  end
26
30
 
31
+ # The exact chat object displaced by the last `start`-restart (the branch
32
+ # that had accumulated the conversation's turns). Held only for the
33
+ # current restart, overwritten by the next one: `restore_restarted_chat`
34
+ # consumes it to undo a restart whose round was rejected before any
35
+ # inference ran, and anything else can keep reading the snapshot written
36
+ # under <save_file>.files/resets/ instead.
37
+ def restart_undo_stash
38
+ @restart_undo_stash
39
+ end
40
+
41
+ def restart_undo_stash=(chat)
42
+ @restart_undo_stash = chat
43
+ end
44
+
45
+ # Undo one restart that has not been advanced since: put the displaced
46
+ # chat back as current_chat, keeping `start_chat` (the restart kept it,
47
+ # and the stashed chat already prefixes it). Returns the restored chat.
48
+ # Raises when the restarted branch has been mutated since the restart
49
+ # (its tail no longer matches the re-branched start_chat), because
50
+ # restoring then would silently drop those appended turns.
51
+ def restore_restarted_chat(prior)
52
+ raise ScoutException, 'Cannot restore a restarted chat that has advanced' unless current_chat == start_chat.branch
53
+ @current_chat = prior
54
+ end
55
+
56
+ def current_chat=(chat)
57
+ @current_chat = Chat.setup(chat)
58
+ end
27
59
  def current_chat
28
60
  @current_chat ||= start
29
61
  end
@@ -0,0 +1,64 @@
1
+ # Low-level mechanics for creating an independent agent conversation.
2
+ #
3
+ # This module deliberately knows nothing about social inheritance, workflow
4
+ # introductions, or persistent workspace policy. Callers compose the seed and
5
+ # decide the anchor/job; this module only makes that composition safe and
6
+ # starts a fresh agent from it.
7
+ module LLM
8
+ class Agent
9
+ module Construction
10
+ module_function
11
+
12
+ # Duplicate the plain values used by agent options and Chat messages.
13
+ # Agent options are deliberately not Marshal-copied: they can contain
14
+ # Procs and other executable objects.
15
+ def duplicate(value)
16
+ case value
17
+ when Hash
18
+ value.each_with_object({}) do |(key, item), copy|
19
+ copy[duplicate(key)] = duplicate(item)
20
+ end
21
+ when Array
22
+ value.collect { |item| duplicate(item) }
23
+ when String
24
+ value.dup
25
+ else
26
+ value
27
+ end
28
+ end
29
+
30
+ def chat_copy(chat)
31
+ Chat.setup(duplicate(chat || []))
32
+ end
33
+
34
+ # Clone an already-resolved template without sharing mutable seed,
35
+ # option, society, or live-conversation state.
36
+ def clone_agent(template)
37
+ agent = template.clone
38
+ agent.request_context = template.request_context
39
+ agent.start_chat = chat_copy(template.start_chat)
40
+ # Carry the deliberate-preparation signal across the clone (nil on the
41
+ # template recomputes from the copied start_chat; an explicit false --
42
+ # load_agent's synthetic `introduce` fallback -- must survive, or the
43
+ # clone would flip to loading kinds implicitly; see Agent#ask).
44
+ agent.start_chat_file = template.start_chat_file?
45
+ agent.other_options = IndiferentHash.setup(duplicate(template.other_options || {}))
46
+ agent.society = nil
47
+ agent.chats = nil
48
+ agent.instance_variable_set(:@current_chat, nil)
49
+ agent
50
+ end
51
+
52
+ # Construct the live agent after the caller has finished composing its
53
+ # policy-specific seed. Anchoring and job attachment happen before the
54
+ # first start/chat operation, preserving auto-save and provenance.
55
+ def build(template, seed:, anchor: nil, job: nil)
56
+ agent = clone_agent(template)
57
+ agent.save_file = anchor unless anchor.nil?
58
+ agent.job = job unless job.nil?
59
+ agent.start(chat_copy(seed))
60
+ agent
61
+ end
62
+ end
63
+ end
64
+ end