brute 4.3.2 → 5.0.1
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/lib/brute/completion/async_faraday.rb +38 -0
- data/lib/brute/completion/lang_chain.rb +185 -0
- data/lib/brute/completion/llmrb.rb +182 -0
- data/lib/brute/completion/open_router.rb +54 -42
- data/lib/brute/completion/ruby_llm.rb +198 -0
- data/lib/brute/contrib/otel.rb +208 -0
- data/lib/brute/hooks.rb +149 -31
- data/lib/brute/message_transport/lang_chain.rb +36 -0
- data/lib/brute/message_transport/llm.rb +6 -0
- data/lib/brute/message_transport/open_router.rb +6 -0
- data/lib/brute/message_transport/ruby_llm.rb +6 -0
- data/lib/brute/message_transport.rb +8 -0
- data/lib/brute/middleware/000_base.rb +61 -0
- data/lib/brute/middleware/002_session_log.rb +1 -1
- data/lib/brute/middleware/004_summarize.rb +1 -1
- data/lib/brute/middleware/006_loop.rb +1 -1
- data/lib/brute/middleware/008_checkpoint.rb +1 -1
- data/lib/brute/middleware/010_max_iterations.rb +1 -1
- data/lib/brute/middleware/020_system_prompt.rb +1 -1
- data/lib/brute/middleware/025_skills.rb +1 -1
- data/lib/brute/middleware/040_compaction_check.rb +1 -1
- data/lib/brute/middleware/060_questions.rb +1 -1
- data/lib/brute/middleware/070_tool_pipeline.rb +60 -47
- data/lib/brute/middleware/event_handler.rb +1 -1
- data/lib/brute/middleware/user_queue.rb +1 -1
- data/lib/brute/turn/agent_pipeline.rb +3 -4
- data/lib/brute/turn/pipeline.rb +151 -2
- data/lib/brute/usage_detection/lang_chain.rb +44 -0
- data/lib/brute/usage_detection/llmrb.rb +53 -0
- data/lib/brute/usage_detection/open_router.rb +62 -0
- data/lib/brute/usage_detection/ruby_llm.rb +55 -0
- data/lib/brute/usage_detection/usage.rb +51 -0
- data/lib/brute/version.rb +1 -1
- data/lib/brute.rb +94 -3
- metadata +83 -9
- data/lib/brute/changelog.rb +0 -322
- data/lib/brute/deprecate.rb +0 -132
- data/lib/brute/middleware/001_otel_span.rb +0 -79
- data/lib/brute/middleware/005_tracing.rb +0 -94
- data/lib/brute/middleware/015_otel_token_usage.rb +0 -44
- data/lib/brute/middleware/073_otel_tool_call.rb +0 -51
- data/lib/brute/middleware/075_otel_tool_results.rb +0 -48
- data/lib/brute/middleware/open_router.rb +0 -56
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
require "brute"
|
|
5
|
-
|
|
6
|
-
module Brute
|
|
7
|
-
module Middleware
|
|
8
|
-
# Records tool calls the LLM requested as span events.
|
|
9
|
-
#
|
|
10
|
-
# Runs POST-call: after the LLM responds, inspects ctx.functions
|
|
11
|
-
# for any tool calls the model wants to make, and adds a span event
|
|
12
|
-
# for each one with the tool name, call ID, and arguments.
|
|
13
|
-
#
|
|
14
|
-
class OtelToolCalls
|
|
15
|
-
def initialize(app)
|
|
16
|
-
@app = app
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def call(env)
|
|
20
|
-
#response = @app.call(env)
|
|
21
|
-
|
|
22
|
-
#span = env[:span]
|
|
23
|
-
#if span
|
|
24
|
-
# functions = env[:pending_functions]
|
|
25
|
-
# if functions && !functions.empty?
|
|
26
|
-
# span.set_attribute("brute.tool_calls.count", functions.size)
|
|
27
|
-
|
|
28
|
-
# functions.each do |fn|
|
|
29
|
-
# attrs = {
|
|
30
|
-
# "tool.name" => fn.name.to_s,
|
|
31
|
-
# "tool.id" => fn.id.to_s,
|
|
32
|
-
# }
|
|
33
|
-
# args = fn.arguments
|
|
34
|
-
# attrs["tool.arguments"] = args.to_json if args
|
|
35
|
-
# span.add_event("tool_call", attributes: attrs)
|
|
36
|
-
# end
|
|
37
|
-
# end
|
|
38
|
-
#end
|
|
39
|
-
|
|
40
|
-
#response
|
|
41
|
-
@app.call(env)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
__END__
|
|
48
|
-
|
|
49
|
-
describe "brute/middleware/073_otel_tool_call" do
|
|
50
|
-
# not implemented
|
|
51
|
-
end
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
require "brute"
|
|
5
|
-
|
|
6
|
-
module Brute
|
|
7
|
-
module Middleware
|
|
8
|
-
# Records tool results as span events.
|
|
9
|
-
#
|
|
10
|
-
# Tool results are now appended directly to env[:messages] as :tool
|
|
11
|
-
# role messages. This middleware can inspect the last messages to
|
|
12
|
-
# record them as span events.
|
|
13
|
-
#
|
|
14
|
-
class OtelToolResults
|
|
15
|
-
def initialize(app)
|
|
16
|
-
@app = app
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def call(env)
|
|
20
|
-
#span = env[:span]
|
|
21
|
-
|
|
22
|
-
#if span && (results = env[:tool_results])
|
|
23
|
-
# span.set_attribute("brute.tool_results.count", results.size)
|
|
24
|
-
|
|
25
|
-
# results.each do |name, value|
|
|
26
|
-
# error = value.is_a?(Hash) && value[:error]
|
|
27
|
-
# attrs = { "tool.name" => name.to_s }
|
|
28
|
-
# if error
|
|
29
|
-
# attrs["tool.status"] = "error"
|
|
30
|
-
# attrs["tool.error"] = value[:error].to_s
|
|
31
|
-
# else
|
|
32
|
-
# attrs["tool.status"] = "ok"
|
|
33
|
-
# end
|
|
34
|
-
# span.add_event("tool_result", attributes: attrs)
|
|
35
|
-
# end
|
|
36
|
-
#end
|
|
37
|
-
|
|
38
|
-
@app.call(env)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
__END__
|
|
45
|
-
|
|
46
|
-
describe "brute/middleware/075_otel_tool_results" do
|
|
47
|
-
# not implemented
|
|
48
|
-
end
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "gem_kit"
|
|
4
|
-
|
|
5
|
-
require_relative "../completion/open_router"
|
|
6
|
-
|
|
7
|
-
module Brute
|
|
8
|
-
module Middleware
|
|
9
|
-
module OpenRouter
|
|
10
|
-
# Deprecated. Completion middlewares now live under Brute::Completion,
|
|
11
|
-
# which names them for what they do (call one provider) rather than for
|
|
12
|
-
# where they happened to sit in the stack:
|
|
13
|
-
#
|
|
14
|
-
# Brute::Middleware::OpenRouter::Completion -> Brute::Completion::OpenRouter
|
|
15
|
-
#
|
|
16
|
-
# The old name stays a working subclass of the new one until the deadline
|
|
17
|
-
# below; see DEPRECATIONS.md and `gem kit deprecations`.
|
|
18
|
-
class Completion < Brute::Completion::OpenRouter
|
|
19
|
-
extend GemKit::Deprecate
|
|
20
|
-
superseded_by "Brute::Completion::OpenRouter", "5.0"
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
__END__
|
|
27
|
-
|
|
28
|
-
describe "brute/middleware/open_router" do
|
|
29
|
-
require "brute/completion/open_router"
|
|
30
|
-
|
|
31
|
-
it "is the new Completion class under the old name" do
|
|
32
|
-
Brute::Middleware::OpenRouter::Completion.superclass.should == Brute::Completion::OpenRouter
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "warns on use, naming the replacement and the removal version" do
|
|
36
|
-
captured = []
|
|
37
|
-
original = GemKit::Deprecate.method(:warn)
|
|
38
|
-
GemKit::Deprecate.define_singleton_method(:warn) { |message| captured << message }
|
|
39
|
-
begin
|
|
40
|
-
Brute::Middleware::OpenRouter::Completion.new(->(env) { env })
|
|
41
|
-
ensure
|
|
42
|
-
GemKit::Deprecate.define_singleton_method(:warn, original)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
captured.size.should == 1
|
|
46
|
-
captured.first.should.match(/Brute::Middleware::OpenRouter::Completion is deprecated/)
|
|
47
|
-
captured.first.should.match(/use Brute::Completion::OpenRouter instead/)
|
|
48
|
-
captured.first.should.match(/removed in 5\.0/)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "is registered with its removal deadline" do
|
|
52
|
-
entry = GemKit::Deprecate.registry.find { |e| e.name == "Brute::Middleware::OpenRouter::Completion" }
|
|
53
|
-
entry.should.not.be.nil
|
|
54
|
-
entry.removed_in.should == Gem::Version.new("5.0")
|
|
55
|
-
end
|
|
56
|
-
end
|