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
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
module Chat
|
|
2
|
+
|
|
3
|
+
# --- inbox strategy configuration ---
|
|
4
|
+
|
|
5
|
+
# Suffixes naming the inbox directories. Both are SIBLINGS of the chat's
|
|
6
|
+
# save_file, in that file's own directory: the save_file basename's LAST
|
|
7
|
+
# extension is stripped and the suffix appended.
|
|
8
|
+
#
|
|
9
|
+
# '<X>.files/agent.chat' -> '<X>.files/agent.inbox'
|
|
10
|
+
# -> '<X>.files/agent.inbox_removed'
|
|
11
|
+
# 'a.b.chat' -> 'a.b.inbox' / 'a.b.inbox_removed' (multi-dot
|
|
12
|
+
# basenames strip only the last extension)
|
|
13
|
+
# 'agent' (no extension) -> 'agent.inbox' / 'agent.inbox_removed'
|
|
14
|
+
#
|
|
15
|
+
# The same sibling rule derives the live-workload sidecar `<base>.jobs` (see
|
|
16
|
+
# `Chat.jobs_file`), so all chat-state siblings of a save_file share ONE
|
|
17
|
+
# stem derivation (`Chat.inbox_stem`).
|
|
18
|
+
#
|
|
19
|
+
# Both are invisible to the provenance globs (`'*.chat'`,
|
|
20
|
+
# `'*.society/**/*.chat'` in Chat::DIRECT_LOG_CHAT_GLOBS), so inbox files are
|
|
21
|
+
# never mistaken for chat logs.
|
|
22
|
+
INBOX_SUFFIX = '.inbox'
|
|
23
|
+
INBOX_REMOVED_SUFFIX = '.inbox_removed'
|
|
24
|
+
|
|
25
|
+
# Live-workload sidecar suffix: `<base>.jobs` is a SIBLING FILE of the chat
|
|
26
|
+
# save_file listing the workflow jobs currently in flight under it.
|
|
27
|
+
JOBS_SUFFIX = '.jobs'
|
|
28
|
+
|
|
29
|
+
# Reserved inbox filename. When pickup reaches a regular file with exactly
|
|
30
|
+
# this name it is consumed exactly once (moved into `.inbox_removed` like
|
|
31
|
+
# any other file, mtime preserved) and the inference is aborted by raising
|
|
32
|
+
# the framework-native `Aborted` exception; the file content NEVER reaches
|
|
33
|
+
# the model -- instead it becomes the abort reason. Files sorted before it
|
|
34
|
+
# in the same pickup are processed normally first; files sorted after it
|
|
35
|
+
# stay in the inbox for the next run.
|
|
36
|
+
INBOX_ABORT_FILE = 'abort'
|
|
37
|
+
|
|
38
|
+
# --- inbox strategy ---
|
|
39
|
+
|
|
40
|
+
# Consume-once message inbox.
|
|
41
|
+
#
|
|
42
|
+
# Unlike the `shorten_*` strategies, `inbox` is NOT purely ephemeral: on
|
|
43
|
+
# every real inference it consumes the regular files found in the inbox
|
|
44
|
+
# sibling of the chat's save_file (see `Chat.inbox_dir`), moving each into
|
|
45
|
+
# the matching `.inbox_removed` sibling (mtime preserved, numeric suffix on
|
|
46
|
+
# name collision) and appending one `{role: 'user'}` message carrying the
|
|
47
|
+
# file content to the outgoing prompt.
|
|
48
|
+
#
|
|
49
|
+
# The filename `abort` (see INBOX_ABORT_FILE) is reserved: reaching it ends
|
|
50
|
+
# the pickup by raising `Aborted` (the framework-native user-interrupt
|
|
51
|
+
# exception, see scout-essentials exceptions.rb / scout-gear step.rb, which
|
|
52
|
+
# records the job as :aborted instead of :error), with the file content as
|
|
53
|
+
# the abort reason. Messages collected from files sorted before it are
|
|
54
|
+
# appended first, but never sent anywhere because the raise happens before
|
|
55
|
+
# the strategy returns; files after it are not touched.
|
|
56
|
+
#
|
|
57
|
+
# Ordering is deliberate: a file is moved BEFORE its content is read and
|
|
58
|
+
# appended, so a crash between the two may drop a notice but can never
|
|
59
|
+
# deliver the same notice twice.
|
|
60
|
+
#
|
|
61
|
+
# Injected messages are seen by the model but never persisted into the chat
|
|
62
|
+
# transcript; `.inbox_removed` is the record of what was delivered.
|
|
63
|
+
#
|
|
64
|
+
# Gating: without a save_file, or when the inbox directory does not exist,
|
|
65
|
+
# this is a silent no-op that creates no directories (the read path never
|
|
66
|
+
# creates the inbox; writers create it themselves).
|
|
67
|
+
def self.inbox(messages, save_file: nil)
|
|
68
|
+
return messages if save_file.nil? || save_file.to_s.empty?
|
|
69
|
+
|
|
70
|
+
inbox_dir = Chat.inbox_dir(save_file)
|
|
71
|
+
return messages unless File.directory?(inbox_dir)
|
|
72
|
+
|
|
73
|
+
# Top-level regular files only (glob '*' skips dotfiles, subdirectories
|
|
74
|
+
# are filtered out), sorted by filename so delivery order is
|
|
75
|
+
# deterministic.
|
|
76
|
+
files = Dir.glob(File.join(inbox_dir, '*')).select{|f| File.file?(f) }.sort
|
|
77
|
+
return messages if files.empty?
|
|
78
|
+
|
|
79
|
+
additions = []
|
|
80
|
+
aborted_reason = nil
|
|
81
|
+
files.each do |file|
|
|
82
|
+
begin
|
|
83
|
+
# Unreadable files are skipped in place: moving one would take it out
|
|
84
|
+
# of reach while failing to deliver it.
|
|
85
|
+
next unless File.readable?(file)
|
|
86
|
+
|
|
87
|
+
mtime = File.mtime(file)
|
|
88
|
+
target = Chat.inbox_removed_target(file, save_file)
|
|
89
|
+
FileUtils.mv(file, target)
|
|
90
|
+
File.utime(mtime, mtime, target)
|
|
91
|
+
|
|
92
|
+
if File.basename(target) == INBOX_ABORT_FILE
|
|
93
|
+
# Reserved filename: consumed once, content becomes the abort
|
|
94
|
+
# reason, delivery of any remaining files is deferred to the next
|
|
95
|
+
# run, and nothing else is appended to the prompt.
|
|
96
|
+
content = Open.read(target)
|
|
97
|
+
aborted_reason = content.strip.empty? ? "Inbox abort: #{target}" : "Inbox abort: #{content.strip}"
|
|
98
|
+
break
|
|
99
|
+
end
|
|
100
|
+
additions << { role: 'user', content: Open.read(target) }
|
|
101
|
+
rescue Exception => e
|
|
102
|
+
# One bad file must never break the ask path: skip it and continue
|
|
103
|
+
# with the rest. The file stays wherever the failure caught it (in
|
|
104
|
+
# the inbox if the move failed, already in `.inbox_removed` if the
|
|
105
|
+
# read failed), so the next inference can still make progress.
|
|
106
|
+
Log.low "Inbox: skipping unreadable/unmovable file #{file}: #{e.message}"
|
|
107
|
+
next
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
if aborted_reason
|
|
112
|
+
Log.low "Inbox: aborting inference (#{aborted_reason})"
|
|
113
|
+
raise Aborted, aborted_reason
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
return messages if additions.empty?
|
|
117
|
+
|
|
118
|
+
Log.low "Inbox: appended #{additions.length} message(s) from #{inbox_dir}"
|
|
119
|
+
|
|
120
|
+
# ScoutCoder: Array#+ on a Chat-annotated array returns a plain Array --
|
|
121
|
+
# the Chat annotation is not carried through +, concat or flatten, so any
|
|
122
|
+
# strategy that rebuilds the message list must re-annotate with
|
|
123
|
+
# Chat.setup or downstream code (Chat.clean/purge/format_messages) sees a
|
|
124
|
+
# bare Array.
|
|
125
|
+
Chat.setup(messages + additions)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Inbox directory of a chat save_file: SIBLING of the save_file in its own
|
|
129
|
+
# directory, named after the save_file basename with its LAST extension
|
|
130
|
+
# stripped plus '.inbox'. An extension-less basename keeps the whole name
|
|
131
|
+
# ('agent' -> 'agent.inbox'); a multi-dot basename strips only the last
|
|
132
|
+
# extension ('a.b.chat' -> 'a.b.inbox').
|
|
133
|
+
def self.inbox_dir(save_file)
|
|
134
|
+
File.join(File.dirname(save_file.to_s), Chat.inbox_stem(save_file) + INBOX_SUFFIX)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Directory holding the record of delivered files: same sibling derivation
|
|
138
|
+
# as `Chat.inbox_dir`, with the '.inbox_removed' suffix.
|
|
139
|
+
def self.inbox_removed_dir(save_file)
|
|
140
|
+
File.join(File.dirname(save_file.to_s), Chat.inbox_stem(save_file) + INBOX_REMOVED_SUFFIX)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Save_file basename with its LAST extension removed ('agent.chat' ->
|
|
144
|
+
# 'agent', 'a.b.chat' -> 'a.b', 'agent' -> 'agent').
|
|
145
|
+
def self.inbox_stem(save_file)
|
|
146
|
+
base = File.basename(save_file.to_s)
|
|
147
|
+
ext = File.extname(base)
|
|
148
|
+
ext.empty? ? base : base[0...-ext.length]
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# Live-workload sidecar of a chat save_file: SIBLING FILE in the save_file's
|
|
152
|
+
# own directory, derived with the SAME trailing-strip rule as the inbox dirs
|
|
153
|
+
# (`Chat.inbox_stem`, which uses File.extname -- never a first-match sub).
|
|
154
|
+
#
|
|
155
|
+
# '<dir>/agent.chat' -> '<dir>/agent.jobs'
|
|
156
|
+
# '<job>.chat.files/agent.chat' -> '<job>.chat.files/agent.jobs'
|
|
157
|
+
# (trailing strip only: a '.chat' in an ANCESTOR component is never
|
|
158
|
+
# touched, unlike the historical unanchored sub)
|
|
159
|
+
# 'a.b.chat' / 'agent' -> 'a.b.jobs' / 'agent.jobs'
|
|
160
|
+
#
|
|
161
|
+
# Writers (LLM.process_calls) rewrite the file per round and remove it in an
|
|
162
|
+
# `ensure` once Workflow.produce returns; it is a snapshot, not an append log.
|
|
163
|
+
def self.jobs_file(save_file)
|
|
164
|
+
File.join(File.dirname(save_file.to_s), Chat.inbox_stem(save_file) + JOBS_SUFFIX)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Return the `.inbox_removed/` target path for `file`, appending a numeric
|
|
168
|
+
# suffix on name collision so previous deliveries are never overwritten.
|
|
169
|
+
# `.inbox_removed/` is created lazily, only when a file is actually about to
|
|
170
|
+
# be moved; the read path never creates directories on its own.
|
|
171
|
+
def self.inbox_removed_target(file, save_file)
|
|
172
|
+
removed_dir = Chat.inbox_removed_dir(save_file)
|
|
173
|
+
FileUtils.mkdir_p(removed_dir) unless File.directory?(removed_dir)
|
|
174
|
+
|
|
175
|
+
name = File.basename(file)
|
|
176
|
+
target = File.join(removed_dir, name)
|
|
177
|
+
return target unless File.exist?(target)
|
|
178
|
+
|
|
179
|
+
ext = File.extname(name)
|
|
180
|
+
stem = ext.empty? ? name : name[0...-ext.length]
|
|
181
|
+
index = 1
|
|
182
|
+
loop do
|
|
183
|
+
target = File.join(removed_dir, "#{stem}.#{index}#{ext}")
|
|
184
|
+
return target unless File.exist?(target)
|
|
185
|
+
index += 1
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|