Class: Brute::Turn::AgentPipeline
- Defined in:
- lib/brute/turn/agent_pipeline.rb
Overview
agent = Brute.agent # => AgentPipeline .use(Middleware::X) # => same AgentPipeline (.use returns self) .run ->(env) { ... } # => same AgentPipeline (.run returns self)
agent.start("what changed?") # => runs the turn, returns env
Direct Known Subclasses
Instance Method Summary collapse
- #generate_map(default_app, mapping) ⇒ Object
-
#map(command, template = nil, &block) ⇒ Object
Register a slash command:.
- #start(input = nil, events: NullSink.new) ⇒ Object
Methods inherited from Pipeline
Methods included from Pipeline::Chainable
Instance Method Details
#generate_map(default_app, mapping) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/brute/turn/agent_pipeline.rb', line 32 def generate_map(default_app, mapping) super.tap do |routes| routes.define_singleton_method(:call) do |prompt| name, args = prompt.to_s.strip.split(/\s+/, 2) prompt = mapping[name].call.to_s.gsub("$ARGUMENTS", args.to_s) if mapping[name] default_app.call(prompt) end end end |
#map(command, template = nil, &block) ⇒ Object
Register a slash command:
map "/weather", "Get the weather in the following location $ARGUMENTS"
map("/weather") { "Get the weather in the following location $ARGUMENTS" }
24 25 26 27 28 29 30 |
# File 'lib/brute/turn/agent_pipeline.rb', line 24 def map(command, template = nil, &block) command = command.to_s command = command.start_with?("/") ? command : "/#{command}" (@map ||= {})[command] = block || proc { template } self end |
#start(input = nil, events: NullSink.new) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/brute/turn/agent_pipeline.rb', line 42 def start(input = nil, events: NullSink.new) env = { messages: (input), events: events, metadata: {}, current_iteration: 1, } env.tap do build.call(env) end end |