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.
- checksums.yaml +4 -4
- data/.vimproject +133 -58
- data/README.md +2 -1
- data/VERSION +1 -1
- data/doc/Improvements.md +490 -148
- data/doc/Model.md +53 -10
- data/doc/StartHere.md +44 -19
- data/doc/developer/Architecture.md +25 -6
- data/doc/developer/Backends.md +207 -48
- data/doc/developer/ChatLifecycle.md +121 -20
- data/doc/developer/DelegationInternals.md +319 -33
- data/doc/developer/DesignPrinciples.md +205 -16
- data/doc/developer/PathEngine.md +628 -0
- data/doc/developer/PromptProcessing.md +332 -82
- data/doc/developer/Provenance.md +388 -40
- data/doc/developer/Sandbox.md +213 -0
- data/doc/user/BuildingAgents.md +130 -18
- data/doc/user/Cookbook.md +29 -8
- data/doc/user/CoreConcepts.md +7 -6
- data/doc/user/Delegation.md +166 -15
- data/doc/user/GettingStarted.md +20 -16
- data/doc/user/ManagingContext.md +155 -17
- data/doc/user/MultiAgentWorkflows.md +105 -15
- data/doc/user/Python.md +11 -1
- data/doc/user/RunningInference.md +90 -47
- data/doc/user/ToolCalling.md +134 -29
- data/doc/user/WritingChats.md +56 -27
- data/lib/scout/llm/agent/attach.rb +13 -17
- data/lib/scout/llm/agent/chat.rb +32 -0
- data/lib/scout/llm/agent/construction.rb +64 -0
- data/lib/scout/llm/agent/conversation.rb +304 -0
- data/lib/scout/llm/agent/delegate.rb +56 -238
- data/lib/scout/llm/agent/path/edit.rb +230 -0
- data/lib/scout/llm/agent/path/patch.rb +252 -0
- data/lib/scout/llm/agent/path/workflow_kinds.rb +175 -0
- data/lib/scout/llm/agent/path.rb +1777 -0
- data/lib/scout/llm/agent/save.rb +11 -9
- data/lib/scout/llm/agent/workflow.rb +77 -16
- data/lib/scout/llm/agent.rb +147 -31
- data/lib/scout/llm/ask.rb +28 -17
- data/lib/scout/llm/backends/anthropic.rb +1 -1
- data/lib/scout/llm/backends/bedrock.rb +3 -2
- data/lib/scout/llm/backends/default.rb +127 -34
- data/lib/scout/llm/backends/glm.rb +28 -1
- data/lib/scout/llm/backends/huggingface.rb +1 -1
- data/lib/scout/llm/backends/ollama.rb +1 -1
- data/lib/scout/llm/backends/openai.rb +7 -6
- data/lib/scout/llm/backends/openwebui.rb +14 -7
- data/lib/scout/llm/backends/relay.rb +8 -2
- data/lib/scout/llm/chat/agent_meta.rb +24 -60
- data/lib/scout/llm/chat/parse.rb +1 -1
- data/lib/scout/llm/chat/process/files.rb +10 -0
- data/lib/scout/llm/chat/process/meta.rb +5 -7
- data/lib/scout/llm/chat/process/tools.rb +104 -49
- data/lib/scout/llm/chat/prompt/epoch_tool_compactation.rb +355 -0
- data/lib/scout/llm/chat/prompt/inbox.rb +188 -0
- data/lib/scout/llm/chat/prompt/shorten_tools.rb +797 -13
- data/lib/scout/llm/chat/prompt/shorten_tools_epoch.rb +1 -365
- data/lib/scout/llm/chat/prompt/shorten_tools_epoch_increment.rb +1 -0
- data/lib/scout/llm/chat/prompt.rb +24 -10
- data/lib/scout/llm/chat/provenance/live.rb +1080 -0
- data/lib/scout/llm/chat/provenance/tokens.rb +386 -0
- data/lib/scout/llm/chat/provenance.rb +343 -676
- data/lib/scout/llm/chat.rb +8 -2
- data/lib/scout/llm/embed.rb +15 -3
- data/lib/scout/llm/image.rb +4 -1
- data/lib/scout/llm/mcp.rb +4 -2
- data/lib/scout/llm/request_context.rb +234 -0
- data/lib/scout/llm/sandbox.rb +263 -0
- data/lib/scout/llm/tools/call.rb +163 -42
- data/lib/scout/llm/tools/definition.rb +48 -0
- data/lib/scout/llm/tools/knowledge_base.rb +1 -0
- data/lib/scout/llm/tools/mcp.rb +50 -43
- data/lib/scout/llm/tools/workflow.rb +90 -20
- data/lib/scout/llm/tools.rb +14 -41
- data/lib/scout/model/decision/base.rb +43 -0
- data/lib/scout/model/decision/jev.rb +161 -0
- data/lib/scout/model/python/torch.rb +1 -1
- data/research/clear-tools-inherit.md +171 -0
- data/research/path-engine-dc1-dc2-dc3-fixes.md +279 -0
- data/research/path-kind-chat-role.md +96 -0
- data/research/path-kind-contract-fixes-engine.md +307 -0
- data/research/scout-ai-runtime-availability.md +65 -0
- data/research/subsys/README.md +127 -0
- data/research/subsys/agent-delegation.md +201 -0
- data/research/subsys/agent-society.md +275 -0
- data/research/subsys/agentworkflow.md +233 -0
- data/research/subsys/backends.md +221 -0
- data/research/subsys/chat.md +314 -0
- data/research/subsys/embed-image.md +244 -0
- data/research/subsys/entry-cli.md +253 -0
- data/research/subsys/model-ml.md +326 -0
- data/research/subsys/provenance.md +290 -0
- data/research/subsys/tools.md +334 -0
- data/scout-ai.gemspec +71 -27
- data/scout_commands/agent/ask +8 -7
- data/scout_commands/llm/abridged +40 -0
- data/scout_commands/llm/ask +9 -9
- data/scout_commands/llm/md +2 -0
- data/scout_commands/llm/prov +724 -59
- data/scout_commands/llm/word +4 -0
- data/share/word/reference.docx +0 -0
- data/test/integration/scout/model/decision/test_jev.rb +144 -0
- data/test/scout/llm/agent/test_attach.rb +117 -0
- data/test/scout/llm/agent/test_conversation.rb +407 -0
- data/test/scout/llm/agent/test_delegate.rb +209 -0
- data/test/scout/llm/agent/test_path.rb +1812 -0
- data/test/scout/llm/agent/test_path_edit.rb +908 -0
- data/test/scout/llm/agent/test_path_errors.rb +390 -0
- data/test/scout/llm/agent/test_path_filesystem.rb +532 -0
- data/test/scout/llm/agent/test_path_patch.rb +233 -0
- data/test/scout/llm/agent/test_path_promotion.rb +386 -0
- data/test/scout/llm/agent/test_path_workflow_integration.rb +665 -0
- data/test/scout/llm/agent/test_save.rb +70 -15
- data/test/scout/llm/agent/test_workflow.rb +130 -4
- data/test/scout/llm/backends/test_anthropic.rb +4 -4
- data/test/scout/llm/backends/test_bedrock.rb +4 -4
- data/test/scout/llm/backends/test_format_other.rb +43 -0
- data/test/scout/llm/backends/test_ollama.rb +2 -2
- data/test/scout/llm/backends/test_openwebui.rb +12 -8
- data/test/scout/llm/backends/test_reasoning.rb +114 -0
- data/test/scout/llm/chat/agent_meta_fixtures.rb +28 -27
- data/test/scout/llm/chat/prompt/test_epoch_tool_compactation.rb +612 -0
- data/test/scout/llm/chat/prov_plot_fixtures.rb +131 -0
- data/test/scout/llm/chat/test_agent_meta.rb +40 -80
- data/test/scout/llm/chat/test_agent_meta_provenance.rb +67 -28
- data/test/scout/llm/chat/test_agent_meta_tokens.rb +59 -8
- data/test/scout/llm/chat/test_agent_view.rb +178 -0
- data/test/scout/llm/chat/test_live_report.rb +282 -0
- data/test/scout/llm/chat/test_live_workload.rb +193 -0
- data/test/scout/llm/chat/test_parse.rb +32 -2
- data/test/scout/llm/chat/test_prompt.rb +411 -0
- data/test/scout/llm/chat/test_prov_cli.rb +310 -15
- data/test/scout/llm/chat/test_prov_cli_live.rb +152 -0
- data/test/scout/llm/chat/test_prov_plot.rb +213 -0
- data/test/scout/llm/chat/test_prov_timeline.rb +355 -0
- data/test/scout/llm/chat/test_provenance.rb +67 -22
- data/test/scout/llm/chat/test_provenance_index.rb +479 -0
- data/test/scout/llm/chat/test_society_view.rb +159 -0
- data/test/scout/llm/test_agent.rb +1 -1
- data/test/scout/llm/test_embed.rb +103 -1
- data/test/scout/llm/test_request_context.rb +299 -0
- data/test/scout/llm/test_sandbox.rb +249 -0
- data/test/scout/llm/tools/test_agent_pairing.rb +150 -0
- data/test/scout/llm/tools/test_call_delegation_conflict.rb +316 -0
- data/test/scout/llm/tools/test_definition.rb +332 -0
- data/test/scout/llm/tools/test_jobs_file.rb +211 -0
- data/test/scout/llm/tools/test_mcp.rb +37 -8
- data/test/scout/llm/tools/test_workflow.rb +45 -1
- data/test/scout/model/decision/test_jev.rb +453 -0
- data/test/scout/model/python/huggingface/causal/test_next_token.rb +7 -10
- data/test/scout/model/python/huggingface/test_causal.rb +11 -2
- data/test/scout/model/python/huggingface/test_classification.rb +5 -3
- data/test/scout/model/python/test_availability.rb +116 -0
- data/test/scout/model/python/test_torch.rb +54 -2
- data/test/support/availability.rb +72 -174
- data/test/support/fake_clients.rb +18 -9
- data/test/support/fixtures.rb +75 -6
- data/test/support/mock_backend.rb +9 -1
- data/test/support/test_fixtures.rb +156 -0
- data/test/test_helper.rb +14 -4
- metadata +70 -26
- data/research/ChatAnalyst-required-changes.md +0 -167
- data/research/agent-delegation-analysis.md +0 -810
- data/research/agent-meta-provenance-integration-plan.md +0 -622
- data/research/agent-workflow-analysis.md +0 -1120
- data/research/backends-analysis.md +0 -836
- data/research/chat-core-analysis.md +0 -946
- data/research/chatanalyst-provenance/00-baseline.md +0 -30
- data/research/chatanalyst-provenance/01-repo-map.md +0 -60
- data/research/chatanalyst-provenance/02-event-reconstruction.md +0 -55
- data/research/chatanalyst-provenance/03-duplication-evidence.md +0 -45
- data/research/chatanalyst-provenance/04-tooling-root-cause.md +0 -57
- data/research/chatanalyst-provenance/05-fix-plan.md +0 -46
- data/research/chatanalyst-provenance/07-critic-review.md +0 -25
- data/research/chatanalyst-provenance/final-report.md +0 -45
- data/research/chatanalyst-provenance/resumption.md +0 -37
- data/research/coding-philosophy-analysis.md +0 -928
- data/research/commands-analysis.md +0 -947
- data/research/multi-agent-patterns-analysis.md +0 -853
- data/research/prompt-strategies-analysis.md +0 -630
- data/research/prov-verbosity-fix-notes.md +0 -77
- data/research/provenance-analysis.md +0 -469
- data/research/provenance-continuation-accounting.md +0 -255
- data/research/synthesis-report.md +0 -487
- data/research/tools-system-analysis.md +0 -779
data/doc/user/ToolCalling.md
CHANGED
|
@@ -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
|
-
|
|
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:`
|
|
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
|
-
|
|
40
|
-
|
|
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
|
|
67
|
+
tool: MyWorkflow my_task input1 input2=value1
|
|
46
68
|
```
|
|
47
69
|
|
|
48
|
-
This exposes only `my_task` from `MyWorkflow
|
|
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:
|
|
141
|
+
kb: my_kb genes proteins interactions
|
|
88
142
|
```
|
|
89
143
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
|
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/
|
|
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,
|
|
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
|
|
169
|
-
- The model
|
|
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
|
-
- **
|
|
178
|
-
`
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
- **
|
|
184
|
-
|
|
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
|
-
##
|
|
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.
|
data/doc/user/WritingChats.md
CHANGED
|
@@ -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
|
|
14
|
-
a blank line
|
|
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
|
|
79
|
-
|
|
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
|
-
- **
|
|
184
|
-
|
|
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
|
|
@@ -2,7 +2,7 @@ module LLM
|
|
|
2
2
|
class Agent
|
|
3
3
|
|
|
4
4
|
ATACH_TYPES = %w(auto image pdf png jpeg)
|
|
5
|
-
def attachments
|
|
5
|
+
def attachments(options = {})
|
|
6
6
|
@other_options[:tools] ||= {}
|
|
7
7
|
|
|
8
8
|
task_name = :attach
|
|
@@ -11,22 +11,28 @@ module LLM
|
|
|
11
11
|
path = Path.setup(parameters[:file]).find
|
|
12
12
|
raise ScoutException, "Path not found: #{path}" unless path.exists?
|
|
13
13
|
|
|
14
|
-
|
|
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
|
|
15
21
|
if file_type == 'auto' && path.get_extension.downcase == 'pdf'
|
|
16
22
|
file_type = 'pdf'
|
|
17
|
-
|
|
23
|
+
elsif file_type == 'auto'
|
|
18
24
|
file_type = 'image'
|
|
19
25
|
end
|
|
20
26
|
|
|
21
|
-
case
|
|
27
|
+
case file_type
|
|
22
28
|
when 'image', 'png', 'jpeg'
|
|
23
29
|
self.image path
|
|
24
30
|
when 'pdf'
|
|
25
31
|
self.pdf path
|
|
26
|
-
when 'auto'
|
|
27
32
|
else
|
|
28
33
|
raise ScoutException, "Unkown file type: #{parameters[:file_type]}"
|
|
29
34
|
end
|
|
35
|
+
"File attached."
|
|
30
36
|
rescue ScoutException => e
|
|
31
37
|
e
|
|
32
38
|
end
|
|
@@ -49,18 +55,8 @@ module LLM
|
|
|
49
55
|
Attach a file to the current chat, supports images and pdfs.
|
|
50
56
|
EOF
|
|
51
57
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
description: description,
|
|
55
|
-
parameters: {
|
|
56
|
-
type: 'object',
|
|
57
|
-
properties: properties,
|
|
58
|
-
required: [:file],
|
|
59
|
-
additionalProperties: false
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
definition = IndiferentHash.setup(function.merge(type: 'function', function: function))
|
|
58
|
+
definition = LLM.tool_definition(task_name, description, properties,
|
|
59
|
+
required: [:file])
|
|
64
60
|
@other_options[:tools][task_name] = [block, definition]
|
|
65
61
|
end
|
|
66
62
|
end
|
data/lib/scout/llm/agent/chat.rb
CHANGED
|
@@ -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
|