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
data/lib/scout/llm/tools.rb
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
require 'scout/knowledge_base'
|
|
2
2
|
require_relative 'tools/mcp'
|
|
3
|
+
require_relative 'tools/definition'
|
|
3
4
|
require_relative 'tools/workflow'
|
|
4
5
|
require_relative 'tools/knowledge_base'
|
|
5
6
|
require_relative 'tools/call'
|
|
6
7
|
module LLM
|
|
8
|
+
# Keep the historical two-argument tool callback contract. A context-aware
|
|
9
|
+
# callback opts in by accepting a third positional argument (including a
|
|
10
|
+
# splat); this matters for strict lambdas, which raise on extra arguments.
|
|
11
|
+
def self.call_tool_callback(block, function_name, function_arguments, request_context)
|
|
12
|
+
if block && (block.arity == 3 || block.arity < 0)
|
|
13
|
+
block.call function_name, function_arguments, request_context
|
|
14
|
+
else
|
|
15
|
+
block.call function_name, function_arguments
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
7
19
|
def self.call_tools(tool_calls, &block)
|
|
8
20
|
tool_calls.collect{|tool_call|
|
|
9
21
|
response_message = LLM.tool_response(tool_call, &block)
|
|
@@ -16,7 +28,7 @@ module LLM
|
|
|
16
28
|
}.flatten
|
|
17
29
|
end
|
|
18
30
|
|
|
19
|
-
def self.tool_response(tool_call, &block)
|
|
31
|
+
def self.tool_response(tool_call, request_context: nil, &block)
|
|
20
32
|
tool_call_id = tool_call.dig("call_id") || tool_call.dig("id")
|
|
21
33
|
if tool_call['function']
|
|
22
34
|
function_name = tool_call.dig("function", "name")
|
|
@@ -31,7 +43,7 @@ module LLM
|
|
|
31
43
|
Log.high "Calling function #{function_name} with arguments #{Log.fingerprint function_arguments}"
|
|
32
44
|
|
|
33
45
|
function_response = begin
|
|
34
|
-
block
|
|
46
|
+
LLM.call_tool_callback(block, function_name, function_arguments, request_context)
|
|
35
47
|
rescue
|
|
36
48
|
$!
|
|
37
49
|
end
|
|
@@ -53,43 +65,4 @@ module LLM
|
|
|
53
65
|
content: content
|
|
54
66
|
}
|
|
55
67
|
end
|
|
56
|
-
|
|
57
|
-
def self.run_tools(messages)
|
|
58
|
-
messages.collect do |info|
|
|
59
|
-
IndiferentHash.setup(info)
|
|
60
|
-
role = info[:role]
|
|
61
|
-
if role == 'cmd'
|
|
62
|
-
{
|
|
63
|
-
role: 'tool',
|
|
64
|
-
content: CMD.cmd(info[:content]).read
|
|
65
|
-
}
|
|
66
|
-
else
|
|
67
|
-
info
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
#def self.tools_to_openai(messages)
|
|
73
|
-
# messages.collect do |message|
|
|
74
|
-
# if message[:role] == 'function_call'
|
|
75
|
-
# tool_call = IndiferentHash.setup(JSON.parse(message[:content]))
|
|
76
|
-
# arguments = tool_call.delete('arguments') || {}
|
|
77
|
-
# name = tool_call[:name]
|
|
78
|
-
# tool_call['type'] = 'function'
|
|
79
|
-
# tool_call['function'] ||= {}
|
|
80
|
-
# tool_call['function']['name'] ||= name || 'function'
|
|
81
|
-
# tool_call['function']['arguments'] = arguments.to_json
|
|
82
|
-
# {role: 'assistant', tool_calls: [tool_call]}
|
|
83
|
-
# elsif message[:role] == 'function_call_output'
|
|
84
|
-
# info = JSON.parse(message[:content])
|
|
85
|
-
# id = info.delete('call_id') || info.dig('id')
|
|
86
|
-
# info['role'] = 'tool'
|
|
87
|
-
# info['tool_call_id'] = id
|
|
88
|
-
# info
|
|
89
|
-
# else
|
|
90
|
-
# message
|
|
91
|
-
# end
|
|
92
|
-
# end.flatten
|
|
93
|
-
#end
|
|
94
|
-
|
|
95
68
|
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require_relative '../base'
|
|
2
|
+
|
|
3
|
+
class Decision < ScoutModel
|
|
4
|
+
|
|
5
|
+
attr_reader :questions
|
|
6
|
+
|
|
7
|
+
def initialize(directory = nil, options = {})
|
|
8
|
+
super
|
|
9
|
+
@questions = options[:questions] || {}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def eval(input)
|
|
13
|
+
normalize(query(input))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def eval_list(inputs)
|
|
17
|
+
inputs.map { |input| eval(input) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def specification
|
|
21
|
+
{ questions: @questions }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
protected
|
|
25
|
+
|
|
26
|
+
def query(_input)
|
|
27
|
+
raise NotImplementedError
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def normalize(raw)
|
|
31
|
+
Result.new(raw, self)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class Result
|
|
35
|
+
attr_reader :value, :model
|
|
36
|
+
|
|
37
|
+
def initialize(value, model)
|
|
38
|
+
@value = value
|
|
39
|
+
@model = model
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base'
|
|
4
|
+
require "json"
|
|
5
|
+
require "net/http"
|
|
6
|
+
require "uri"
|
|
7
|
+
|
|
8
|
+
class Decision
|
|
9
|
+
class Jev < Decision
|
|
10
|
+
DEFAULT_URL = "https://api.typesafe.ai/v1/systemone"
|
|
11
|
+
DEFAULT_MODEL = "jev-latest"
|
|
12
|
+
|
|
13
|
+
RETRYABLE_STATUS = [429, 529].freeze
|
|
14
|
+
|
|
15
|
+
class Error < StandardError
|
|
16
|
+
attr_reader :status, :body
|
|
17
|
+
|
|
18
|
+
def initialize(message, status: nil, body: nil)
|
|
19
|
+
super(message)
|
|
20
|
+
@status = status
|
|
21
|
+
@body = body
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class Client
|
|
26
|
+
def initialize(
|
|
27
|
+
api_key: Scout::Config.get(:key, :jev, env: 'TYPESAFE_API_KEY'),
|
|
28
|
+
url: DEFAULT_URL,
|
|
29
|
+
open_timeout: 10,
|
|
30
|
+
read_timeout: 120,
|
|
31
|
+
max_retries: 2,
|
|
32
|
+
retry_base: 0.25,
|
|
33
|
+
http_factory: nil,
|
|
34
|
+
sleeper: nil
|
|
35
|
+
)
|
|
36
|
+
raise Error, "TYPESAFE_API_KEY is not configured" if api_key.to_s.empty?
|
|
37
|
+
|
|
38
|
+
@api_key = api_key
|
|
39
|
+
@url = url
|
|
40
|
+
@open_timeout = open_timeout
|
|
41
|
+
@read_timeout = read_timeout
|
|
42
|
+
@max_retries = max_retries
|
|
43
|
+
@retry_base = retry_base
|
|
44
|
+
|
|
45
|
+
@http_factory = http_factory || method(:default_http)
|
|
46
|
+
@sleeper = sleeper || ->(seconds) { sleep(seconds) }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def evaluate(model:, state:, questions:)
|
|
50
|
+
request(
|
|
51
|
+
model: model,
|
|
52
|
+
state: state,
|
|
53
|
+
questions: questions
|
|
54
|
+
)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def request(payload)
|
|
60
|
+
attempts = 0
|
|
61
|
+
|
|
62
|
+
loop do
|
|
63
|
+
response = perform_request(payload)
|
|
64
|
+
status = response.code.to_i
|
|
65
|
+
|
|
66
|
+
return parse_response(response) if status.between?(200, 299)
|
|
67
|
+
|
|
68
|
+
if RETRYABLE_STATUS.include?(status) && attempts < @max_retries
|
|
69
|
+
@sleeper.call(retry_delay(response, attempts))
|
|
70
|
+
attempts += 1
|
|
71
|
+
next
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
raise Error.new(
|
|
75
|
+
"Jev API request failed: HTTP #{status}",
|
|
76
|
+
status: status,
|
|
77
|
+
body: response.body
|
|
78
|
+
)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def perform_request(payload)
|
|
83
|
+
uri = URI.parse(@url)
|
|
84
|
+
http = @http_factory.call(uri)
|
|
85
|
+
|
|
86
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
|
87
|
+
request["Authorization"] = "Bearer #{@api_key}"
|
|
88
|
+
request["Content-Type"] = "application/json"
|
|
89
|
+
request["Accept"] = "application/json"
|
|
90
|
+
request.body = JSON.generate(payload)
|
|
91
|
+
|
|
92
|
+
http.open_timeout = @open_timeout
|
|
93
|
+
http.read_timeout = @read_timeout
|
|
94
|
+
|
|
95
|
+
http.request(request)
|
|
96
|
+
rescue URI::InvalidURIError => e
|
|
97
|
+
raise Error, "Invalid Jev URL: #{e.message}"
|
|
98
|
+
rescue Error
|
|
99
|
+
raise
|
|
100
|
+
rescue StandardError => e
|
|
101
|
+
raise Error, "Jev request failed: #{e.class}: #{e.message}"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def default_http(uri)
|
|
105
|
+
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
|
106
|
+
http.use_ssl = (uri.scheme == "https")
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def parse_response(response)
|
|
111
|
+
JSON.parse(response.body)
|
|
112
|
+
rescue JSON::ParserError => e
|
|
113
|
+
raise Error.new(
|
|
114
|
+
"Jev API returned invalid JSON: #{e.message}",
|
|
115
|
+
status: response.code.to_i,
|
|
116
|
+
body: response.body
|
|
117
|
+
)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def retry_delay(response, attempt)
|
|
121
|
+
retry_after = response["Retry-After"]
|
|
122
|
+
|
|
123
|
+
return retry_after.to_f if retry_after&.match?(/\A\d+(?:\.\d+)?\z/)
|
|
124
|
+
|
|
125
|
+
@retry_base * (2**attempt)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
attr_reader :model, :client
|
|
130
|
+
|
|
131
|
+
def initialize(options = {})
|
|
132
|
+
super(nil, options)
|
|
133
|
+
|
|
134
|
+
@model = options.fetch(:model, DEFAULT_MODEL)
|
|
135
|
+
|
|
136
|
+
@client =
|
|
137
|
+
options[:client] ||
|
|
138
|
+
Client.new(
|
|
139
|
+
**options.slice(
|
|
140
|
+
:api_key,
|
|
141
|
+
:url,
|
|
142
|
+
:open_timeout,
|
|
143
|
+
:read_timeout,
|
|
144
|
+
:max_retries,
|
|
145
|
+
:retry_base
|
|
146
|
+
).compact
|
|
147
|
+
)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
protected
|
|
151
|
+
|
|
152
|
+
def query(input)
|
|
153
|
+
@client.evaluate(
|
|
154
|
+
model: @model,
|
|
155
|
+
state: input,
|
|
156
|
+
questions: @questions
|
|
157
|
+
)
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
@@ -29,7 +29,7 @@ class TorchModel < PythonModel
|
|
|
29
29
|
dtype ||= TorchModel.dtype(options)
|
|
30
30
|
state.to(device)
|
|
31
31
|
@optimizer ||= TorchModel.optimizer(state, options[:training_args] || {})
|
|
32
|
-
@criterion ||= TorchModel.
|
|
32
|
+
@criterion ||= TorchModel.criterion(state, options[:training_args] || {})
|
|
33
33
|
|
|
34
34
|
epochs = options[:training_args][:epochs] || 3
|
|
35
35
|
batch_size = options[:batch_size]
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# `clear_tools` social-inheritance mode — decision record
|
|
2
|
+
|
|
3
|
+
Feature: a fourth `SOCIAL_INHERIT_MODES` entry, `clear_tools`, so that
|
|
4
|
+
continuing a specialist conversation drops earlier bouts' tool-call
|
|
5
|
+
traces (`function_call`/`function_call_output`) from the context sent to
|
|
6
|
+
the model, while the stored chat, logs and provenance keep everything.
|
|
7
|
+
Design packet only — no production code changed here; this note pins the
|
|
8
|
+
decisions and the evidence for the later implementation packet.
|
|
9
|
+
|
|
10
|
+
Hard constraint (user): clearing is context-only. Nothing may be removed
|
|
11
|
+
from stored chats, logs, or provenance.
|
|
12
|
+
|
|
13
|
+
## Adopted semantics (rules 1-7)
|
|
14
|
+
|
|
15
|
+
1. **Mode accepted everywhere `inherit` is**: `SOCIAL_INHERIT_MODES`
|
|
16
|
+
becomes `%w[none tools conversation clear_tools]`. The `ask` tool's
|
|
17
|
+
`enum:` picks it up automatically (delegate.rb references the
|
|
18
|
+
constant); only the separately maintained description string needs an
|
|
19
|
+
edit.
|
|
20
|
+
2. **Continuation (the feature's core)**: when `ask_conversation`
|
|
21
|
+
continues an EXISTING conversation (the `@chats[key]` continuation
|
|
22
|
+
branch, no `restart:`), and `inherit == 'clear_tools'`, append
|
|
23
|
+
`agent.current_chat.message :clear_tools, true` immediately before
|
|
24
|
+
`agent.user(prompt)`. One marker per continuation call; repeated
|
|
25
|
+
markers are equivalent by the reverse scan (probe A, case 5).
|
|
26
|
+
3. **Marker form**: content `true` (truthy), never `'false'` —
|
|
27
|
+
`Chat.clear` treats `content != 'false'` as active, and the
|
|
28
|
+
print/parse round trip turns `true` into String `"true"`, which is
|
|
29
|
+
still active (probe B).
|
|
30
|
+
4. **Insertion site is `ask_conversation`, not `open_conversation`**:
|
|
31
|
+
`load_chat`/`open_conversation` without a following prompt must not
|
|
32
|
+
fire clearing (there is no new round to compile). The implementation
|
|
33
|
+
obtains the "already existed" signal however it likes (pre-check of
|
|
34
|
+
`@chats` under the social key, or a return tweak in
|
|
35
|
+
`open_conversation`); the pinned contract is marker-then-prompt inside
|
|
36
|
+
`ask_conversation` only.
|
|
37
|
+
5. **First creation (and any `restart:`) with `clear_tools`**: seed
|
|
38
|
+
exactly like `'conversation'` (`social_inherited_context` case), no
|
|
39
|
+
marker appended, plus ONE informational `Log.low` line (not a
|
|
40
|
+
warning) naming the fallback. Rationale below.
|
|
41
|
+
6. **No `Chat.tools` change**: the marker never reaches `Chat.tools` in
|
|
42
|
+
the live ask path, so chat-declared tool definitions survive; see
|
|
43
|
+
probe A verdict.
|
|
44
|
+
7. **Both layers already coexist — keep them**: the raw chat-file role
|
|
45
|
+
`clear_tools:` (clear.rb; used by AgentSuite `Planned` via
|
|
46
|
+
`chat.message :clear_tools, true`) remains the low-level marker for
|
|
47
|
+
workflow authors; the inherit mode is the delegation-level policy that
|
|
48
|
+
appends that same marker on continuation. No new chat option is added.
|
|
49
|
+
|
|
50
|
+
## Why these choices (resolved ambiguities)
|
|
51
|
+
|
|
52
|
+
- **(c) Marker vs chat-line tool definitions — definitions INTACT.** The
|
|
53
|
+
hazard in `Chat.tools` (`elsif role == 'clear_tools'; tool_definitions
|
|
54
|
+
= {}`, tools.rb:222) is real only for a DIRECT `Chat.tools` call on a
|
|
55
|
+
marker-bearing chat (probe A, case 1: `[]`). In the live ask path the
|
|
56
|
+
marker is consumed earlier: `LLM.chat` runs `Chat.clear` (chat.rb:53)
|
|
57
|
+
BEFORE any backend resolves tools (`backends/default.rb` `tools()` →
|
|
58
|
+
`LLM.tools` → `Chat.tools`, always on the post-clear message list).
|
|
59
|
+
Probe A cases 2-4: post-clear roles contain no `clear_tools`; tool
|
|
60
|
+
definitions `["hi"]` both via `Chat.tools` on the compiled chat and
|
|
61
|
+
end-to-end through `LLM.ask`. So plain insertion needs no re-append of
|
|
62
|
+
tooling and no special insertion point; the smallest fix consistent
|
|
63
|
+
with clear.rb/tools.rb semantics is NO fix. Keep the tools.rb branch as
|
|
64
|
+
a guard for direct/raw consumers (removing it would change behavior no
|
|
65
|
+
current caller exercises). This consumption ORDER in `LLM.chat` is
|
|
66
|
+
load-bearing and must not be reordered.
|
|
67
|
+
- **(a) Granularity — one marker per continuation call.** The reverse
|
|
68
|
+
scan in `Chat.clear` sets the drop flag at the nearest marker and never
|
|
69
|
+
resets it before the break role, so one marker and N markers drop the
|
|
70
|
+
same set of traces (probe A, case 5: identical definitions and
|
|
71
|
+
model-visible roles with two markers). Appending unconditionally is
|
|
72
|
+
simpler than dedup and proven harmless; stored-chats grow by one
|
|
73
|
+
marker line per continuation.
|
|
74
|
+
- **(b) Creation fallback — 'conversation', silent-with-note.** At
|
|
75
|
+
creation the specialist's own chat has no bouts, so there is nothing of
|
|
76
|
+
its own to clear; seeding like `'conversation'` is the coherent choice
|
|
77
|
+
because that is the mode whose context tool traces can come from. NOT
|
|
78
|
+
chosen: clearing the CALLER's seeded traces at creation — the stated
|
|
79
|
+
problem is the specialist conversation's own accumulation across bouts;
|
|
80
|
+
a caller that wants its context pre-cleared can put a `clear_tools:`
|
|
81
|
+
chat line in its own chat (rule 7). A warning is wrong (nothing failed;
|
|
82
|
+
warnings train users to ignore them); full silence hides a mode
|
|
83
|
+
interaction someone debugging context size will want visible — hence one
|
|
84
|
+
`Log.low` line.
|
|
85
|
+
- **Inherit-mode vs the user's originally suggested plain
|
|
86
|
+
`clear_tools: true` chat option.** The chat role already exists and
|
|
87
|
+
stays; the inherit mode was preferred for the delegation surface
|
|
88
|
+
because the `ask` tool's prompt is appended with `Agent#user`
|
|
89
|
+
(deliberate security boundary: role-looking text in a delegated prompt
|
|
90
|
+
cannot become a control message), so a caller CANNOT inject the marker
|
|
91
|
+
through the tool — the `inherit` enum is the sanctioned channel for
|
|
92
|
+
context policy. Both are provided: chat role for chat authors (Planned
|
|
93
|
+
precedent), inherit mode for `ask`-tool callers.
|
|
94
|
+
- **Hard constraint already holds today.** Probe B: `LLM.chat`, `LLM.ask`
|
|
95
|
+
and a full `Agent#chat` round leave the stored chat untouched — after
|
|
96
|
+
the round the stored roles still contain `clear_tools` AND
|
|
97
|
+
`function_call`/`function_call_output`; only the compiled model view
|
|
98
|
+
drops them. The marker round-trips through `Chat.print`/`Chat.parse`
|
|
99
|
+
(`"clear_tools:\n\ntrue"` → role `clear_tools`, content `"true"`,
|
|
100
|
+
active), so save/reload keeps it working.
|
|
101
|
+
- **Adjacent non-interactions, recorded so nobody re-probes them**: the
|
|
102
|
+
caller's `Chat#tooling` selection (`introduce`/`tool`/`mcp`/`kb`/
|
|
103
|
+
`path_kind`) ignores `clear_tools` markers, so a marker in the caller's
|
|
104
|
+
chat cannot leak into `inherit: 'tools'` seeding; `restart:` re-branches
|
|
105
|
+
from start_chat (no prior content to clear → no marker, rule 5); a
|
|
106
|
+
caller-seeded chat that already contains a `clear_tools` marker copies
|
|
107
|
+
through `social_chat_copy` and behaves under the existing marker
|
|
108
|
+
semantics — coherent, no special handling.
|
|
109
|
+
|
|
110
|
+
## Verification evidence (probes)
|
|
111
|
+
|
|
112
|
+
- Probe A — `tmp/clear-tools-design/probe_compiled_tools.rb`
|
|
113
|
+
(`ruby tmp/clear-tools-design/probe_compiled_tools.rb`), the
|
|
114
|
+
discriminating run. Stored chat: `tool: ProbeCTWF hi` line, one
|
|
115
|
+
user/assistant round WITH a function_call/function_call_output pair,
|
|
116
|
+
then `clear_tools true`, then the follow-up user prompt. Key output:
|
|
117
|
+
- `direct_chat_tools_on_stored_chat: []` (the hazard, direct call only)
|
|
118
|
+
- `compiled_roles_after_llm_chat: [system, tool, user, assistant,
|
|
119
|
+
assistant, user]`, `compiled_marker_present: false`,
|
|
120
|
+
`compiled_function_call_pairs: 0`
|
|
121
|
+
- `chat_tools_on_compiled_chat: ["hi"]`
|
|
122
|
+
- `ask_path_tool_definitions: ["hi"]`,
|
|
123
|
+
`ask_path_model_visible_roles: [system, user, assistant, assistant,
|
|
124
|
+
user]` (mock backend, end-to-end)
|
|
125
|
+
- `repeat_marker_*`: same as single marker.
|
|
126
|
+
- VERDICT: definitions INTACT in the ask pipeline; stripped only for a
|
|
127
|
+
direct `Chat.tools` call on the marker-bearing stored chat.
|
|
128
|
+
- Probe B — `tmp/clear-tools-design/probe_constraints.rb`
|
|
129
|
+
(`ruby tmp/clear-tools-design/probe_constraints.rb`, mock backend via
|
|
130
|
+
`Scout::Config.set({backend: :mock}, :ask, :llm)`). Key output:
|
|
131
|
+
- `stored_roles_after_llm_chat` / `stored_roles_after_llm_ask` still
|
|
132
|
+
contain `clear_tools`, `function_call`, `function_call_output`
|
|
133
|
+
(`llm_chat_mutates: false`, `llm_ask_mutates: false`)
|
|
134
|
+
- `agent_stored_roles_after_round: [..., clear_tools, user,
|
|
135
|
+
assistant]`, `agent_round_preserves_marker_and_traces: true`
|
|
136
|
+
- `Chat.print`/`Chat.parse` round trip: marker survives as String
|
|
137
|
+
`"true"`, active (`!= 'false'`); `Chat.tools` on that recompiled chat
|
|
138
|
+
returns `["hi"]` (the `marker_roundtrip_*` keys in the probe are null
|
|
139
|
+
because that check ran `LLM.chat` — the compiled view — which
|
|
140
|
+
consumes the marker by design; the parse-only round trip was
|
|
141
|
+
confirmed separately: `Chat.parse(Chat.print(chat))` →
|
|
142
|
+
`[["clear_tools","true"],["user","hi"]]`).
|
|
143
|
+
|
|
144
|
+
## Files to change (implementation packet, not done here)
|
|
145
|
+
|
|
146
|
+
- `lib/scout/llm/agent/conversation.rb` — add `'clear_tools'` to
|
|
147
|
+
`SOCIAL_INHERIT_MODES`; `social_inherited_context` case `'clear_tools'`
|
|
148
|
+
→ same as `'conversation'`; `ask_conversation` continuation-branch
|
|
149
|
+
marker append (rule 2/4) with the `Log.low` creation fallback note
|
|
150
|
+
(rule 5).
|
|
151
|
+
- `lib/scout/llm/agent/delegate.rb` — the `inherit` description string
|
|
152
|
+
only (enum already derives from the constant).
|
|
153
|
+
- `test/scout/llm/agent/test_conversation.rb` — pin tests: creation seeds
|
|
154
|
+
like conversation with no marker (+ log note); continuation appends the
|
|
155
|
+
marker before the user prompt; stored chat retains marker and traces
|
|
156
|
+
after a round; repeated continuations equivalent; restart emits no
|
|
157
|
+
marker.
|
|
158
|
+
- `doc/developer/DelegationInternals.md` — mode table row, continuation
|
|
159
|
+
semantics, and the note that `inherit` now has one mode with
|
|
160
|
+
continuation-time behavior (the others remain creation-only).
|
|
161
|
+
- NOT changed: `lib/scout/llm/chat/process/clear.rb`,
|
|
162
|
+
`lib/scout/llm/chat/process/tools.rb` (rule 6).
|
|
163
|
+
|
|
164
|
+
## Working-tree note
|
|
165
|
+
|
|
166
|
+
`lib/scout/llm/chat/process/tools.rb` carries a PRE-EXISTING uncommitted
|
|
167
|
+
modification (the `path_kind` registration moved out of `Chat.tools`;
|
|
168
|
+
commit 9fd2269 follow-up). It belongs to the prior feature, is orthogonal
|
|
169
|
+
to `clear_tools` (the `clear_tools` branch at tools.rb:222 is untouched
|
|
170
|
+
by it), and was left exactly as found. All probe evidence above was
|
|
171
|
+
gathered against the working tree WITH that diff applied.
|