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,131 @@
|
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
|
2
|
+
require 'scout/llm/chat'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'open3'
|
|
5
|
+
require 'rbconfig'
|
|
6
|
+
require 'timeout'
|
|
7
|
+
require_relative 'agent_meta_fixtures'
|
|
8
|
+
|
|
9
|
+
# Explanatory-plot fixture builder for the prov `--dot`/`--plot`/`--timeline`
|
|
10
|
+
# section.
|
|
11
|
+
#
|
|
12
|
+
# Mirrors the real `test_simplify_delegation` hierarchy (in
|
|
13
|
+
# test/scout/llm/chat/test_simplify.rb) inside a TmpFile dir, using the
|
|
14
|
+
# AgentMetaFixtures helpers instead of bespoke file surgery so the dot
|
|
15
|
+
# tests exercise the same traversal path as the tree/flow ones:
|
|
16
|
+
#
|
|
17
|
+
# root.chat (Manager) note, root
|
|
18
|
+
# +- .files/agent.society/{Searcher,Worker}/... 3 society chats
|
|
19
|
+
# +- receipts: 6 delegated Cortex/continue jobs
|
|
20
|
+
# echo-worker, cortex-smoke x3 (SAME clean_name; continuation
|
|
21
|
+
# chain ordered by explicit File.utime), cortex-unknown-brief,
|
|
22
|
+
# cortex-bad-brief (status=error, no .files)
|
|
23
|
+
# each success job logs Worker.chat (cumulative replay per turn)
|
|
24
|
+
#
|
|
25
|
+
# Timeline schedule: every stamped node gets ONE coherent time applied BOTH
|
|
26
|
+
# as chat-content meta `timestamp=` fields and as File.mtime (job mtime =
|
|
27
|
+
# the END of its chat), so the timeline view's chat-content priority and
|
|
28
|
+
# its mtime fallback agree on the order and the flow view's mtime-ordered
|
|
29
|
+
# continuation chain is untouched. Cumulative chain replays share their
|
|
30
|
+
# first turn's timestamp, so chain chats are ordered by (start, end, path).
|
|
31
|
+
# The smoke family is contiguous in the resulting sequence, so the temporal
|
|
32
|
+
# cluster rule fires on this fixture; the root and the error job carry NO
|
|
33
|
+
# chat timestamps on purpose, exercising the mtime-fallback badge.
|
|
34
|
+
module ProvPlotFixtures
|
|
35
|
+
# Seconds after `base` (base = Time.now.utc - 600): root 0, society
|
|
36
|
+
# chats 10/44/50, echo 30, smoke turns 60/95/110 (cumulative chats span
|
|
37
|
+
# 60->95 and 60->110), unknown 130->140, error job 150.
|
|
38
|
+
TIMELINE_OFFSETS = {
|
|
39
|
+
root: 0, society_searcher: 10, echo: 30, society_worker: 44,
|
|
40
|
+
society_mgr: 50, smoke: [60, 95, 110], unknown: [130, 140], bad: 150
|
|
41
|
+
}.freeze
|
|
42
|
+
|
|
43
|
+
# Returns a named Hash: {root: root_chat, jobs: {echo:, smoke:
|
|
44
|
+
# [turn1, turn2, turn3], unknown:, bad:}, society: society_chats,
|
|
45
|
+
# schedule: schedule}. `schedule` maps every stamped node
|
|
46
|
+
# path to its [start, end] Time pair; the timeline tests recompute the
|
|
47
|
+
# event sequence, the cluster outcome and the overlap flags from it
|
|
48
|
+
# instead of trusting the spec's ASSUMED order.
|
|
49
|
+
def explanatory_fixture(dir)
|
|
50
|
+
base = Time.now.utc - 600
|
|
51
|
+
iso = lambda { |time| time.utc.iso8601 }
|
|
52
|
+
worker_chat = lambda do |turns, times|
|
|
53
|
+
(1..turns).collect do |i|
|
|
54
|
+
"user: turn #{i}\nmeta: pt=27000 ct=95 tt=27100 inference_id=s#{i} " \
|
|
55
|
+
"timestamp=#{iso.call(times[i - 1])}\nassistant: ok#{i}\n"
|
|
56
|
+
end * ''
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
echo_time = base + TIMELINE_OFFSETS[:echo]
|
|
60
|
+
smoke_times = TIMELINE_OFFSETS[:smoke].collect { |offset| base + offset }
|
|
61
|
+
unknown_times = TIMELINE_OFFSETS[:unknown].collect { |offset| base + offset }
|
|
62
|
+
|
|
63
|
+
echo = make_job(dir, 'Cortex/continue/echo-worker_f44dbdeb0c47d569454e8276ea39de5e.chat',
|
|
64
|
+
info: {workflow: 'Cortex', task_name: 'continue', clean_name: 'echo-worker'},
|
|
65
|
+
logs: {'Worker.chat' => worker_chat.call(1, [echo_time])})
|
|
66
|
+
smoke = [
|
|
67
|
+
make_job(dir, 'Cortex/continue/cortex-smoke_115194274cd0f8e93ec792fe4c73deba.chat',
|
|
68
|
+
info: {workflow: 'Cortex', task_name: 'continue', clean_name: 'cortex-smoke'},
|
|
69
|
+
logs: {'Worker.chat' => worker_chat.call(1, smoke_times[0, 1])}),
|
|
70
|
+
make_job(dir, 'Cortex/continue/cortex-smoke_e82f128e92d0e62380defe56a7220c10.chat',
|
|
71
|
+
info: {workflow: 'Cortex', task_name: 'continue', clean_name: 'cortex-smoke'},
|
|
72
|
+
logs: {'Worker.chat' => worker_chat.call(2, smoke_times[0, 2])}),
|
|
73
|
+
make_job(dir, 'Cortex/continue/cortex-smoke_a8f0e48e3aa9e5e127490869ccef6e3d.chat',
|
|
74
|
+
info: {workflow: 'Cortex', task_name: 'continue', clean_name: 'cortex-smoke'},
|
|
75
|
+
logs: {'Worker.chat' => worker_chat.call(3, smoke_times)})
|
|
76
|
+
]
|
|
77
|
+
unknown = make_job(dir, 'Cortex/continue/cortex-unknown-brief_ec60777c00847dfd02ea4d33b24895e3.chat',
|
|
78
|
+
info: {workflow: 'Cortex', task_name: 'continue', clean_name: 'cortex-unknown-brief'},
|
|
79
|
+
logs: {'Worker.chat' => worker_chat.call(2, unknown_times)})
|
|
80
|
+
bad = make_job(dir, 'Cortex/continue/cortex-bad-brief_56de1491208492552873b7fd299efe02.chat',
|
|
81
|
+
result: '',
|
|
82
|
+
info: {workflow: 'Cortex', task_name: 'continue', clean_name: 'cortex-bad-brief',
|
|
83
|
+
status: 'error', exception: '{"m":"No brief unknown-brief for agent Worker"}'})
|
|
84
|
+
|
|
85
|
+
society_chats = []
|
|
86
|
+
root = write_chat(dir, 'root.chat',
|
|
87
|
+
receipt_chat_text(
|
|
88
|
+
{'r1' => [echo, *smoke, unknown, bad].collect { |job| meta_receipt("job=#{job}") }}
|
|
89
|
+
))
|
|
90
|
+
|
|
91
|
+
society_times = [['Searcher', 'default', TIMELINE_OFFSETS[:society_searcher]],
|
|
92
|
+
['Worker', 'default', TIMELINE_OFFSETS[:society_worker]],
|
|
93
|
+
['Worker', 'mgr-social-smoke', TIMELINE_OFFSETS[:society_mgr]]]
|
|
94
|
+
society_times = society_times.collect do |agent, conv, offset|
|
|
95
|
+
path = File.join(root + '.files', 'agent.society', agent, conv, 'agent.chat')
|
|
96
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
97
|
+
time = base + offset
|
|
98
|
+
File.write(path, "user: #{agent} #{conv}\nmeta: pt=12000 ct=100 tt=12700 " \
|
|
99
|
+
"inference_id=#{agent}#{conv} timestamp=#{iso.call(time)}\nassistant: done\n")
|
|
100
|
+
society_chats << path
|
|
101
|
+
[path, time]
|
|
102
|
+
end.to_h
|
|
103
|
+
|
|
104
|
+
# Stamp every fixture file with its schedule time AFTER all files exist
|
|
105
|
+
# (make_job writes at the same second, so file-creation order would be
|
|
106
|
+
# a coin flip). The smoke jobs keep a strictly monotonic mtime
|
|
107
|
+
# sequence (60 < 95 < 110), so the flow view's continuation chain
|
|
108
|
+
# ordering and turn numbering are unchanged by the schedule.
|
|
109
|
+
schedule = {}
|
|
110
|
+
stamp = lambda do |path, start_time, end_time|
|
|
111
|
+
File.utime(end_time, end_time, path)
|
|
112
|
+
schedule[path] = [start_time, end_time]
|
|
113
|
+
end
|
|
114
|
+
stamp.call(root, base, base)
|
|
115
|
+
stamp.call(echo, echo_time, echo_time)
|
|
116
|
+
stamp.call(File.join(echo + '.files', 'Worker.chat'), echo_time, echo_time)
|
|
117
|
+
smoke.each_with_index do |job, index|
|
|
118
|
+
stamp.call(job, smoke_times[index], smoke_times[index])
|
|
119
|
+
stamp.call(File.join(job + '.files', 'Worker.chat'), smoke_times.first, smoke_times[index])
|
|
120
|
+
end
|
|
121
|
+
stamp.call(unknown, unknown_times.last, unknown_times.last)
|
|
122
|
+
stamp.call(File.join(unknown + '.files', 'Worker.chat'), unknown_times.first, unknown_times.last)
|
|
123
|
+
stamp.call(bad, base + TIMELINE_OFFSETS[:bad], base + TIMELINE_OFFSETS[:bad])
|
|
124
|
+
society_times.each { |path, time| stamp.call(path, time, time) }
|
|
125
|
+
|
|
126
|
+
{root: root,
|
|
127
|
+
jobs: {echo: echo, smoke: smoke, unknown: unknown, bad: bad},
|
|
128
|
+
society: society_chats,
|
|
129
|
+
schedule: schedule}
|
|
130
|
+
end
|
|
131
|
+
end
|
|
@@ -2,15 +2,16 @@ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
|
|
2
2
|
require 'scout/llm/chat'
|
|
3
3
|
|
|
4
4
|
class TestChatAgentMeta < Test::Unit::TestCase
|
|
5
|
+
|
|
5
6
|
def chat(text)
|
|
6
7
|
Chat.setup(LLM.messages(text))
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
# Build persisted-style chat text with one paired tool call whose output
|
|
10
|
-
# envelope carries a receipt
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
11
|
+
# envelope carries a receipt under the `meta` key with an array of
|
|
12
|
+
# already-deserialized field Hashes (as LLM.process_calls writes for
|
|
13
|
+
# delegated agents). The `agent_meta` kwarg forces the LEGACY envelope
|
|
14
|
+
# key; the current reader does not accept it (deliberate breakage).
|
|
14
15
|
def receipt_text(agent_meta: nil, meta: nil, name: 'ask', call_id: 'call-1', content: 'child answer')
|
|
15
16
|
envelope = {name: name, content: content, id: call_id}
|
|
16
17
|
envelope[:agent_meta] = agent_meta unless agent_meta.nil?
|
|
@@ -22,7 +23,7 @@ function_call_output: #{envelope.to_json}
|
|
|
22
23
|
EOF
|
|
23
24
|
end
|
|
24
25
|
|
|
25
|
-
# Current-format
|
|
26
|
+
# Current-format receipt: `meta` key carrying deserialized field Hashes.
|
|
26
27
|
def valid_meta_receipt
|
|
27
28
|
receipt_text(meta: [
|
|
28
29
|
{'pt' => 100, 'ct' => 50, 'tt' => 150, 'inference_id' => 'aaa'},
|
|
@@ -30,15 +31,8 @@ function_call_output: #{envelope.to_json}
|
|
|
30
31
|
])
|
|
31
32
|
end
|
|
32
33
|
|
|
33
|
-
def valid_receipt
|
|
34
|
-
receipt_text(agent_meta: [
|
|
35
|
-
{role: 'meta', content: 'pt=100 ct=50 tt=150 inference_id=aaa'},
|
|
36
|
-
{role: 'meta', content: 'job=Worker/ask/Default_x'}
|
|
37
|
-
])
|
|
38
|
-
end
|
|
39
|
-
|
|
40
34
|
def test_extracts_valid_receipt_entries
|
|
41
|
-
evidence = Chat.agent_meta_evidence(chat(
|
|
35
|
+
evidence = Chat.agent_meta_evidence(chat(valid_meta_receipt))
|
|
42
36
|
assert_equal 2, evidence.length
|
|
43
37
|
|
|
44
38
|
direct, projection = evidence
|
|
@@ -52,19 +46,19 @@ function_call_output: #{envelope.to_json}
|
|
|
52
46
|
assert_equal 'ask', direct[:tool_name]
|
|
53
47
|
assert_equal 0, direct[:agent_meta_index]
|
|
54
48
|
assert_equal 2, direct[:output_address]
|
|
55
|
-
assert_equal [2, :
|
|
49
|
+
assert_equal [2, :meta, 0], direct[:evidence_address]
|
|
56
50
|
assert_nil direct[:source]
|
|
57
|
-
|
|
51
|
+
assert_nil direct[:raw_message]
|
|
58
52
|
|
|
59
53
|
assert_equal 1, projection[:agent_meta_index]
|
|
60
|
-
assert_equal [2, :
|
|
54
|
+
assert_equal [2, :meta, 1], projection[:evidence_address]
|
|
61
55
|
assert_equal 'Worker/ask/Default_x', projection[:meta][:job]
|
|
62
56
|
end
|
|
63
57
|
|
|
64
58
|
def test_extracts_receipt_entries_from_persisted_file_with_source
|
|
65
59
|
TmpFile.with_dir do |dir|
|
|
66
60
|
path = File.join(dir, 'parent.chat')
|
|
67
|
-
Open.write(path,
|
|
61
|
+
Open.write(path, valid_meta_receipt)
|
|
68
62
|
conversation = Chat.load(path)
|
|
69
63
|
|
|
70
64
|
evidence = Chat.agent_meta_evidence(conversation, source: path)
|
|
@@ -73,11 +67,11 @@ function_call_output: #{envelope.to_json}
|
|
|
73
67
|
direct = evidence.first
|
|
74
68
|
assert_equal path, direct[:source]
|
|
75
69
|
assert_equal [path, 2], direct[:output_address]
|
|
76
|
-
assert_equal [path, 2, :
|
|
70
|
+
assert_equal [path, 2, :meta, 0], direct[:evidence_address]
|
|
77
71
|
assert_equal 'call-1', direct[:call_id]
|
|
78
72
|
assert_equal 'ask', direct[:tool_name]
|
|
79
73
|
|
|
80
|
-
assert_equal [path, 2, :
|
|
74
|
+
assert_equal [path, 2, :meta, 1], evidence.last[:evidence_address]
|
|
81
75
|
end
|
|
82
76
|
end
|
|
83
77
|
|
|
@@ -94,7 +88,7 @@ assistant: Hi
|
|
|
94
88
|
|
|
95
89
|
def test_agent_meta_not_an_array_is_skipped_with_warning
|
|
96
90
|
warnings = []
|
|
97
|
-
evidence = Chat.agent_meta_evidence(chat(receipt_text(
|
|
91
|
+
evidence = Chat.agent_meta_evidence(chat(receipt_text(meta: 'oops')), warnings: warnings)
|
|
98
92
|
assert_equal [], evidence
|
|
99
93
|
assert_equal 1, warnings.length
|
|
100
94
|
|
|
@@ -110,7 +104,7 @@ assistant: Hi
|
|
|
110
104
|
|
|
111
105
|
def test_non_hash_entry_is_skipped_with_warning
|
|
112
106
|
warnings = []
|
|
113
|
-
evidence = Chat.agent_meta_evidence(chat(receipt_text(
|
|
107
|
+
evidence = Chat.agent_meta_evidence(chat(receipt_text(meta: ['nonsense'])), warnings: warnings)
|
|
114
108
|
assert_equal [], evidence
|
|
115
109
|
assert_equal 1, warnings.length
|
|
116
110
|
assert_equal :not_a_hash, warnings.first[:reason]
|
|
@@ -118,52 +112,8 @@ assistant: Hi
|
|
|
118
112
|
assert_equal 'nonsense', warnings.first[:raw_entry]
|
|
119
113
|
end
|
|
120
114
|
|
|
121
|
-
def test_entry_with_wrong_role_is_skipped_with_warning
|
|
122
|
-
warnings = []
|
|
123
|
-
agent_meta = [
|
|
124
|
-
{role: 'assistant', content: 'not a meta record'},
|
|
125
|
-
{role: 'meta', content: 'pt=1 tt=1 inference_id=keep'}
|
|
126
|
-
]
|
|
127
|
-
evidence = Chat.agent_meta_evidence(chat(receipt_text(agent_meta: agent_meta)), warnings: warnings)
|
|
128
|
-
assert_equal 1, evidence.length
|
|
129
|
-
assert_equal 1, warnings.length
|
|
130
|
-
assert_equal :invalid_role, warnings.first[:reason]
|
|
131
|
-
assert_equal 0, warnings.first[:agent_meta_index]
|
|
132
|
-
assert_equal({ 'role' => 'assistant', 'content' => 'not a meta record' }, warnings.first[:raw_entry])
|
|
133
|
-
assert_equal [2, :agent_meta, 1], evidence.first[:evidence_address]
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
def test_entry_without_string_content_is_skipped_with_warning
|
|
137
|
-
warnings = []
|
|
138
|
-
agent_meta = [
|
|
139
|
-
{role: 'meta'},
|
|
140
|
-
{role: 'meta', content: 42},
|
|
141
|
-
{role: 'meta', content: 'pt=1 tt=1 inference_id=keep'}
|
|
142
|
-
]
|
|
143
|
-
evidence = Chat.agent_meta_evidence(chat(receipt_text(agent_meta: agent_meta)), warnings: warnings)
|
|
144
|
-
assert_equal 1, evidence.length
|
|
145
|
-
assert_equal 2, warnings.length
|
|
146
|
-
assert_equal %i[invalid_content invalid_content], warnings.collect { |w| w[:reason] }
|
|
147
|
-
assert_equal 0, warnings.first[:agent_meta_index]
|
|
148
|
-
assert_equal 1, warnings.last[:agent_meta_index]
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
def test_unparseable_content_is_skipped_with_warning
|
|
152
|
-
warnings = []
|
|
153
|
-
evidence = Chat.agent_meta_evidence(chat(receipt_text(agent_meta: [{role: 'meta', content: 'no key value pairs here'}])), warnings: warnings)
|
|
154
|
-
assert_equal [], evidence
|
|
155
|
-
assert_equal 1, warnings.length
|
|
156
|
-
assert_equal :unparseable_meta, warnings.first[:reason]
|
|
157
|
-
assert_equal 0, warnings.first[:agent_meta_index]
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
def test_malformed_entries_are_skipped_without_warnings_kwarg
|
|
161
|
-
evidence = Chat.agent_meta_evidence(chat(receipt_text(agent_meta: [{role: 'assistant', content: 'x'}])))
|
|
162
|
-
assert_equal [], evidence
|
|
163
|
-
end
|
|
164
|
-
|
|
165
115
|
def test_meta_evidence_combines_both_origins
|
|
166
|
-
text =
|
|
116
|
+
text = valid_meta_receipt + "\nmeta: pt=10 tt=12 inference_id=local1\nassistant: done\n"
|
|
167
117
|
conversation = chat(text)
|
|
168
118
|
|
|
169
119
|
evidence = Chat.meta_evidence(conversation)
|
|
@@ -186,19 +136,19 @@ assistant: Hi
|
|
|
186
136
|
def test_meta_evidence_preserves_source_addresses
|
|
187
137
|
TmpFile.with_dir do |dir|
|
|
188
138
|
path = File.join(dir, 'parent.chat')
|
|
189
|
-
Open.write(path,
|
|
139
|
+
Open.write(path, valid_meta_receipt + "\nmeta: pt=10 tt=12 inference_id=local1\nassistant: done\n")
|
|
190
140
|
conversation = Chat.load(path)
|
|
191
141
|
|
|
192
142
|
evidence = Chat.meta_evidence(conversation, source: path)
|
|
193
143
|
assert_equal [path, 3], evidence.first[:meta_address]
|
|
194
|
-
assert_equal [path, 2, :
|
|
195
|
-
assert_equal [path, 2, :
|
|
144
|
+
assert_equal [path, 2, :meta, 0], evidence[1][:evidence_address]
|
|
145
|
+
assert_equal [path, 2, :meta, 1], evidence[2][:evidence_address]
|
|
196
146
|
assert evidence.all? { |record| record[:source] == path }
|
|
197
147
|
end
|
|
198
148
|
end
|
|
199
149
|
|
|
200
150
|
def test_extraction_does_not_change_chat_contents
|
|
201
|
-
conversation = chat(
|
|
151
|
+
conversation = chat(valid_meta_receipt + "\nmeta: pt=10 tt=12 inference_id=local1\nassistant: done\n")
|
|
202
152
|
before = conversation.collect { |message| [message[:role].to_s, message[:content].to_s] }
|
|
203
153
|
|
|
204
154
|
Chat.agent_meta_evidence(conversation)
|
|
@@ -214,7 +164,7 @@ assistant: Hi
|
|
|
214
164
|
end
|
|
215
165
|
|
|
216
166
|
def test_agent_meta_job_references_returns_only_job_records
|
|
217
|
-
conversation = chat(
|
|
167
|
+
conversation = chat(valid_meta_receipt)
|
|
218
168
|
references = Chat.agent_meta_job_references(conversation)
|
|
219
169
|
|
|
220
170
|
assert_equal 1, references.length
|
|
@@ -225,15 +175,15 @@ assistant: Hi
|
|
|
225
175
|
assert_equal 'call-1', reference[:call_id]
|
|
226
176
|
assert_equal 'ask', reference[:tool_name]
|
|
227
177
|
assert_equal 1, reference[:agent_meta_index]
|
|
228
|
-
assert_equal [2, :
|
|
178
|
+
assert_equal [2, :meta, 1], reference[:evidence_address]
|
|
229
179
|
|
|
230
180
|
TmpFile.with_dir do |dir|
|
|
231
181
|
path = File.join(dir, 'parent.chat')
|
|
232
|
-
Open.write(path,
|
|
182
|
+
Open.write(path, valid_meta_receipt)
|
|
233
183
|
with_source = Chat.agent_meta_job_references(Chat.load(path), source: path)
|
|
234
184
|
assert_equal 1, with_source.length
|
|
235
185
|
assert_equal 'Worker/ask/Default_x', with_source.first[:job]
|
|
236
|
-
assert_equal [path, 2, :
|
|
186
|
+
assert_equal [path, 2, :meta, 1], with_source.first[:evidence_address]
|
|
237
187
|
end
|
|
238
188
|
end
|
|
239
189
|
|
|
@@ -260,8 +210,8 @@ assistant: Hi
|
|
|
260
210
|
end
|
|
261
211
|
|
|
262
212
|
def test_agent_meta_is_not_limited_to_ask_tool
|
|
263
|
-
|
|
264
|
-
evidence = Chat.agent_meta_evidence(chat(receipt_text(
|
|
213
|
+
meta_entries = [Chat.parse_meta('pt=7 tt=7 inference_id=other')]
|
|
214
|
+
evidence = Chat.agent_meta_evidence(chat(receipt_text(meta: meta_entries, name: 'chat_task', call_id: 'call-9')))
|
|
265
215
|
assert_equal 1, evidence.length
|
|
266
216
|
assert_equal 'chat_task', evidence.first[:tool_name]
|
|
267
217
|
assert_equal 'call-9', evidence.first[:call_id]
|
|
@@ -293,10 +243,20 @@ assistant: Hi
|
|
|
293
243
|
assert_equal :agent_meta, references.first[:origin]
|
|
294
244
|
end
|
|
295
245
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
246
|
+
# Deliberate breakage (plan B2): the legacy `agent_meta` envelope key is no
|
|
247
|
+
# longer accepted. A legacy-only receipt produces NO evidence at all, and a
|
|
248
|
+
# mixed envelope ignores the legacy key entirely.
|
|
249
|
+
def test_legacy_agent_meta_envelope_produces_no_evidence
|
|
250
|
+
legacy_only = receipt_text(agent_meta: [{role: 'meta', content: 'pt=100 tt=150 inference_id=aaa'}])
|
|
251
|
+
warnings = []
|
|
252
|
+
assert_equal [], Chat.agent_meta_evidence(chat(legacy_only), warnings: warnings)
|
|
253
|
+
assert_empty warnings, 'the legacy key is not a receipt: nothing to warn about'
|
|
254
|
+
|
|
255
|
+
assert_equal [], Chat.agent_meta_job_references(chat(legacy_only))
|
|
256
|
+
|
|
257
|
+
mixed = receipt_text(meta: [{'tt' => 1}],
|
|
258
|
+
agent_meta: [{role: 'meta', content: 'tt=2'}])
|
|
259
|
+
evidence = Chat.agent_meta_evidence(chat(mixed))
|
|
300
260
|
assert_equal 1, evidence.length
|
|
301
261
|
assert_equal 1, evidence.first[:meta][:tt]
|
|
302
262
|
assert_equal :meta, evidence.first[:evidence_address][1]
|