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
|
@@ -73,15 +73,6 @@ class TestLLMAgentSave < Test::Unit::TestCase
|
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
def test_save_without_path_raises_when_unconfigured
|
|
77
|
-
agent = simple_agent
|
|
78
|
-
agent.user 'orphan'
|
|
79
|
-
|
|
80
|
-
assert_raise ScoutException do
|
|
81
|
-
agent.save
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
76
|
def test_save_nested_society
|
|
86
77
|
TmpFile.with_dir do |dir|
|
|
87
78
|
root = simple_agent('root')
|
|
@@ -175,7 +166,7 @@ class TestLLMAgentSave < Test::Unit::TestCase
|
|
|
175
166
|
agent.save_file = chat_file
|
|
176
167
|
|
|
177
168
|
agent.user 'auto question'
|
|
178
|
-
res = agent.chat persist: false,
|
|
169
|
+
res = agent.chat persist: false, backend: :mock
|
|
179
170
|
|
|
180
171
|
assert_equal 'mock answer', res
|
|
181
172
|
content = Open.read(chat_file)
|
|
@@ -208,7 +199,7 @@ class TestLLMAgentSave < Test::Unit::TestCase
|
|
|
208
199
|
grandchild.user 'grandchild question'
|
|
209
200
|
child.chats = { 'Critic/c_1' => grandchild }
|
|
210
201
|
|
|
211
|
-
child.chat persist: false,
|
|
202
|
+
child.chat persist: false, backend: :mock
|
|
212
203
|
|
|
213
204
|
assert_include Open.read(child_file), 'mock answer'
|
|
214
205
|
|
|
@@ -231,7 +222,7 @@ class TestLLMAgentSave < Test::Unit::TestCase
|
|
|
231
222
|
agent.save_file = chat_file
|
|
232
223
|
agent.user 'bare question'
|
|
233
224
|
|
|
234
|
-
assert_include agent.ask(agent.current_chat, persist: false,
|
|
225
|
+
assert_include agent.ask(agent.current_chat, persist: false, backend: :mock), 'mock answer'
|
|
235
226
|
|
|
236
227
|
# Bare ask: the chat was not grown by Agent#chat, so no file anywhere
|
|
237
228
|
assert !Open.exist?(chat_file)
|
|
@@ -252,6 +243,13 @@ class TestLLMAgentSave < Test::Unit::TestCase
|
|
|
252
243
|
|
|
253
244
|
agent = simple_agent('root')
|
|
254
245
|
worker = simple_agent('worker')
|
|
246
|
+
# ScoutCoder: the specialist's round is launched by LLM.process_calls
|
|
247
|
+
# as 'agent.chat return_messages: true' with NO call options, so only
|
|
248
|
+
# its own other_options can keep it on the mock backend on a DIRECT
|
|
249
|
+
# run where an account endpoint (env LLM/ASK_ENDPOINT or
|
|
250
|
+
# ~/.scout/etc/AI/<endpoint>.yaml) would otherwise override the
|
|
251
|
+
# test_helper config pin and send the child round to a real client.
|
|
252
|
+
worker.other_options = IndiferentHash.setup(backend: :mock, persist: false)
|
|
255
253
|
agent.society = { 'Worker' => worker }
|
|
256
254
|
agent.socialize
|
|
257
255
|
|
|
@@ -259,7 +257,7 @@ class TestLLMAgentSave < Test::Unit::TestCase
|
|
|
259
257
|
agent.save_file = chat_file
|
|
260
258
|
agent.user 'tool question'
|
|
261
259
|
|
|
262
|
-
assert_equal 'final answer', agent.chat(persist: false,
|
|
260
|
+
assert_equal 'final answer', agent.chat(persist: false, backend: :mock)
|
|
263
261
|
|
|
264
262
|
# The parent chat file holds the tool round and its answer
|
|
265
263
|
content = Open.read(chat_file)
|
|
@@ -275,13 +273,57 @@ class TestLLMAgentSave < Test::Unit::TestCase
|
|
|
275
273
|
end
|
|
276
274
|
end
|
|
277
275
|
|
|
276
|
+
# The dropped legacy layout: saving an agent (with society conversations)
|
|
277
|
+
# must NOT create a `.files/log` tree at all, while still producing the
|
|
278
|
+
# canonical files: the root chat copy and the society conversations.
|
|
279
|
+
def test_save_produces_no_legacy_log_tree
|
|
280
|
+
TmpFile.with_dir do |dir|
|
|
281
|
+
LLM::Mock.script([
|
|
282
|
+
{tool_calls: [{name: 'ask', arguments: {agent: 'Worker', prompt: 'hi'}}]},
|
|
283
|
+
'final answer'
|
|
284
|
+
])
|
|
285
|
+
|
|
286
|
+
agent = simple_agent('root')
|
|
287
|
+
worker = simple_agent('worker')
|
|
288
|
+
# ScoutCoder: the specialist's round is launched by LLM.process_calls
|
|
289
|
+
# as 'agent.chat return_messages: true' with NO call options, so only
|
|
290
|
+
# its own other_options can keep it on the mock backend on a DIRECT
|
|
291
|
+
# run where an account endpoint (env LLM/ASK_ENDPOINT or
|
|
292
|
+
# ~/.scout/etc/AI/<endpoint>.yaml) would otherwise override the
|
|
293
|
+
# test_helper config pin and send the child round to a real client.
|
|
294
|
+
worker.other_options = IndiferentHash.setup(backend: :mock, persist: false)
|
|
295
|
+
agent.society = { 'Worker' => worker }
|
|
296
|
+
agent.socialize
|
|
297
|
+
|
|
298
|
+
chat_file = File.join(dir, 'root.chat')
|
|
299
|
+
agent.save_file = chat_file
|
|
300
|
+
agent.user 'root question'
|
|
301
|
+
assert_equal 'final answer', agent.chat(persist: false, backend: :mock)
|
|
302
|
+
agent.save
|
|
303
|
+
|
|
304
|
+
legacy_dir = File.join(chat_file + '.files', 'log')
|
|
305
|
+
refute Open.exist?(legacy_dir),
|
|
306
|
+
'legacy .files/log tree must not be created by saving'
|
|
307
|
+
|
|
308
|
+
# Canonical files are all there: the root chat itself (a plain
|
|
309
|
+
# save_file owns no .files copy; only CLI/workflow-anchored save files
|
|
310
|
+
# live inside a .files dir) and the society conversation.
|
|
311
|
+
assert Open.exist?(chat_file), 'root chat file must be written'
|
|
312
|
+
assert_include Open.read(chat_file), 'root question'
|
|
313
|
+
society_chat = File.join(chat_file.sub(/\.chat\z/, '.society'), 'Worker', 'default', 'agent.chat')
|
|
314
|
+
assert Open.exist?(society_chat),
|
|
315
|
+
'canonical society conversation must be written'
|
|
316
|
+
assert_include Open.read(society_chat), 'hi'
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
|
|
278
320
|
def test_no_auto_save_without_save_file
|
|
279
321
|
TmpFile.with_dir do |dir|
|
|
280
322
|
LLM::Mock.script('mock answer')
|
|
281
323
|
|
|
282
324
|
agent = simple_agent
|
|
283
325
|
agent.user 'volatile question'
|
|
284
|
-
agent.chat persist: false,
|
|
326
|
+
agent.chat persist: false, backend: :mock
|
|
285
327
|
|
|
286
328
|
assert !Open.exist?(File.join(dir, 'never.chat'))
|
|
287
329
|
assert_equal [], Dir.glob(File.join(dir, '**', '*.chat'))
|
|
@@ -362,6 +404,19 @@ class TestLLMAgentSocietySaveFile < Test::Unit::TestCase
|
|
|
362
404
|
agent.send(:society_save_file, 'Direct', 'harness_test')
|
|
363
405
|
end
|
|
364
406
|
|
|
407
|
+
# CLI `ask --chat` builds its agent save file from the chat's files_dir
|
|
408
|
+
# through Agent.canonical_chat_file (scout_commands/agent/ask and
|
|
409
|
+
# scout_commands/llm/ask); these mirror the two layouts that CLI accepts.
|
|
410
|
+
def test_canonical_chat_file_cli_shaped_save_file
|
|
411
|
+
assert_equal 'dir/cli.chat.files/agent.chat',
|
|
412
|
+
LLM::Agent.canonical_chat_file('dir/cli.chat.files', nil)
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
def test_canonical_chat_file_cli_shaped_named_agent
|
|
416
|
+
assert_equal 'dir/job.chat.files/worker.chat',
|
|
417
|
+
LLM::Agent.canonical_chat_file('dir/job.chat.files', 'worker')
|
|
418
|
+
end
|
|
419
|
+
|
|
365
420
|
def test_society_save_file_plain_root_chat
|
|
366
421
|
agent = LLM::Agent.new
|
|
367
422
|
agent.save_file = 'dir/root.chat'
|
|
@@ -400,7 +455,7 @@ class TestLLMAgentSocietySaveFile < Test::Unit::TestCase
|
|
|
400
455
|
# must not leave a stray `cli.society.files` directory behind.
|
|
401
456
|
LLM::Mock.script('mock answer')
|
|
402
457
|
child.user 'child question'
|
|
403
|
-
child.chat persist: false,
|
|
458
|
+
child.chat persist: false, backend: :mock
|
|
404
459
|
|
|
405
460
|
assert_include Open.read(expected), 'mock answer'
|
|
406
461
|
assert_empty Dir.glob(File.join(dir, '**', '*.society.files*'))
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
|
2
2
|
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
|
3
3
|
|
|
4
|
+
# Offline replacement for the remote `Baking` workflow (same technique as
|
|
5
|
+
# test/scout/llm/test_chat.rb): the `introduce:`/`tool:` directives resolve
|
|
6
|
+
# workflow names through Kernel.const_get first, so a named module is
|
|
7
|
+
# reachable without any git clone.
|
|
8
|
+
TestBaking = Module.new do
|
|
9
|
+
extend Workflow
|
|
10
|
+
self.name = "TestBaking"
|
|
11
|
+
|
|
12
|
+
desc "Bake a tray of muffins"
|
|
13
|
+
input :blueberries, :boolean, "Add blueberries", true
|
|
14
|
+
task :bake_muffin_tray => :string do |blueberries|
|
|
15
|
+
"Baking muffins: blueberries=#{blueberries}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
4
19
|
class TestWorkflowChatTaskSave < Test::Unit::TestCase
|
|
5
20
|
# NOTE on setup order: test_helper's `setup do` callback runs AFTER this
|
|
6
21
|
# `setup` method and does `Open.rm_rf tmpdir`, i.e. it deletes every
|
|
@@ -15,6 +30,8 @@ class TestWorkflowChatTaskSave < Test::Unit::TestCase
|
|
|
15
30
|
@tmp_work = Path.setup(File.join(TmpFile.tmpdir, 'workflow_chat_task_save'))
|
|
16
31
|
Open.mkdir @tmp_work
|
|
17
32
|
TestWorkflowChatTaskSaveWF.directory = @tmp_work
|
|
33
|
+
$tooling_probe_agent = nil
|
|
34
|
+
$tools_option_agent = nil
|
|
18
35
|
end
|
|
19
36
|
|
|
20
37
|
def teardown
|
|
@@ -39,22 +56,84 @@ class TestWorkflowChatTaskSave < Test::Unit::TestCase
|
|
|
39
56
|
self.name = 'TestWorkflowChatTaskSaveWF'
|
|
40
57
|
|
|
41
58
|
chat_task :plain do
|
|
42
|
-
LLM::Agent.new(start_chat: Chat.setup([{role: :system, content: 'You are a helper.'}, {role: :user, content: 'Say hi'}])
|
|
59
|
+
LLM::Agent.new(start_chat: Chat.setup([{role: :system, content: 'You are a helper.'}, {role: :user, content: 'Say hi'}]),
|
|
60
|
+
backend: :mock, persist: false)
|
|
43
61
|
end
|
|
44
62
|
|
|
45
63
|
chat_task :with_chat do
|
|
46
|
-
agent = LLM::Agent.new(start_chat: Chat.setup([{role: :system, content: 'You are a helper.'}])
|
|
64
|
+
agent = LLM::Agent.new(start_chat: Chat.setup([{role: :system, content: 'You are a helper.'}]),
|
|
65
|
+
backend: :mock, persist: false)
|
|
47
66
|
agent.user 'question one'
|
|
48
67
|
agent.current_chat.push({role: :assistant, content: 'answer one'})
|
|
49
68
|
agent
|
|
50
69
|
end
|
|
70
|
+
|
|
71
|
+
# The agent is built through the `agent` helper and socializes (the
|
|
72
|
+
# `ask` tool) DURING its first round. The round then ends in a
|
|
73
|
+
# ScoutException raised by the block itself, so chat_task's rescue path
|
|
74
|
+
# runs and log_agent (the end-of-task sweep) NEVER executes: the child
|
|
75
|
+
# conversation can only be durable through its creation-time anchor.
|
|
76
|
+
chat_task :socialize_in_first_round do
|
|
77
|
+
# The specialist template carries the same options-level pins: the
|
|
78
|
+
# child round is launched by LLM.process_calls as
|
|
79
|
+
# 'agent.chat return_messages: true' with NO call options, so only the
|
|
80
|
+
# agent's own other_options can keep it on the mock backend (and out
|
|
81
|
+
# of the shared ask cache) on a direct run.
|
|
82
|
+
worker = LLM::Agent.new(start_chat: Chat.setup([{role: :system, content: 'child helper'}]),
|
|
83
|
+
backend: :mock, persist: false)
|
|
84
|
+
agent = self.agent nil
|
|
85
|
+
agent.society = { 'Worker' => worker }
|
|
86
|
+
agent.socialize
|
|
87
|
+
agent.user 'delegate please'
|
|
88
|
+
LLM::Mock.script({tool_calls: [{name: 'ask', arguments: {agent: 'Worker', prompt: 'child prompt'}}]},
|
|
89
|
+
'child answer',
|
|
90
|
+
'parent done')
|
|
91
|
+
# ScoutCoder: hermetic fix (two layers, both required for a DIRECT
|
|
92
|
+
# `ruby test/.../test_workflow.rb` run).
|
|
93
|
+
#
|
|
94
|
+
# 1. persist: false. LLM.ask persists every round under
|
|
95
|
+
# Scout.var.cache.ask (~/.scout/var/cache/ask), a SHARED cross-run
|
|
96
|
+
# store. On a warm cache the whole tool round below is served from
|
|
97
|
+
# a cached entry WITHOUT executing the ask tool, so the child
|
|
98
|
+
# conversation is never opened, anchored, or saved: the society
|
|
99
|
+
# subtree this test asserts on only materializes on a cache miss.
|
|
100
|
+
#
|
|
101
|
+
# 2. backend: :mock at the OPTIONS level (not via test_helper's
|
|
102
|
+
# Scout::Config pin). An account endpoint — `LLM`/`ASK_ENDPOINT`
|
|
103
|
+
# env or `~/.scout/etc/AI/<endpoint>.yaml`, resolved in
|
|
104
|
+
# LLM.ask AFTER the config lookup — merges its yaml into the ask
|
|
105
|
+
# options with add_defaults, and a yaml `backend: openai` (plus
|
|
106
|
+
# url/key/model) therefore overrides the config-pinned mock. The
|
|
107
|
+
# real backend then ignores the scripted tool call, so the child
|
|
108
|
+
# never socializes and the assertion at the bottom fails; worse,
|
|
109
|
+
# the round goes LIVE against the account endpoint. An explicit
|
|
110
|
+
# options value survives add_defaults, so this pin makes the task
|
|
111
|
+
# hermetic: it always runs the scripted mock round (which always
|
|
112
|
+
# emits the `ask` tool call) and never constructs a real client.
|
|
113
|
+
agent.chat(return_messages: true, persist: false, backend: :mock)
|
|
114
|
+
raise ScoutException, 'deliberate stop before log_agent'
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Hygiene probe: declarative workflow tooling from the job chat must
|
|
118
|
+
# reach the seeded conversation, and the helper's own option handling
|
|
119
|
+
# (which keeps :tools, unlike the social pipeline's private-option
|
|
120
|
+
# strip) must still deliver an options-level tool to the agent.
|
|
121
|
+
chat_task :tooling_probe do
|
|
122
|
+
$tooling_probe_agent = self.agent nil
|
|
123
|
+
extra = [Proc.new { |_name, _args| 'ok' },
|
|
124
|
+
{'name' => 'extra_tool',
|
|
125
|
+
'parameters' => {'type' => 'object', 'properties' => {}, 'required' => []}}]
|
|
126
|
+
$tools_option_agent = self.agent nil, tools: {'extra_tool' => extra}
|
|
127
|
+
$tooling_probe_agent.current_chat.push({role: :assistant, content: 'probe done'})
|
|
128
|
+
$tooling_probe_agent
|
|
129
|
+
end
|
|
51
130
|
end
|
|
52
131
|
|
|
53
132
|
def test_no_files_without_society
|
|
54
133
|
job = run_job(TmpFile.tmpdir, :plain)
|
|
55
134
|
path = job.path
|
|
56
135
|
# The unified provenance save ALWAYS writes this job agent's own chat at
|
|
57
|
-
# `<path>.files/
|
|
136
|
+
# `<path>.files/agent.chat` (that is the point of the mechanism);
|
|
58
137
|
# only the society subtree stays lazy and appears with a live society.
|
|
59
138
|
assert File.exist?("#{path}.files/agent.chat")
|
|
60
139
|
assert !File.exist?("#{path}.files/agent.society")
|
|
@@ -84,7 +163,7 @@ class TestWorkflowChatTaskSave < Test::Unit::TestCase
|
|
|
84
163
|
agent.society = { 'Worker' => worker }
|
|
85
164
|
agent.save_file = File.join(dir, 'agent.chat')
|
|
86
165
|
agent.user 'question'
|
|
87
|
-
child = agent.ask_agent('Worker', 'child prompt', options: {endpoint: 'mock'})
|
|
166
|
+
child = agent.ask_agent('Worker', 'child prompt', options: {endpoint: 'mock', persist: false})
|
|
88
167
|
agent.current_chat.push({role: :assistant, content: 'final answer'})
|
|
89
168
|
|
|
90
169
|
written = agent.save
|
|
@@ -107,4 +186,51 @@ class TestWorkflowChatTaskSave < Test::Unit::TestCase
|
|
|
107
186
|
assert_include delta.first[:content], 'question one'
|
|
108
187
|
assert_include delta.last[:content], 'answer one'
|
|
109
188
|
end
|
|
189
|
+
|
|
190
|
+
# The fails-today guard of the A4 step: a chat_task agent that socializes
|
|
191
|
+
# INSIDE its first round leaves a durable child society file, even though
|
|
192
|
+
# the task then aborts before log_agent's end-of-task save sweep.
|
|
193
|
+
def test_socialize_inside_first_round_persists_child_society
|
|
194
|
+
job = run_job(TmpFile.tmpdir, :socialize_in_first_round)
|
|
195
|
+
child = File.join(job.files_dir.to_s, 'agent.society', 'Worker', 'default', 'agent.chat')
|
|
196
|
+
assert Open.exist?(child), "expected the socialized child chat at #{child}"
|
|
197
|
+
parent = File.join(job.files_dir.to_s, 'agent.chat')
|
|
198
|
+
assert Open.exist?(parent), "expected the job agent chat at #{parent}"
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def test_agent_helper_seeds_tooling_and_keeps_tools_option
|
|
202
|
+
chat = "tool: TestWorkflowChatTaskSaveWF\nintroduce: TestWorkflowChatTaskSaveWF\nuser: hi\n"
|
|
203
|
+
TestWorkflowChatTaskSaveWF.directory = Path.setup(TmpFile.tmpdir)
|
|
204
|
+
job = TestWorkflowChatTaskSaveWF.job(:tooling_probe, chat: chat)
|
|
205
|
+
job.produce
|
|
206
|
+
|
|
207
|
+
agent = $tooling_probe_agent
|
|
208
|
+
refute_nil agent
|
|
209
|
+
# Anchored and job-wired at creation, through the pipeline
|
|
210
|
+
assert_equal File.join(job.files_dir.to_s, 'agent.chat'), agent.save_file.to_s
|
|
211
|
+
assert_equal job.path.to_s, agent.job.path.to_s
|
|
212
|
+
# Seed order preserved: declarative tooling first, then the cwd/job
|
|
213
|
+
# system preamble, exactly where start_chat.follow tooling sat before
|
|
214
|
+
roles = agent.start_chat.collect { |m| m[:role].to_s }
|
|
215
|
+
assert_equal %w[tool introduce system], roles
|
|
216
|
+
assert agent.start_chat.last[:content].include?('Your current working directory')
|
|
217
|
+
# The declarative tooling seeded into the conversation still resolves
|
|
218
|
+
# to real tool definitions. The chat inside a chat_task refers to this
|
|
219
|
+
# workflow itself; here we resolve the directive against a module whose
|
|
220
|
+
# constant IS reachable, to prove the seeded messages are well-formed
|
|
221
|
+
# tooling rather than inert text (the same technique as
|
|
222
|
+
# test/scout/llm/test_chat.rb's TestBaking).
|
|
223
|
+
seeded = Chat.setup(agent.start_chat.dup)
|
|
224
|
+
seeded.each { |m| m[:content] = m[:content].to_s.gsub('TestWorkflowChatTaskSaveWF', 'TestBaking') }
|
|
225
|
+
definitions = LLM::Mock.tools(seeded, {})
|
|
226
|
+
assert_include definitions.keys, :bake_muffin_tray
|
|
227
|
+
assert_equal TestBaking, definitions[:bake_muffin_tray].first
|
|
228
|
+
|
|
229
|
+
# Option hygiene: the helper's options reach the agent intact (the
|
|
230
|
+
# pipeline does not strip :tools on this path)
|
|
231
|
+
tools_option_agent = $tools_option_agent
|
|
232
|
+
refute_nil tools_option_agent
|
|
233
|
+
assert tools_option_agent.other_options[:tools]['extra_tool']
|
|
234
|
+
assert_equal File.join(job.files_dir.to_s, 'agent.chat'), tools_option_agent.save_file.to_s
|
|
235
|
+
end
|
|
110
236
|
end
|
|
@@ -17,7 +17,7 @@ user: say hi
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def test_ask
|
|
20
|
-
client =
|
|
20
|
+
client = TestClients.anthropic_client('backends/anthropic')
|
|
21
21
|
res = LLM::Anthropic.ask 'user: write a script that sorts files in a directory',
|
|
22
22
|
client: client, model: 'claude-sonnet-4-5', persist: false
|
|
23
23
|
|
|
@@ -42,7 +42,7 @@ user:
|
|
|
42
42
|
|
|
43
43
|
should i take an umbrella?
|
|
44
44
|
EOF
|
|
45
|
-
client =
|
|
45
|
+
client = TestClients.anthropic_client('backends/anthropic')
|
|
46
46
|
res = LLM::Anthropic.ask prompt, client: client, persist: false
|
|
47
47
|
|
|
48
48
|
assert_equal 'Mock answer from Anthropic messages', res
|
|
@@ -83,7 +83,7 @@ What is the weather in London. Should I take my umbrella?
|
|
|
83
83
|
},
|
|
84
84
|
]
|
|
85
85
|
|
|
86
|
-
client =
|
|
86
|
+
client = TestClients.anthropic_client('backends/anthropic_tool_use', 'backends/anthropic')
|
|
87
87
|
respose = LLM::Anthropic.ask prompt, tools: tools,
|
|
88
88
|
client: client, log_errors: true, persist: false do |name,arguments|
|
|
89
89
|
"It's 15 degrees and raining."
|
|
@@ -101,7 +101,7 @@ What is the weather in London. Should I take my umbrella?
|
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
def test_json_output
|
|
104
|
-
client =
|
|
104
|
+
client = TestClients.anthropic_client('backends/anthropic')
|
|
105
105
|
res = LLM::Anthropic.ask 'user: What other movies have the protagonists of the original gost busters played on, just the top.',
|
|
106
106
|
format: :json, client: client, persist: false
|
|
107
107
|
|
|
@@ -14,7 +14,7 @@ class TestLLMBedrock < Test::Unit::TestCase
|
|
|
14
14
|
# dispatching to the :bedrock backend).
|
|
15
15
|
def test_ask
|
|
16
16
|
require 'scout/llm/backends/bedrock'
|
|
17
|
-
client =
|
|
17
|
+
client = TestClients.bedrock_client('backends/bedrock')
|
|
18
18
|
|
|
19
19
|
response = LLM::Bedrock.ask 'user: say hi to bedrock',
|
|
20
20
|
client: client,
|
|
@@ -36,7 +36,7 @@ class TestLLMBedrock < Test::Unit::TestCase
|
|
|
36
36
|
|
|
37
37
|
def test_ask_prompt_type
|
|
38
38
|
require 'scout/llm/backends/bedrock'
|
|
39
|
-
client =
|
|
39
|
+
client = TestClients.bedrock_client('backends/bedrock')
|
|
40
40
|
|
|
41
41
|
response = LLM::Bedrock.ask 'user: say hi through the prompt endpoint',
|
|
42
42
|
client: client, type: :prompt,
|
|
@@ -52,7 +52,7 @@ class TestLLMBedrock < Test::Unit::TestCase
|
|
|
52
52
|
|
|
53
53
|
def test_embeddings
|
|
54
54
|
require 'scout/llm/backends/bedrock'
|
|
55
|
-
client =
|
|
55
|
+
client = TestClients.bedrock_client('backends/bedrock_embedding')
|
|
56
56
|
|
|
57
57
|
emb = LLM::Bedrock.embed 'Some text', client: client,
|
|
58
58
|
model: 'amazon.titan-embed-text-v1'
|
|
@@ -90,7 +90,7 @@ class TestLLMBedrock < Test::Unit::TestCase
|
|
|
90
90
|
}
|
|
91
91
|
]
|
|
92
92
|
|
|
93
|
-
client =
|
|
93
|
+
client = TestClients.bedrock_client('backends/bedrock_tool_use', 'backends/bedrock')
|
|
94
94
|
|
|
95
95
|
calls_seen = []
|
|
96
96
|
response = LLM::Bedrock.ask 'user: What is the weather in London? Should I take an umbrella? Use the tool.',
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Wire-format regression: strategy-injected bookkeeping keys (the
|
|
2
|
+
# epoch_tool_compactation record's `compacted` flag) must not reach the
|
|
3
|
+
# provider request payload, while the record's content stays intact.
|
|
4
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
|
5
|
+
require 'scout/llm/backends/default'
|
|
6
|
+
require 'scout/llm/backends/anthropic'
|
|
7
|
+
require 'scout/llm/backends/glm'
|
|
8
|
+
|
|
9
|
+
class TestBackendFormatOther < Test::Unit::TestCase
|
|
10
|
+
def test_compaction_record_flag_is_dropped_on_the_wire
|
|
11
|
+
record = IndiferentHash.setup(
|
|
12
|
+
{ role: :user, content: '[TOOL-COMPACTION-RECORD] body', compacted: true }
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
[LLM::Anthropic, LLM::GLM].each do |backend|
|
|
16
|
+
formatted = backend.format_messages([{ role: 'user', content: 'hi' }, record])
|
|
17
|
+
|
|
18
|
+
wire_record = formatted.last
|
|
19
|
+
assert_not_nil wire_record
|
|
20
|
+
assert_equal '[TOOL-COMPACTION-RECORD] body', wire_record[:content]
|
|
21
|
+
assert_not_include wire_record.keys.collect(&:to_s), 'compacted'
|
|
22
|
+
assert_equal %w[content role], wire_record.keys.collect(&:to_s).sort
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_format_other_does_not_mutate_the_original_message
|
|
27
|
+
record = IndiferentHash.setup(
|
|
28
|
+
{ role: :user, content: 'meta-ish', compacted: true, something_else: 1 }
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
LLM::Anthropic.format_messages([record.dup])
|
|
32
|
+
|
|
33
|
+
assert_equal %w[compacted content role something_else], record.keys.collect(&:to_s).sort
|
|
34
|
+
assert_equal true, record[:compacted]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_plain_user_message_passes_through_equivalently
|
|
38
|
+
plain = IndiferentHash.setup({ role: 'user', content: 'hello' })
|
|
39
|
+
formatted = LLM::Anthropic.format_messages([plain])
|
|
40
|
+
|
|
41
|
+
assert_equal({ role: 'user', content: 'hello' }, formatted.first)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -4,7 +4,7 @@ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1
|
|
|
4
4
|
class TestLLMOllama < Test::Unit::TestCase
|
|
5
5
|
|
|
6
6
|
def test_ask
|
|
7
|
-
client =
|
|
7
|
+
client = TestClients.ollama_client('backends/ollama')
|
|
8
8
|
res = LLM::OLlama.ask 'user: write a script that sorts files in a directory',
|
|
9
9
|
client: client, model: 'mistral', mode: 'chat', persist: false
|
|
10
10
|
|
|
@@ -44,7 +44,7 @@ What is the weather in London. Should I take an umbrella?
|
|
|
44
44
|
},
|
|
45
45
|
]
|
|
46
46
|
|
|
47
|
-
client =
|
|
47
|
+
client = TestClients.ollama_client('backends/ollama_tool_call', 'backends/ollama')
|
|
48
48
|
respose = LLM::OLlama.ask prompt, model: 'gpt-oss',
|
|
49
49
|
client: client, tool_choice: 'required',
|
|
50
50
|
tools: tools, persist: false do |name,arguments|
|
|
@@ -15,18 +15,22 @@ user: write a script that sorts files in a directory
|
|
|
15
15
|
ppp LLM::OpenWebUI.ask prompt, model: 'qwen3-vl:30b', url: "https://gepeto.bsc.es/api"
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
# Offline: stub RestClient.
|
|
19
|
-
# parsing are exercised. OpenWebUI is OpenAI-compatible, so the
|
|
20
|
-
# fixture is replayed as the response body.
|
|
18
|
+
# Offline: stub RestClient::Request.execute so only request construction and
|
|
19
|
+
# response parsing are exercised. OpenWebUI is OpenAI-compatible, so the
|
|
20
|
+
# openai_chat fixture is replayed as the response body.
|
|
21
21
|
def test_ask_request_construction
|
|
22
22
|
fixture = TestFixtures.fixture('backends/openai_chat')
|
|
23
23
|
expected_answer = fixture.dig('choices', 0, 'message', 'content')
|
|
24
24
|
|
|
25
25
|
recorded = []
|
|
26
|
-
original = RestClient.method(:
|
|
27
|
-
|
|
28
|
-
RestClient.define_singleton_method(:
|
|
29
|
-
recorded << {
|
|
26
|
+
original = RestClient::Request.method(:execute)
|
|
27
|
+
|
|
28
|
+
RestClient::Request.define_singleton_method(:execute) do |**request_options|
|
|
29
|
+
recorded << {
|
|
30
|
+
url: request_options[:url],
|
|
31
|
+
payload: JSON.parse(request_options[:payload]),
|
|
32
|
+
headers: request_options[:headers]
|
|
33
|
+
}
|
|
30
34
|
body = Struct.new(:body).new(fixture.to_json)
|
|
31
35
|
body
|
|
32
36
|
end
|
|
@@ -36,7 +40,7 @@ user: write a script that sorts files in a directory
|
|
|
36
40
|
model: 'qwen3-vl:30b', url: 'https://openwebui.example/api',
|
|
37
41
|
key: 'test-key', persist: false
|
|
38
42
|
ensure
|
|
39
|
-
RestClient.singleton_class.send(:define_method, :
|
|
43
|
+
RestClient::Request.singleton_class.send(:define_method, :execute, original)
|
|
40
44
|
end
|
|
41
45
|
|
|
42
46
|
assert_equal expected_answer, answer
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
|
2
|
+
require 'scout/llm/backends/responses'
|
|
3
|
+
require 'scout/llm/backends/openai'
|
|
4
|
+
|
|
5
|
+
class TestLLMReasoning < Test::Unit::TestCase
|
|
6
|
+
def responses(*items)
|
|
7
|
+
{ 'output' => items }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def reasoning_item(*texts)
|
|
11
|
+
{
|
|
12
|
+
'type' => 'reasoning',
|
|
13
|
+
'summary' => texts.collect { |text| { 'type' => 'summary_text', 'text' => text } }
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def chat(message)
|
|
18
|
+
{ 'choices' => [{ 'message' => message }] }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_responses_summary_on_a_tool_call_turn
|
|
22
|
+
response = responses(
|
|
23
|
+
reasoning_item('Check the available data').merge('encrypted_content' => 'opaque-state'),
|
|
24
|
+
{ 'type' => 'function_call', 'name' => 'example', 'arguments' => '{}' }
|
|
25
|
+
)
|
|
26
|
+
assert_equal 'Check the available data', LLM::Responses.reasoning(response)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_responses_collects_all_summary_parts_in_order
|
|
30
|
+
response = responses(
|
|
31
|
+
reasoning_item("First\npoint", 'Second point'),
|
|
32
|
+
{ 'type' => 'message', 'content' => [{ 'type' => 'output_text', 'text' => 'Answer' }] },
|
|
33
|
+
reasoning_item('Third point')
|
|
34
|
+
)
|
|
35
|
+
original = Marshal.dump(response)
|
|
36
|
+
|
|
37
|
+
assert_equal 'First point Second point Third point', LLM::Responses.reasoning(response)
|
|
38
|
+
assert_equal original, Marshal.dump(response)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_responses_with_only_encrypted_reasoning
|
|
42
|
+
response = responses(reasoning_item.merge('encrypted_content' => 'opaque-state'))
|
|
43
|
+
assert_nil LLM::Responses.reasoning(response)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_responses_without_reasoning
|
|
47
|
+
response = responses(
|
|
48
|
+
{ 'type' => 'message', 'content' => [{ 'type' => 'output_text', 'text' => 'Answer' }] }
|
|
49
|
+
)
|
|
50
|
+
assert_nil LLM::Responses.reasoning(response)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_legacy_chat_reasoning_content
|
|
54
|
+
response = chat('reasoning_content' => "Legacy\ntext")
|
|
55
|
+
assert_equal 'Legacy text', LLM::OpenAI.reasoning(response)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_openrouter_chat_reasoning
|
|
59
|
+
assert_equal 'Summary', LLM::OpenAI.reasoning(chat('reasoning' => 'Summary'))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_chat_does_not_duplicate_text_from_reasoning_details
|
|
63
|
+
response = chat(
|
|
64
|
+
'reasoning' => 'Summary',
|
|
65
|
+
'reasoning_details' => [
|
|
66
|
+
{ 'type' => 'reasoning.summary', 'summary' => 'Summary' },
|
|
67
|
+
{ 'type' => 'reasoning.encrypted', 'data' => 'opaque-state' }
|
|
68
|
+
]
|
|
69
|
+
)
|
|
70
|
+
assert_equal 'Summary', LLM::OpenAI.reasoning(response)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_chat_falls_back_to_readable_reasoning_details
|
|
74
|
+
response = chat('reasoning_details' => [
|
|
75
|
+
{ 'type' => 'reasoning.summary', 'summary' => 'Summary' },
|
|
76
|
+
{ 'type' => 'reasoning.encrypted', 'data' => 'opaque-state' },
|
|
77
|
+
{ 'type' => 'reasoning.text', 'text' => 'More text' }
|
|
78
|
+
])
|
|
79
|
+
assert_equal 'Summary More text', LLM::OpenAI.reasoning(response)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_empty_legacy_chat_field_falls_back_to_reasoning
|
|
83
|
+
response = chat('reasoning_content' => '', 'reasoning' => 'Summary')
|
|
84
|
+
assert_equal 'Summary', LLM::OpenAI.reasoning(response)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_chat_with_only_encrypted_reasoning
|
|
88
|
+
response = chat('reasoning_details' => [
|
|
89
|
+
{ 'type' => 'reasoning.encrypted', 'data' => 'opaque-state' }
|
|
90
|
+
])
|
|
91
|
+
assert_nil LLM::OpenAI.reasoning(response)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def test_empty_response_shapes
|
|
95
|
+
[nil, {}, { 'choices' => [] }, { 'choices' => [nil] }].each do |response|
|
|
96
|
+
assert_nil LLM::Responses.reasoning(response)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def test_unreadable_summary_entries_are_skipped
|
|
101
|
+
response = responses(
|
|
102
|
+
nil,
|
|
103
|
+
{ 'type' => 'reasoning', 'summary' => nil },
|
|
104
|
+
{ 'type' => 'reasoning', 'summary' => [
|
|
105
|
+
nil, {},
|
|
106
|
+
{ 'type' => 'unknown', 'text' => 'Not a summary' },
|
|
107
|
+
{ 'type' => 'summary_text', 'text' => 123 },
|
|
108
|
+
{ 'type' => 'summary_text', 'text' => ' ' },
|
|
109
|
+
{ 'type' => 'summary_text', 'text' => 'Valid summary' }
|
|
110
|
+
] }
|
|
111
|
+
)
|
|
112
|
+
assert_equal 'Valid summary', LLM::Responses.reasoning(response)
|
|
113
|
+
end
|
|
114
|
+
end
|