scout-ai 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.vimproject +135 -55
- data/README.md +2 -1
- data/VERSION +1 -1
- data/doc/Improvements.md +490 -148
- data/doc/Model.md +53 -10
- data/doc/StartHere.md +44 -19
- data/doc/developer/Architecture.md +25 -6
- data/doc/developer/Backends.md +207 -48
- data/doc/developer/ChatLifecycle.md +121 -20
- data/doc/developer/DelegationInternals.md +320 -34
- data/doc/developer/DesignPrinciples.md +205 -16
- data/doc/developer/PathEngine.md +628 -0
- data/doc/developer/PromptProcessing.md +332 -82
- data/doc/developer/Provenance.md +402 -44
- data/doc/developer/Sandbox.md +213 -0
- data/doc/user/BuildingAgents.md +130 -18
- data/doc/user/Cookbook.md +29 -8
- data/doc/user/CoreConcepts.md +7 -6
- data/doc/user/Delegation.md +166 -15
- data/doc/user/GettingStarted.md +20 -16
- data/doc/user/ManagingContext.md +155 -17
- data/doc/user/MultiAgentWorkflows.md +105 -15
- data/doc/user/Python.md +11 -1
- data/doc/user/RunningInference.md +90 -47
- data/doc/user/ToolCalling.md +134 -29
- data/doc/user/WritingChats.md +56 -27
- data/lib/scout/llm/agent/attach.rb +64 -0
- data/lib/scout/llm/agent/chat.rb +32 -0
- data/lib/scout/llm/agent/construction.rb +64 -0
- data/lib/scout/llm/agent/conversation.rb +304 -0
- data/lib/scout/llm/agent/delegate.rb +56 -238
- data/lib/scout/llm/agent/path/edit.rb +230 -0
- data/lib/scout/llm/agent/path/patch.rb +252 -0
- data/lib/scout/llm/agent/path/workflow_kinds.rb +175 -0
- data/lib/scout/llm/agent/path.rb +1777 -0
- data/lib/scout/llm/agent/save.rb +11 -9
- data/lib/scout/llm/agent/workflow.rb +79 -17
- data/lib/scout/llm/agent.rb +151 -27
- data/lib/scout/llm/ask.rb +37 -27
- data/lib/scout/llm/backends/anthropic.rb +1 -1
- data/lib/scout/llm/backends/bedrock.rb +3 -2
- data/lib/scout/llm/backends/default.rb +131 -32
- data/lib/scout/llm/backends/glm.rb +28 -1
- data/lib/scout/llm/backends/huggingface.rb +1 -1
- data/lib/scout/llm/backends/ollama.rb +1 -1
- data/lib/scout/llm/backends/openai.rb +7 -6
- data/lib/scout/llm/backends/openwebui.rb +14 -7
- data/lib/scout/llm/backends/relay.rb +8 -2
- data/lib/scout/llm/chat/agent_meta.rb +24 -60
- data/lib/scout/llm/chat/parse.rb +1 -1
- data/lib/scout/llm/chat/process/files.rb +10 -0
- data/lib/scout/llm/chat/process/meta.rb +5 -7
- data/lib/scout/llm/chat/process/tools.rb +104 -52
- data/lib/scout/llm/chat/prompt/epoch_tool_compactation.rb +355 -0
- data/lib/scout/llm/chat/prompt/inbox.rb +188 -0
- data/lib/scout/llm/chat/prompt/shorten_tools.rb +797 -13
- data/lib/scout/llm/chat/prompt/shorten_tools_epoch.rb +1 -365
- data/lib/scout/llm/chat/prompt/shorten_tools_epoch_increment.rb +1 -0
- data/lib/scout/llm/chat/prompt.rb +24 -10
- data/lib/scout/llm/chat/provenance/live.rb +1080 -0
- data/lib/scout/llm/chat/provenance/tokens.rb +386 -0
- data/lib/scout/llm/chat/provenance.rb +352 -626
- data/lib/scout/llm/chat.rb +8 -2
- data/lib/scout/llm/embed.rb +15 -3
- data/lib/scout/llm/image.rb +4 -1
- data/lib/scout/llm/mcp.rb +4 -2
- data/lib/scout/llm/request_context.rb +234 -0
- data/lib/scout/llm/sandbox.rb +263 -0
- data/lib/scout/llm/tools/call.rb +163 -42
- data/lib/scout/llm/tools/definition.rb +48 -0
- data/lib/scout/llm/tools/knowledge_base.rb +1 -0
- data/lib/scout/llm/tools/mcp.rb +50 -43
- data/lib/scout/llm/tools/workflow.rb +90 -20
- data/lib/scout/llm/tools.rb +14 -41
- data/lib/scout/model/decision/base.rb +43 -0
- data/lib/scout/model/decision/jev.rb +161 -0
- data/lib/scout/model/python/torch.rb +1 -1
- data/research/clear-tools-inherit.md +171 -0
- data/research/path-engine-dc1-dc2-dc3-fixes.md +279 -0
- data/research/path-kind-chat-role.md +96 -0
- data/research/path-kind-contract-fixes-engine.md +307 -0
- data/research/scout-ai-runtime-availability.md +65 -0
- data/research/subsys/README.md +127 -0
- data/research/subsys/agent-delegation.md +201 -0
- data/research/subsys/agent-society.md +275 -0
- data/research/subsys/agentworkflow.md +233 -0
- data/research/subsys/backends.md +221 -0
- data/research/subsys/chat.md +314 -0
- data/research/subsys/embed-image.md +244 -0
- data/research/subsys/entry-cli.md +253 -0
- data/research/subsys/model-ml.md +326 -0
- data/research/subsys/provenance.md +290 -0
- data/research/subsys/tools.md +334 -0
- data/scout-ai.gemspec +72 -26
- data/scout_commands/agent/ask +8 -7
- data/scout_commands/llm/abridged +40 -0
- data/scout_commands/llm/ask +9 -9
- data/scout_commands/llm/md +2 -0
- data/scout_commands/llm/prov +845 -80
- data/scout_commands/llm/word +4 -0
- data/share/word/reference.docx +0 -0
- data/test/integration/scout/model/decision/test_jev.rb +144 -0
- data/test/scout/llm/agent/test_attach.rb +117 -0
- data/test/scout/llm/agent/test_conversation.rb +407 -0
- data/test/scout/llm/agent/test_delegate.rb +209 -0
- data/test/scout/llm/agent/test_path.rb +1812 -0
- data/test/scout/llm/agent/test_path_edit.rb +908 -0
- data/test/scout/llm/agent/test_path_errors.rb +390 -0
- data/test/scout/llm/agent/test_path_filesystem.rb +532 -0
- data/test/scout/llm/agent/test_path_patch.rb +233 -0
- data/test/scout/llm/agent/test_path_promotion.rb +386 -0
- data/test/scout/llm/agent/test_path_workflow_integration.rb +665 -0
- data/test/scout/llm/agent/test_save.rb +70 -15
- data/test/scout/llm/agent/test_workflow.rb +130 -4
- data/test/scout/llm/backends/test_anthropic.rb +4 -4
- data/test/scout/llm/backends/test_bedrock.rb +4 -4
- data/test/scout/llm/backends/test_format_other.rb +43 -0
- data/test/scout/llm/backends/test_ollama.rb +2 -2
- data/test/scout/llm/backends/test_openwebui.rb +12 -8
- data/test/scout/llm/backends/test_reasoning.rb +114 -0
- data/test/scout/llm/chat/agent_meta_fixtures.rb +109 -22
- data/test/scout/llm/chat/prompt/test_epoch_tool_compactation.rb +612 -0
- data/test/scout/llm/chat/prov_plot_fixtures.rb +131 -0
- data/test/scout/llm/chat/test_agent_meta.rb +40 -80
- data/test/scout/llm/chat/test_agent_meta_provenance.rb +200 -28
- data/test/scout/llm/chat/test_agent_meta_tokens.rb +112 -7
- data/test/scout/llm/chat/test_agent_view.rb +178 -0
- data/test/scout/llm/chat/test_live_report.rb +282 -0
- data/test/scout/llm/chat/test_live_workload.rb +193 -0
- data/test/scout/llm/chat/test_parse.rb +32 -2
- data/test/scout/llm/chat/test_prompt.rb +411 -0
- data/test/scout/llm/chat/test_prov_cli.rb +708 -13
- data/test/scout/llm/chat/test_prov_cli_live.rb +152 -0
- data/test/scout/llm/chat/test_prov_plot.rb +213 -0
- data/test/scout/llm/chat/test_prov_timeline.rb +355 -0
- data/test/scout/llm/chat/test_provenance.rb +67 -22
- data/test/scout/llm/chat/test_provenance_index.rb +479 -0
- data/test/scout/llm/chat/test_society_view.rb +159 -0
- data/test/scout/llm/test_agent.rb +1 -1
- data/test/scout/llm/test_embed.rb +103 -1
- data/test/scout/llm/test_request_context.rb +299 -0
- data/test/scout/llm/test_sandbox.rb +249 -0
- data/test/scout/llm/tools/test_agent_pairing.rb +150 -0
- data/test/scout/llm/tools/test_call_delegation_conflict.rb +316 -0
- data/test/scout/llm/tools/test_definition.rb +332 -0
- data/test/scout/llm/tools/test_jobs_file.rb +211 -0
- data/test/scout/llm/tools/test_mcp.rb +37 -8
- data/test/scout/llm/tools/test_workflow.rb +45 -1
- data/test/scout/model/decision/test_jev.rb +453 -0
- data/test/scout/model/python/huggingface/causal/test_next_token.rb +7 -10
- data/test/scout/model/python/huggingface/test_causal.rb +11 -2
- data/test/scout/model/python/huggingface/test_classification.rb +5 -3
- data/test/scout/model/python/test_availability.rb +116 -0
- data/test/scout/model/python/test_torch.rb +54 -2
- data/test/support/availability.rb +72 -174
- data/test/support/fake_clients.rb +18 -9
- data/test/support/fixtures.rb +75 -6
- data/test/support/mock_backend.rb +9 -1
- data/test/support/test_fixtures.rb +156 -0
- data/test/test_helper.rb +14 -4
- metadata +71 -25
- data/research/ChatAnalyst-required-changes.md +0 -167
- data/research/agent-delegation-analysis.md +0 -810
- data/research/agent-meta-provenance-integration-plan.md +0 -622
- data/research/agent-workflow-analysis.md +0 -1120
- data/research/backends-analysis.md +0 -836
- data/research/chat-core-analysis.md +0 -946
- data/research/chatanalyst-provenance/00-baseline.md +0 -30
- data/research/chatanalyst-provenance/01-repo-map.md +0 -60
- data/research/chatanalyst-provenance/02-event-reconstruction.md +0 -55
- data/research/chatanalyst-provenance/03-duplication-evidence.md +0 -45
- data/research/chatanalyst-provenance/04-tooling-root-cause.md +0 -57
- data/research/chatanalyst-provenance/05-fix-plan.md +0 -46
- data/research/chatanalyst-provenance/07-critic-review.md +0 -25
- data/research/chatanalyst-provenance/final-report.md +0 -45
- data/research/chatanalyst-provenance/resumption.md +0 -37
- data/research/coding-philosophy-analysis.md +0 -928
- data/research/commands-analysis.md +0 -947
- data/research/multi-agent-patterns-analysis.md +0 -853
- data/research/prompt-strategies-analysis.md +0 -630
- data/research/prov-verbosity-fix-notes.md +0 -77
- data/research/provenance-analysis.md +0 -469
- data/research/synthesis-report.md +0 -487
- data/research/tools-system-analysis.md +0 -779
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
# 02 - Provenance, receipts and token accounting
|
|
2
|
+
|
|
3
|
+
> Investigation, not normative documentation. Verified behavior of the
|
|
4
|
+
> provenance traversal, agent_meta receipts, token-event deduplication, the
|
|
5
|
+
> live report and the `prov` CLI. Normative reference:
|
|
6
|
+
> `doc/developer/Provenance.md`.
|
|
7
|
+
|
|
8
|
+
## Scope
|
|
9
|
+
|
|
10
|
+
`lib/scout/llm/chat/provenance.rb` (1841 lines) and its immediate
|
|
11
|
+
collaborators: `chat/agent_meta.rb`, `chat/process/meta.rb` (tracing and
|
|
12
|
+
accounting helpers), `chat/tool_calls.rb` (receipt pairing),
|
|
13
|
+
`lib/scout/llm/tools/call.rb` (jobs sidecar + receipt writer),
|
|
14
|
+
`lib/scout/llm/agent/save.rb` (society layout) and `scout_commands/llm/prov`
|
|
15
|
+
(the renderer).
|
|
16
|
+
|
|
17
|
+
## Verified behavior
|
|
18
|
+
|
|
19
|
+
### Edge model
|
|
20
|
+
|
|
21
|
+
`PROVENANCE_RELATIONS = %i[job dependency log result agent_job]`
|
|
22
|
+
(provenance.rb:5).
|
|
23
|
+
|
|
24
|
+
| relation | parent -> child | producer | consumer |
|
|
25
|
+
|---|---|---|---|
|
|
26
|
+
| `job` | chat -> job | `meta: job=<short path>` written by `Agent#ask` at dispatch (agent.rb:85-88, before `job.produce`) | traversal `chat.jobs` |
|
|
27
|
+
| `agent_job` | chat -> job | `meta[].job` field of a receipt inside `function_call_output` JSON (writer `LLM.meta_receipt_from_messages`, tools/call.rb:37-50, 222) | `agent_meta_job_references` -> traversal queue |
|
|
28
|
+
| `dependency` | job -> job | Scout-gear Step `.info` `dependencies`, recorded at `reset_info(status: :setup)` after `run_dependencies` | traversal (provenance.rb:372-375) |
|
|
29
|
+
| `log` | job -> chat and chat -> chat | save machinery writing `<base>.files/*.chat` / `<base>.files/<name>.society/**/*.chat` | `direct_job_chat_files` / `direct_chat_sidecar_files` |
|
|
30
|
+
| `result` | job -> chat | `chat_task` writing the job result chat (`job.type == 'chat'`) | `job_result_chat_file` |
|
|
31
|
+
|
|
32
|
+
`delegated_result` is **not** a traversal relation - it is a rendering-only
|
|
33
|
+
reversal of `:agent_job` in the prov renderer. The `step` auxiliary field of
|
|
34
|
+
the tool-output envelope is never an edge source.
|
|
35
|
+
|
|
36
|
+
Log families: `DIRECT_LOG_CHAT_GLOBS = ['*.chat', '*.society/**/*.chat']`
|
|
37
|
+
(provenance.rb:20) - exactly two families. The legacy `.files/log/**` layout
|
|
38
|
+
is no longer read; `resets/` snapshots fall outside the globs and are
|
|
39
|
+
invisible to traversal. Root-copy asymmetry: the chat root excludes top-level
|
|
40
|
+
`<save>.files/*.chat`, while the job root includes its own top-level
|
|
41
|
+
`agent.chat`.
|
|
42
|
+
|
|
43
|
+
### Entry points and shapes
|
|
44
|
+
|
|
45
|
+
- `traverse_provenance(root, root_type:, follow:, on_error:, &block)` - BFS
|
|
46
|
+
queue yielding `kind, object, parent_kind, parent, relation, first_visit`
|
|
47
|
+
and, optionally, a 7th `detail` value. The 7-argument form is only yielded
|
|
48
|
+
when the block can receive it (`block.arity == -1 || >= 7`,
|
|
49
|
+
provenance.rb:279-283); it carries the full receipt record on `:agent_job`
|
|
50
|
+
edges. Without a block the method returns an `Enumerator`. Node identity is
|
|
51
|
+
`[kind, realpath]`, so a chat-typed job and its result chat sharing one path
|
|
52
|
+
collapse to one node per kind.
|
|
53
|
+
- `root_type` inference: `Step === root ? :job : :chat`; a bare path string
|
|
54
|
+
whose `Step.type` is `'chat'` still infers `:chat` (it carries a `.info`
|
|
55
|
+
declaring type chat); `root_type: :job` forces `Step.load` + job relations.
|
|
56
|
+
Unknown `follow` symbols raise `ParameterException`; `follow: []` yields
|
|
57
|
+
zero edges.
|
|
58
|
+
- `provenance_edges(root, **options)` returns flat edges
|
|
59
|
+
`{from:, to:, relation:, detail:}`; `:agent_job` edges carry the receipt
|
|
60
|
+
record under `detail:` (keys `agent_meta_index, call_id, evidence_address,
|
|
61
|
+
evidence, job, output_address, raw_entry, reference, tool_name`).
|
|
62
|
+
- `provenance_chat_files` / `provenance_jobs` are first-visit collectors;
|
|
63
|
+
`provenance(chat_file, prov = {})` is the legacy chat->chat Hash shim.
|
|
64
|
+
- `on_error` callback arity is exactly **5**
|
|
65
|
+
(`error, kind, object, relation, reference`). Only the block has the
|
|
66
|
+
optional 7th `detail` argument.
|
|
67
|
+
|
|
68
|
+
### Job reference resolution
|
|
69
|
+
|
|
70
|
+
- `load_job_reference` -> `Step.load(ref)` with `job_reference_fallback_bases`
|
|
71
|
+
tried when the literal path is absent (a candidate is a file or has an
|
|
72
|
+
`.info`). `resolve_job_reference` returns `[step, nil]` or `[nil, step]`;
|
|
73
|
+
unresolved `:agent_job` references are reported, never silently dropped.
|
|
74
|
+
- Live resolution (`load_live_job_reference`) tries `Workflow.directory`
|
|
75
|
+
**first** (because `Step.load` relocates a bare short path onto an empty
|
|
76
|
+
mirror of the jobs tree), then the absolute form, then `load_job_reference`.
|
|
77
|
+
Corollary: an observer must run in the directory that owns `var/jobs` or set
|
|
78
|
+
`Workflow.directory`; with the default PWD-relative tree, `--live` from
|
|
79
|
+
another cwd prints nothing and exits 0.
|
|
80
|
+
|
|
81
|
+
### Run-scoped parse-once cache
|
|
82
|
+
|
|
83
|
+
`Thread.current[:scout_ai_provenance_run_cache]` is opened by every public
|
|
84
|
+
entry point (`traverse_provenance`, `provenance_token_events`,
|
|
85
|
+
`provenance_token_totals`/`tokens`, and the collectors). One top-level call
|
|
86
|
+
parses each chat file once even when traversal and token collection both load
|
|
87
|
+
it; nested public calls reuse the outer cache.
|
|
88
|
+
|
|
89
|
+
### Token events and totals
|
|
90
|
+
|
|
91
|
+
`provenance_token_events(root, warnings:, strict:, **traversal_options)`:
|
|
92
|
+
|
|
93
|
+
- Sources: chat-side trace records with no `:job` and at least one
|
|
94
|
+
TOKEN_KEYS field -> `origin: :chat_meta`; receipt-side `agent_meta_evidence`
|
|
95
|
+
records with no `:job` and at least one field -> `origin: :agent_meta`. A
|
|
96
|
+
`job=` projection meta is never a token event.
|
|
97
|
+
- Identity priority: `inference_id` -> `provider_response_id` ->
|
|
98
|
+
`[:lineage, lineage_id]` (chat-side legacy) -> `[:receipt, evidence_address]`
|
|
99
|
+
(marked `receipt_unresolved`, never merged; documented possible overcount
|
|
100
|
+
for legacy receipt data).
|
|
101
|
+
- Canonical evidence: `origin_rank = {chat_meta: 0, agent_meta: 1}`, then
|
|
102
|
+
discovery order; tokens come only from the canonical record; all duplicate
|
|
103
|
+
evidence records are retained in `event[:evidence]`.
|
|
104
|
+
- Conflicts: disagreement on any TOKEN_KEYS value (as integers, missing = 0)
|
|
105
|
+
or on two different non-empty `provider_response_id`s -> `conflict: true`
|
|
106
|
+
plus one warning `{reason: :identity_conflict, ...}` per conflicting event;
|
|
107
|
+
`strict: true` raises `ScoutException` instead. Missing-vs-present
|
|
108
|
+
`provider_response_id` and missing optional `cct/cwt/rt` are
|
|
109
|
+
`incomplete_evidence: true` (counted, never warned).
|
|
110
|
+
- Warning routing: with a `warnings` Array, traversal-stage agent_meta
|
|
111
|
+
problems (malformed receipts, unresolved references) are routed into it with
|
|
112
|
+
a `message:` key while the traversal continues; unrelated errors still
|
|
113
|
+
raise. Without the Array, agent_meta problems raise exactly as in strict
|
|
114
|
+
traversal. The receipt-problem buffer is de-duplicated against
|
|
115
|
+
traversal-stage warnings on `[reason, output_address, agent_meta_index]`.
|
|
116
|
+
- `provenance_token_totals(root, scope:, warnings:, conflicts:, **opts)`
|
|
117
|
+
scopes: `:deduplicated_total` (default), `:chat_evidence`,
|
|
118
|
+
`:receipt_evidence`, `:receipt_only` (receipt evidence with no chat
|
|
119
|
+
evidence - the disjoint delegated contribution); unknown scope raises
|
|
120
|
+
`ParameterException`. The scopes are coverage, **not** a partition:
|
|
121
|
+
`chat_evidence` and `receipt_evidence` overlap and must not be summed.
|
|
122
|
+
`conflicts:` receives `events`, `incomplete_evidence_events`,
|
|
123
|
+
`authoritative` (true iff no conflicts).
|
|
124
|
+
- `Chat.tokens(root)` aliases `provenance_token_totals`.
|
|
125
|
+
- Checkpoint fields `*_c`/`*_s` are never read or summed here (a chat with
|
|
126
|
+
`pt=10` + `pt_c=999` totals 10).
|
|
127
|
+
- `USAGE_FIELD_MAP`/`normalize_usage` (process/meta.rb:23-71) map
|
|
128
|
+
OpenAI/GLM/Anthropic spellings to `pt/ct/tt/cct/cwt/rt`; only *wrapped*
|
|
129
|
+
`usage` hashes are normalized - a bare top-level token hash passes through.
|
|
130
|
+
|
|
131
|
+
### Receipts (agent_meta)
|
|
132
|
+
|
|
133
|
+
- Writer: `LLM.meta_receipt_from_messages` deserializes the child's `meta`
|
|
134
|
+
messages into plain field Hashes; entries parsing to no fields are dropped.
|
|
135
|
+
- Reader: one record per valid entry, `origin: :agent_meta`,
|
|
136
|
+
`evidence_address` suffix `[:meta, index]`, `raw_message` always nil.
|
|
137
|
+
- Only the current `meta` key is read; the legacy serialized `agent_meta` key
|
|
138
|
+
contributes no evidence and no warnings.
|
|
139
|
+
- Malformed taxonomy: `:not_an_array`, `:not_a_hash`, `:empty_meta` (plus
|
|
140
|
+
role/content-shape rejections) - skipped, never reinterpreted; only output
|
|
141
|
+
JSON parsing to a Hash with an explicit receipt key is inspected.
|
|
142
|
+
- Envelope auxiliary fields (`step`, `start_timestamp`, `timestamp`) are
|
|
143
|
+
bookkeeping; the sole receipt-driven edge source is `meta[].job`.
|
|
144
|
+
|
|
145
|
+
### Projection and tracing
|
|
146
|
+
|
|
147
|
+
`Chat.project(job, messages)` prepends exactly one `meta: job=<short path>`
|
|
148
|
+
marker, keeps response messages in order with per-inference metas inline, is
|
|
149
|
+
idempotent on re-projection, and strips `reas` unless
|
|
150
|
+
`chat.project.keep_reas`. Trace records carry `lineage_id`, `inference_id`,
|
|
151
|
+
`deduplication` (`:inference_id` / `:legacy_lineage`), `meta_address`,
|
|
152
|
+
covered lineage ids and message addresses, parsed meta and `orphan`; job
|
|
153
|
+
projection metas appear as `legacy_lineage` records with nil `inference_id`
|
|
154
|
+
and are excluded from token events by the `meta[:job]` filter. `orphan` is set
|
|
155
|
+
at meta-creation time by the backend for rounds whose output covers zero
|
|
156
|
+
messages; it is inert for accounting.
|
|
157
|
+
|
|
158
|
+
### Live report
|
|
159
|
+
|
|
160
|
+
`Chat.live_report(save_file, captured: [])` folds three passes and returns
|
|
161
|
+
`{entries:, scanned: {sidecar:, agent_view:, society:}}`:
|
|
162
|
+
|
|
163
|
+
- **Sidecar** - `live_workload(reference)` derives `<base>.jobs` via
|
|
164
|
+
`Chat.jobs_file` (trailing `.chat` stripped); an absent sidecar is `[]`.
|
|
165
|
+
Entries are newline-separated job short paths. Classification
|
|
166
|
+
`classify_live_job_info`: terminal status (`done|error|aborted|cleaned`) ->
|
|
167
|
+
`:finished`; non-terminal with a live pid (`/proc/<pid>` exists, not
|
|
168
|
+
zombie) -> `:running`; non-terminal with dead/absent pid -> `:crashed`;
|
|
169
|
+
unreadable/non-Hash -> `:unknown`/nil. The chat-task discriminator is
|
|
170
|
+
`step.type.to_s == 'chat'`. `expand_live_jobs` walks *direct* dependencies
|
|
171
|
+
(not `rec_dependencies`), cycle-guarded, `LIVE_DEPENDENCY_DEPTH_LIMIT = 5`,
|
|
172
|
+
collecting only `:running` jobs; `via:` records the sidecar entry that
|
|
173
|
+
reached the job.
|
|
174
|
+
- **Waiting-wrapper fallback** - `live_dependency_candidates`: when a step
|
|
175
|
+
has no recorded dependencies and no terminal status, glob
|
|
176
|
+
`<workflow namespace>/*/*.info` siblings for running jobs (`.info` files,
|
|
177
|
+
because a chat_task path is a file). The wrapper is then reported once as
|
|
178
|
+
workload context with `state: :waiting`.
|
|
179
|
+
- **Agent view** - `agent_log_activity(save_file)` classifies from trailing
|
|
180
|
+
messages, skipping `AGENT_CONTROL_ROLES`; verdicts `dispatched`,
|
|
181
|
+
`tool_round_in_flight` (function_call without output),
|
|
182
|
+
`next_round_pending` (function_call_output), `idle`, `no_messages`,
|
|
183
|
+
`unreadable`, `no_inference`. `dangling_agent_job_metas` reads the save
|
|
184
|
+
file's `job=` metas with the same `Chat#jobs` reader the forensic traversal
|
|
185
|
+
uses (not receipt-borne references) and follows each to a running job;
|
|
186
|
+
terminal or already-captured ids are not reported.
|
|
187
|
+
- **Society** - `society_dir_of` delegates to the `LLM::Agent` rules
|
|
188
|
+
(nested chat -> plain `society` sibling; root chat -> `<name>.society`
|
|
189
|
+
sibling). `society_agent_chats` scans for `agent.chat` files only, bounded
|
|
190
|
+
to `SOCIETY_SCAN_DEPTH_LIMIT = 128` levels, no symlinks, sorted.
|
|
191
|
+
`society_live` reports each child whole: `:dangling_job` when
|
|
192
|
+
workflow-backed, `:agent_activity` otherwise.
|
|
193
|
+
- **Folding** - entries keyed by job id (sidecar short path, the same form a
|
|
194
|
+
`job=` meta stores) or agent-log path; captured ids (normalized by
|
|
195
|
+
`live_captured_ids` from the forensic report's `:job`/`:agent_job` job
|
|
196
|
+
nodes) are dropped in every pass; two passes naming the same job deep-merge
|
|
197
|
+
with earlier scalar facts winning.
|
|
198
|
+
- **CLI `--live`** - the live section is appended after the normal report and
|
|
199
|
+
omitted entirely (header included) when there are no entries. Kinds are
|
|
200
|
+
relabelled `chat_task`/`dangling_job`/`agent_active`/`workflow`, inference
|
|
201
|
+
first. Live entries carry no token figures.
|
|
202
|
+
|
|
203
|
+
### prov CLI
|
|
204
|
+
|
|
205
|
+
- Root classification uses the `.info` sidecar only:
|
|
206
|
+
`Open.exists?(filename + '.info')` -> `Step.load` + `root_type: :job`, else
|
|
207
|
+
`Path.setup`.
|
|
208
|
+
- One traversal feeds nodes/edges/tokens/renderers; `captured_references`
|
|
209
|
+
for the live section are taken from that same traversal's
|
|
210
|
+
`:job`/`:agent_job` records, in both the Step path form and the raw string
|
|
211
|
+
form.
|
|
212
|
+
- Footer `root deduplicated_total=<tt> (<N> events) prompt=... cache=<abs>@<rate>%
|
|
213
|
+
fresh=... [cache_write=...] cont=... reason=...`; `--component` relabels
|
|
214
|
+
per-node numbers `direct=`; job nodes add `delta=`. Per-job deltas sum to
|
|
215
|
+
the root total on continuation chains but **not** on general DAGs - the
|
|
216
|
+
evidence closures of two parents overlap.
|
|
217
|
+
- `--evidence` prints per-event identity, raw values, evidence locations
|
|
218
|
+
(receipt addresses as `base:idx[meta,i]`) and statuses (`counted once`,
|
|
219
|
+
`receipt-only`, `legacy unresolved`, `conflict`), followed by
|
|
220
|
+
receipt-only / legacy-unresolved / identity-conflict / job-projection
|
|
221
|
+
sections and a trailing warnings block.
|
|
222
|
+
|
|
223
|
+
## Sharp edges and known issues
|
|
224
|
+
|
|
225
|
+
- **"Three log families" is two globs** (F22). `doc/developer/Provenance.md`
|
|
226
|
+
says the `log` relation covers three families and lists two; the third was
|
|
227
|
+
the legacy `.files/log/**` layout, no longer read.
|
|
228
|
+
- **The optional 7th `detail` yield is undocumented but load-bearing** (F22):
|
|
229
|
+
receipt-aware renderers depend on it; `provenance_edges` exposes it as
|
|
230
|
+
`detail:`.
|
|
231
|
+
- **`resets/` snapshots are invisible to traversal** (F22): outside the
|
|
232
|
+
globs, by construction.
|
|
233
|
+
- **Checkout-vs-gem trap** (F22, operational): the installed gem (2.0.0 at
|
|
234
|
+
study time; checkout 2.1.0) may lack checkout-only methods such as
|
|
235
|
+
`Chat.live_report`; running the checkout's `prov` without
|
|
236
|
+
`-I<checkout>/lib` raises NoMethodError. Pin the load path or `RUBYOPT`
|
|
237
|
+
when reproducing.
|
|
238
|
+
- **`--live` needs the owning cwd**: without `Workflow.directory` pointing at
|
|
239
|
+
the tree that owns `var/jobs`, sidecar entries resolve to nothing and the
|
|
240
|
+
command exits 0 silently.
|
|
241
|
+
- **Snapshot races are expected** (sidecar read vs `.info` read); `kill -9`
|
|
242
|
+
leaves `.info` non-terminal and only pid liveness rescues the
|
|
243
|
+
classification.
|
|
244
|
+
- **`Chat#jobs` returns raw reference strings verbatim**, including
|
|
245
|
+
`.chat`-suffixed chat-typed paths and non-existent paths; consumers must
|
|
246
|
+
resolve them.
|
|
247
|
+
- Prior artifacts describing write-before-produce / jobs-sidecar removal /
|
|
248
|
+
type-3 immediate `job=` metas as *recommendations* are history: all are
|
|
249
|
+
implemented (`Open.write(jobs_file, ...)` before `Workflow.produce`,
|
|
250
|
+
`Open.rm jobs_file` in `ensure`, and the meta written at dispatch).
|
|
251
|
+
|
|
252
|
+
## Open questions
|
|
253
|
+
|
|
254
|
+
- Exec-dispatched children (`exec_export`) and fork-vs-exec `.info` latency
|
|
255
|
+
are marked NEEDS-LIVE-PROBE; measuring them requires a real running
|
|
256
|
+
workflow.
|
|
257
|
+
- Live cost attribution is deferred by design until a backend reports usage
|
|
258
|
+
in flight.
|
|
259
|
+
- Whether ChatAnalyst consumes the receipt primitives (documented as pending
|
|
260
|
+
in Provenance.md) is outside this subsystem.
|
|
261
|
+
- Emergency backend snapshots (failed requests) are not under any Step's
|
|
262
|
+
files dir; if that ever changes, traversal picks them up automatically.
|
|
263
|
+
|
|
264
|
+
## Evidence
|
|
265
|
+
|
|
266
|
+
Provenance: derived from the 2026-09-10/11 Cortex subsystem studies, probed
|
|
267
|
+
against this checkout at HEAD `a992a33` plus the uncommitted 2026-09-11 fix
|
|
268
|
+
sweep (attach/MCP/embed/torch); no fix in this sweep touches this subsystem.
|
|
269
|
+
|
|
270
|
+
- Code: `lib/scout/llm/chat/provenance.rb` (1841 lines; constants at :5 and
|
|
271
|
+
:20, `LIVE_DEPENDENCY_DEPTH_LIMIT` :1109, `SOCIETY_SCAN_DEPTH_LIMIT`
|
|
272
|
+
:1683), `chat/agent_meta.rb`, `chat/tool_calls.rb`,
|
|
273
|
+
`chat/process/meta.rb`, `lib/scout/llm/tools/call.rb:124-193`
|
|
274
|
+
(jobs sidecar, agent fan-out), `lib/scout/llm/agent/save.rb`,
|
|
275
|
+
`lib/scout/llm/agent/workflow.rb` (`chat_task`),
|
|
276
|
+
`lib/scout/llm/backends/default.rb:415-448,540-602`,
|
|
277
|
+
`scout_commands/llm/prov`.
|
|
278
|
+
- Docs: `doc/developer/Provenance.md`, `doc/developer/Architecture.md`,
|
|
279
|
+
`doc/developer/ChatLifecycle.md` (meta grammar, `*_c`/`*_s` checkpoints).
|
|
280
|
+
- Probes: 26 offline scripts on synthetic fixtures under `Dir.mktmpdir`
|
|
281
|
+
(`tmp/subsys-provenance/probe1_traversal.rb` ...
|
|
282
|
+
`probe26_malformed.rb`), each printing a JSON verdict. Representative
|
|
283
|
+
findings: traversal arity and root-type inference; `detail` key set of
|
|
284
|
+
`:agent_job` edges; run-cache parse counts; scope overlap demonstrated
|
|
285
|
+
numerically (`chat_evidence` + `receipt_evidence` both 165 for an event
|
|
286
|
+
with chat-side canonical evidence, `receipt_only` 0); `classify_live_job_info`
|
|
287
|
+
verdict table; `agent_log_activity` verdict table; receipt-envelope
|
|
288
|
+
variants (`meta` absent / not-an-array / empty entry / legacy
|
|
289
|
+
`agent_meta` key -> 0 events, 0 warnings); wrapped-vs-bare usage hash
|
|
290
|
+
normalization.
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
# 05 - Tool definitions, dispatch and MCP
|
|
2
|
+
|
|
3
|
+
> Investigation, not normative documentation. Verified behavior of the tool
|
|
4
|
+
> registry, the four executor kinds, definition construction, the
|
|
5
|
+
> `function_call_output` envelope, knowledge-base tools and both halves of
|
|
6
|
+
> MCP. Normative reference: `doc/user/ToolCalling.md`, `doc/user/Cookbook.md`.
|
|
7
|
+
|
|
8
|
+
## Scope
|
|
9
|
+
|
|
10
|
+
`lib/scout/llm/tools.rb`, `lib/scout/llm/tools/{definition,workflow,
|
|
11
|
+
knowledge_base,mcp,call}.rb`, the chat-message compilers in
|
|
12
|
+
`lib/scout/llm/chat/process/tools.rb`, and the serving side
|
|
13
|
+
`lib/scout/llm/mcp.rb`.
|
|
14
|
+
|
|
15
|
+
## Verified behavior
|
|
16
|
+
|
|
17
|
+
### Registry shape and dispatch
|
|
18
|
+
|
|
19
|
+
The canonical registry is a plain `{name => [executor, definition]}` Hash
|
|
20
|
+
(`tools/call.rb:96`). `LLM.process_calls` dispatches four executor kinds:
|
|
21
|
+
|
|
22
|
+
| executor | dispatch | returns |
|
|
23
|
+
|---|---|---|
|
|
24
|
+
| `Proc` | `obj.call(function_name, function_arguments)` | immediate value |
|
|
25
|
+
| `String` | `const_get` if a constant, else `Workflow.require_workflow(obj)`, then `call_workflow` | job/step |
|
|
26
|
+
| `Workflow` module | `call_workflow(obj, ...)` | job/step |
|
|
27
|
+
| `KnowledgeBase` | `call_knowledge_base(obj, ...)` | association list / details hash |
|
|
28
|
+
|
|
29
|
+
An unknown name with no block *creates* a `ParameterException` and returns it
|
|
30
|
+
as the content (not raised) - it surfaces as `error: "error"` in the envelope.
|
|
31
|
+
With a block given to `process_calls`, the block is tried first. A registry
|
|
32
|
+
value that is a bare Hash (executor slot dropped) makes the content the
|
|
33
|
+
definition hash itself. `nil` Proc results become the literal string
|
|
34
|
+
`"success"`; Numeric results are stringified.
|
|
35
|
+
|
|
36
|
+
### Definition construction
|
|
37
|
+
|
|
38
|
+
`LLM.tool_definition(name, description, properties, required: nil,
|
|
39
|
+
defaults: nil, strict: true, envelope: true)`:
|
|
40
|
+
|
|
41
|
+
- `envelope: true` (default) wraps into `{type: 'function', function:
|
|
42
|
+
{name:, description:, parameters:}}` - used by the agent layer and the MCP
|
|
43
|
+
client definitions. `envelope: false` produces the bare hash - used by
|
|
44
|
+
`task_tool_definition`; the backend's `format_tool_definitions` then
|
|
45
|
+
flattens `definition[:function]` and strips `parameters[:defaults]`.
|
|
46
|
+
- `strict: true` emits `parameters[:additionalProperties] = false`.
|
|
47
|
+
- `defaults` is a replay side-channel: emitted as `parameters[:defaults]`
|
|
48
|
+
only when truthy, and merged into the call arguments in `process_calls`
|
|
49
|
+
**before** execution.
|
|
50
|
+
|
|
51
|
+
**Defaults merge precedence is `function_arguments.merge(defaults)`** - the
|
|
52
|
+
definition defaults *override* the model-supplied arguments (F10), and
|
|
53
|
+
`tool: WF task name=X` both pre-fills and *hides* the input.
|
|
54
|
+
|
|
55
|
+
### Workflow tools
|
|
56
|
+
|
|
57
|
+
`LLM.workflow_tools(workflow, tasks = nil)`:
|
|
58
|
+
|
|
59
|
+
- `tasks.nil?` -> `workflow.all_exports`; if empty **and** `all_tasks`
|
|
60
|
+
exists, all tasks.
|
|
61
|
+
- `Array === workflow` merges each workflow's tools in order; **later
|
|
62
|
+
workflows overwrite earlier ones on name collision** (the registry key is
|
|
63
|
+
the task name only).
|
|
64
|
+
- Returns `{task_name(Symbol) => [workflow, definition]}`. A task whose
|
|
65
|
+
`task_info` returns `nil` is skipped; an *unknown* task name raises
|
|
66
|
+
`RuntimeError` from `task_info` itself.
|
|
67
|
+
|
|
68
|
+
`LLM.task_tool_definition(workflow, task_name, inputs = nil)`:
|
|
69
|
+
|
|
70
|
+
- Type mapping `scout_to_tool_input_type` (workflow.rb:3-11) is
|
|
71
|
+
**symbol-keyed** and covers only `:chat`/`:text`/`:select`/`:path` ->
|
|
72
|
+
`:string`, `:float` -> `:number`, and any `*_array` -> `:array`. String
|
|
73
|
+
type names pass through unchanged, and **`:boolean`, `:integer`, `:json`
|
|
74
|
+
and `:file` are not in the map** - they pass through as symbols rather
|
|
75
|
+
than `"boolean"`/`"number"`/`"string"`.
|
|
76
|
+
- `input_options[:select_options]` -> `"enum"` on the property (Hash values
|
|
77
|
+
unwrapped).
|
|
78
|
+
- `required` = only inputs whose `input_options` carry `required: true`.
|
|
79
|
+
- The `inputs` restriction list: bare names restrict which properties are
|
|
80
|
+
emitted; `name=value` tokens become definition defaults that pre-fill
|
|
81
|
+
**and hide** the input.
|
|
82
|
+
- The `return_path` property is appended only for non-`exec_exports` tasks.
|
|
83
|
+
|
|
84
|
+
`LLM.call_workflow(workflow, task_name, parameters)`
|
|
85
|
+
(tools/workflow.rb:75-115): builds `workflow.job(...)`; then exec export or
|
|
86
|
+
exec type -> `job.exec`, returning the result value directly (no Step);
|
|
87
|
+
`return_path` truthy -> `job.run(true)` + `Chat.allow_read_job(job)`,
|
|
88
|
+
returns the job path String; default -> returns the **Step**. The
|
|
89
|
+
recursive-call guard raises `ScoutException 'Potential recursive call'`
|
|
90
|
+
when the job is already running in this pid and `allow_recursive != 'true'`
|
|
91
|
+
(workflow.rb:106); the method-level `rescue ScoutException` **returns the
|
|
92
|
+
exception object** instead of raising.
|
|
93
|
+
|
|
94
|
+
### Knowledge base tools
|
|
95
|
+
|
|
96
|
+
`LLM.knowledge_base_tool_definition(kb, databases = nil)` - one *association*
|
|
97
|
+
tool per database plus, **only when the database has fields** (3-column
|
|
98
|
+
source), a `<db>_association_details` tool; two-column databases expose only
|
|
99
|
+
the association tool.
|
|
100
|
+
|
|
101
|
+
- Association tool: directed -> `entities` (array of string; "Source
|
|
102
|
+
entities in the association, or target entities if reverse is true") +
|
|
103
|
+
`reverse` (boolean); `undirected:` -> only `entities`, description mentions
|
|
104
|
+
the `entity~partner` output. The KB-registered `description:` is embedded
|
|
105
|
+
when present.
|
|
106
|
+
- Details tool: >1 fields -> `associations` + `fields` (array, "Limit the
|
|
107
|
+
response to these fields"), description lists field names and notes `;`
|
|
108
|
+
multi-values; exactly 1 field -> `fields` deleted; 0 fields -> tool not
|
|
109
|
+
generated.
|
|
110
|
+
|
|
111
|
+
`LLM.call_knowledge_base(kb, database, parameters)`:
|
|
112
|
+
|
|
113
|
+
- `<db>_association_details` -> strips the suffix, reads `kb.get_index(db)`;
|
|
114
|
+
with `fields` -> `values.values_at(*field_pos)`; without -> the full Hash
|
|
115
|
+
keyed by field name. Missing associations are skipped.
|
|
116
|
+
- Plain database -> `entities` (a JSON string is parsed) + `reverse` ->
|
|
117
|
+
`kb.parents` / `kb.children`, returning `source~target` entries.
|
|
118
|
+
- **No argument validation**: unknown field names raise inside
|
|
119
|
+
`identify_field`; empty/missing `entities` flows into the KB.
|
|
120
|
+
- `reverse` results depend on KB registration flags (`undirected`, `key`),
|
|
121
|
+
not on the tool layer; `kb.parents` is target-side, `kb.children`
|
|
122
|
+
source-side, and for a directed database `parents` is not simply the
|
|
123
|
+
inverse of `children`.
|
|
124
|
+
|
|
125
|
+
### MCP - two independent halves
|
|
126
|
+
|
|
127
|
+
**(a) Client side, `LLM.mcp_tools` (tools/mcp.rb)**: consumes an external
|
|
128
|
+
MCP server and produces `{tool_name => [Proc, definition]}`.
|
|
129
|
+
|
|
130
|
+
- `url == 'stdio'` -> `MCPClient.create_client(mcp_server_configs:
|
|
131
|
+
[options.merge(type: 'stdio')])`; the chat compiler passes `command:` plus
|
|
132
|
+
the remaining tokens. **Every token after the command is a tool-name
|
|
133
|
+
selection filter, not a command argument** (`mcp: stdio echo x` selects
|
|
134
|
+
tools named `x`).
|
|
135
|
+
- Remote URL: effective merge `options.merge(type: 'http', transport:
|
|
136
|
+
:streamable_http)` via `MCPClient.connect(url, **options)`. The `type:`
|
|
137
|
+
computed from `Open.remote?(url)` is overwritten by the literal `'http'`,
|
|
138
|
+
and `connect` dials eagerly - an unreachable URL raises at `mcp_tools`
|
|
139
|
+
construction time rather than at first tool call.
|
|
140
|
+
- Bearer token: `LLM.get_url_config(:key, url, :mcp)` ->
|
|
141
|
+
`options[:headers]['Authorization'] = "Bearer #{token}"` (set even when
|
|
142
|
+
empty). `read_timeout` from `Scout::Config.get(:timeout, :mcp, :tools)`.
|
|
143
|
+
- Each server tool becomes a **double-wrapped** definition: both a top-level
|
|
144
|
+
`name/description/parameters` and a `function` envelope holding the same
|
|
145
|
+
Hash. `backends/default.rb`'s flatten path handles it, so the
|
|
146
|
+
provider-visible shape ends up flat.
|
|
147
|
+
- The executor Proc calls `tool.server.call_tool(name, params)` and unwraps
|
|
148
|
+
`res['content']` -> array -> `.first` -> `['content']`/`['text']`.
|
|
149
|
+
|
|
150
|
+
**(b) Server side, `Workflow#mcp` (mcp.rb)**: serves a workflow's tasks as
|
|
151
|
+
MCP tools over a `StdioTransport`. Current behavior (fixed 2026-09-11,
|
|
152
|
+
uncommitted): the block is `do |server_context: nil, **parameters|` capturing
|
|
153
|
+
`workflow = self` and `task_name = task.to_s` in locals, returning
|
|
154
|
+
`MCP::Tool::Response.new([{type: 'text', text:
|
|
155
|
+
workflow.job(task_name, parameters).run.to_s}])`. Tool names are Strings so
|
|
156
|
+
the JSON-RPC lookup matches. Annotations are hard-coded
|
|
157
|
+
(`read_only_hint/destructive_hint/idempotent_hint/open_world_hint` = true /
|
|
158
|
+
false / true / false); the served input schema is
|
|
159
|
+
`tool_definition[:parameters].slice(:properties, :required)`, so the
|
|
160
|
+
`return_path` boolean survives into it. Results are coerced with `.to_s`
|
|
161
|
+
into a single text item; `structuredContent` is never produced, `nil`
|
|
162
|
+
becomes the empty string, and job failures surface as JSON-RPC `-32603
|
|
163
|
+
Internal error calling tool <name>: <msg>`.
|
|
164
|
+
|
|
165
|
+
Before the fix (F2) every served call failed with `Internal error`: the
|
|
166
|
+
block declared two positional parameters while the `mcp` gem invokes
|
|
167
|
+
`tool.call(**args)`, `self` inside `MCP::Tool.define`'s `Class.new` block
|
|
168
|
+
was the anonymous tool class rather than the Workflow module, the return
|
|
169
|
+
value was not an `MCP::Tool::Response`, and Symbol tool names missed the
|
|
170
|
+
String JSON-RPC lookup. The fixed contract is stable across `mcp` 1.1.0 and
|
|
171
|
+
1.5.1 (`call_tool_with_args` still dispatches `tool.call(**args,
|
|
172
|
+
server_context:)` when `accepts_server_context?` matches a `:keyrest` or a
|
|
173
|
+
literal `server_context` key); older positional-invocation releases are
|
|
174
|
+
deliberately unsupported. `mcp` is not a declared runtime dependency (the
|
|
175
|
+
gemspec lists only `ruby-mcp-client`, the client gem), so the supported
|
|
176
|
+
range is undefined upstream.
|
|
177
|
+
|
|
178
|
+
### Result shaping
|
|
179
|
+
|
|
180
|
+
Each call emits a **pair**: `{role: 'function_call', content: <tool-call
|
|
181
|
+
json>}` (normalized: `call_id` renamed to `id`, name at top level,
|
|
182
|
+
`function` envelope preserved when present) plus `{role:
|
|
183
|
+
'function_call_output', content: <response json>}` with fields `name`,
|
|
184
|
+
`content`, `id`, plus `error`, `stack`, `meta`, `step`, `start_timestamp`,
|
|
185
|
+
`timestamp` when applicable (`start_timestamp` once per round, `timestamp`
|
|
186
|
+
per output).
|
|
187
|
+
|
|
188
|
+
Special executor results:
|
|
189
|
+
|
|
190
|
+
- **`Step`**: done -> `content.load`; `error?` with an exception ->
|
|
191
|
+
`error: :error` + `{exception: ...}` JSON; otherwise -> `content.run`
|
|
192
|
+
inside begin/rescue; `step: step.short_path` added to the envelope. All
|
|
193
|
+
Step-producing calls are batched through `Workflow.produce` with the
|
|
194
|
+
transient `<save_file>.jobs` sidecar, rewritten per round and removed in
|
|
195
|
+
`ensure` (success and error).
|
|
196
|
+
- **`LLM::Agent`**: collected and `chat(return_messages: true)`'d in
|
|
197
|
+
parallel (`Open.traverse`, cpus config `:agent_ask`/`:agents`, env
|
|
198
|
+
`ASK_AGENTS`, default 3), then per agent-returning call
|
|
199
|
+
`Chat.allow_read_job`, `content.current_chat.follow(res)`,
|
|
200
|
+
`meta = LLM.meta_receipt_from_messages(Chat.find_role(res, :meta))`,
|
|
201
|
+
`content = content.answer`. Pairing is by tool-call position.
|
|
202
|
+
- **`Exception`** (returned, not raised): `error: :error` +
|
|
203
|
+
`{exception: msg, exception_line: first}`.
|
|
204
|
+
- **Hash with exactly `content`+`meta`**: content-with-inference-meta; `meta`
|
|
205
|
+
passes through verbatim as the deserialized receipt array.
|
|
206
|
+
- Other Hash -> `to_json`; `TSV` -> `to_s`; `IO`/`TSV::Dumper` -> `.read`;
|
|
207
|
+
anything else -> `to_json` with a `to_s` fallback.
|
|
208
|
+
- **Truncation**: String content longer than `LLM.max_content_length`
|
|
209
|
+
(config `max_content_length`, tokens `:llm_tools,:tools,:llm,:ask`,
|
|
210
|
+
default 100_000) is replaced by an exception JSON carrying a
|
|
211
|
+
`Log.fingerprint` of the content and `error: :truncated`; with a Step
|
|
212
|
+
attached the message points at `step.path` (tools/call.rb:10, 257-258).
|
|
213
|
+
|
|
214
|
+
Error taxonomy on the envelope's `error` key: `:error` (executor/step
|
|
215
|
+
exception), `:truncated`, `:scout` (`ScoutException` during shaping),
|
|
216
|
+
`:harness` (any other shaping failure).
|
|
217
|
+
|
|
218
|
+
### Chat-message compilation
|
|
219
|
+
|
|
220
|
+
`Chat.tools(messages)` mutates the array in place, removing and replacing
|
|
221
|
+
tooling roles:
|
|
222
|
+
|
|
223
|
+
- `tool: WF [task [inputs...]]` -> `LLM.workflow_tools(workflow, [task,
|
|
224
|
+
*inputs])`; a bare workflow name exposes all exports; `none`/`noinputs` as
|
|
225
|
+
the sole token restricts the schema to just `return_path`.
|
|
226
|
+
- `introduce: WF` -> **documentation only**: replaced by a `user:` message
|
|
227
|
+
with the workflow's title+description; generates **zero** tools;
|
|
228
|
+
deduplicated per workflow name. Whole-workflow tooling requires a bare
|
|
229
|
+
`tool: MyWorkflow`.
|
|
230
|
+
- `mcp: <url|stdio> [tool names...]` -> `LLM.mcp_tools`; named tools select
|
|
231
|
+
a subset, a nonexistent name silently yields a `nil` registry entry, and
|
|
232
|
+
the bracket syntax `[a b]` shown in the docs is not special - brackets
|
|
233
|
+
become part of the tool name.
|
|
234
|
+
- `kb: <kb-path-or-agent-name> [databases...]` -> `KnowledgeBase.load`; an
|
|
235
|
+
empty KB falls back to `LLM.load_agent(name).knowledge_base`; no matching
|
|
236
|
+
agent raises `ScoutException "No agent found with name <path>"`.
|
|
237
|
+
- `clear_tools:` resets the accumulated registry to `{}`.
|
|
238
|
+
- `Chat.associations` (separate pass): `association: <name> <path>
|
|
239
|
+
key=value...` registers a database inline into a KB rooted at
|
|
240
|
+
`Scout.var.Agent.Chat.knowledge_base` and emits only that database's
|
|
241
|
+
tools; `clear_associations:` resets. `Chat.tooling` selects
|
|
242
|
+
`[:introduce, :tool, :mcp, :kb]` - it does **not** include `association`,
|
|
243
|
+
which `AgentWorkflow#tooling` also does not harvest.
|
|
244
|
+
|
|
245
|
+
`task:`/`inline_task:`/`exec_task:` share the file but are chat-context
|
|
246
|
+
constructs: they run a workflow job eagerly (`exec_task` inlines the result
|
|
247
|
+
as a `user:` message; the others leave a `job:`/`inline_job:` path message
|
|
248
|
+
and `Workflow.produce` the collected jobs).
|
|
249
|
+
|
|
250
|
+
### Agent auto-wiring
|
|
251
|
+
|
|
252
|
+
`Agent#chat` assembles `options[:tools] || {}`, merged with
|
|
253
|
+
`@other_options[:tools]` (JSON-parsed when a String), then
|
|
254
|
+
`LLM.workflow_tools(workflow)` when the agent has a workflow with tasks, and
|
|
255
|
+
the KB tools when it has a KB with databases. `AgentWorkflow#tooling`
|
|
256
|
+
harvests `tool:`/`kb:`/`mcp:`/`introduce:` messages out of the job chat and
|
|
257
|
+
follows them into the spawned agent's `start_chat`.
|
|
258
|
+
|
|
259
|
+
### Legacy entry points
|
|
260
|
+
|
|
261
|
+
`LLM.call_tools` / `LLM.tool_response` are a simpler registry-less path (no
|
|
262
|
+
lookup, no defaults merge, no Step/Agent handling); used only by
|
|
263
|
+
`backends/bedrock.rb`. `LLM.run_tools(messages)` converts legacy `cmd:`
|
|
264
|
+
messages into `tool:` messages by running the command. `LLM.ask_knowledge_base`
|
|
265
|
+
builds a block-dispatched `children` lookup and rewrites `~` to `=>` - a
|
|
266
|
+
different output convention from `call_knowledge_base`.
|
|
267
|
+
|
|
268
|
+
## Sharp edges and known issues
|
|
269
|
+
|
|
270
|
+
- **`introduce:` generates zero tools** (F4, open): ToolCalling.md claims it
|
|
271
|
+
auto-generates a tool definition per task; it is documentation injection
|
|
272
|
+
only. Affects every consumer relying on it, including prepared briefs.
|
|
273
|
+
- **Definition defaults override model arguments and hide inputs** (F10,
|
|
274
|
+
open). Whether "pre-fill" should mean "apply only when the model omits the
|
|
275
|
+
input" is an open semantic decision.
|
|
276
|
+
- **Symbol-named KB databases break the tool layer on reload** (F15, open):
|
|
277
|
+
`register(:name, ...)` + `save` round-trips the registry YAML with symbol
|
|
278
|
+
keys and `get_database('name')` does a string-keyed lookup ->
|
|
279
|
+
`RuntimeError "Repo brothers not found and not registered"`. A
|
|
280
|
+
scout-gear/scout-ai boundary trap; register with String names.
|
|
281
|
+
- **`:boolean`/`:integer`/`:json` tool inputs pass through the type map
|
|
282
|
+
unnormalized** (open); whether any provider rejects the symbol needs a
|
|
283
|
+
live call.
|
|
284
|
+
- **MCP client definitions are double-wrapped** (open): handled by the
|
|
285
|
+
shared flatten path, but per-backend handling was not probed.
|
|
286
|
+
- Hard-coded serving annotations and the `return_path` boolean leaking into
|
|
287
|
+
the served schema (recorded, not fixed).
|
|
288
|
+
- `LLM.max_content_length` config tokens are not surfaced in any doc.
|
|
289
|
+
- **Fixed 2026-09-11, uncommitted:** F2 - MCP serving broken against `mcp`
|
|
290
|
+
gem 1.1.0; fixed in `lib/scout/llm/mcp.rb` with
|
|
291
|
+
`test/scout/llm/tools/test_mcp.rb` (3/0) and re-verified on 1.5.1. During
|
|
292
|
+
the fix a stray unauthorized `scout_to_tool_input_type` edit in
|
|
293
|
+
`tools/workflow.rb` was made and reverted; HEAD semantics are restored.
|
|
294
|
+
- **Client-side transport edit pending owner review**: the working tree
|
|
295
|
+
carries an unattributed `lib/scout/llm/tools/mcp.rb` edit (`:http ->
|
|
296
|
+
:https` default plus `MCPClient.connect` instead of `create_client`). It
|
|
297
|
+
is not required for compatibility with `ruby-mcp-client` 2.1.0 (the old
|
|
298
|
+
`create_client` API still constructs `MCPClient::ServerHTTP` on that gem,
|
|
299
|
+
and streamable HTTP was already reachable via
|
|
300
|
+
`create_client(type: 'streamable_http')`), and it changes observable
|
|
301
|
+
behaviour (transport class, eager connection). Kept in place and flagged.
|
|
302
|
+
|
|
303
|
+
## Open questions
|
|
304
|
+
|
|
305
|
+
- Should defaults apply only when the model omits the input (F10)?
|
|
306
|
+
- Whether `association:` roles should propagate to delegated agents.
|
|
307
|
+
- The interaction of `task:`/`inline_task:`/`exec_task:` with a `tool:` role
|
|
308
|
+
naming the same workflow is untested.
|
|
309
|
+
- The supported `mcp` gem version range (server side).
|
|
310
|
+
|
|
311
|
+
## Evidence
|
|
312
|
+
|
|
313
|
+
Provenance: derived from the 2026-09-10/11 Cortex subsystem studies, probed
|
|
314
|
+
against this checkout at HEAD `a992a33` plus the uncommitted 2026-09-11 fix
|
|
315
|
+
sweep. The MCP serving fix (F2) is in scope here and is described as current
|
|
316
|
+
behavior above.
|
|
317
|
+
|
|
318
|
+
- Code: `lib/scout/llm/tools/call.rb`; `tools/workflow.rb:3-14` (type map),
|
|
319
|
+
`:20-33` (input restriction/defaults), `:53-68`, `:75-115`;
|
|
320
|
+
`tools/knowledge_base.rb`; `tools/mcp.rb` (client); `tools/definition.rb`;
|
|
321
|
+
`lib/scout/llm/tools.rb` (legacy); `lib/scout/llm/mcp.rb` (server, current
|
|
322
|
+
fixed form); `lib/scout/llm/chat/process/tools.rb`;
|
|
323
|
+
`lib/scout/llm/backends/default.rb:216-236`.
|
|
324
|
+
- Gem cross-reference: `mcp-1.1.0/lib/mcp/server.rb:1048-1074`,
|
|
325
|
+
`mcp-1.1.0/lib/mcp/tool.rb:129-141`; the same contract at
|
|
326
|
+
`mcp-1.5.1/lib/mcp/server.rb:1569-1598`.
|
|
327
|
+
- Tests: `test/scout/llm/tools/{test_mcp,test_workflow,test_jobs_file,
|
|
328
|
+
test_definition,test_knowledge_base,test_tools}.rb` (0 failures after the
|
|
329
|
+
fix; `test_call.rb` is an empty placeholder).
|
|
330
|
+
- Probes: ~28 offline probes under `tmp/subsys-tools/`; the decisive MCP
|
|
331
|
+
boundary probe is the versioned Cortex artifact
|
|
332
|
+
`probe/mcp_serving_dispatch.rb` (Observation `mcp_serving_dispatch`),
|
|
333
|
+
whose `Observation/probe` run reproduces the fixed/broken matrix and drives
|
|
334
|
+
the real `scout_commands/workflow/mcp` entry point end-to-end over stdio.
|