Class: Bristow::Functions::Delegate
- Inherits:
-
Bristow::Function
- Object
- Bristow::Function
- Bristow::Functions::Delegate
- Defined in:
- lib/bristow/functions/delegate.rb
Class Method Summary collapse
Instance Method Summary collapse
- #agency=(agency) ⇒ Object
- #description ⇒ Object
-
#initialize(agent, agency) ⇒ Delegate
constructor
A new instance of Delegate.
- #parameters ⇒ Object
- #perform(agent_name:, message:) ⇒ Object
Methods inherited from Bristow::Function
Methods included from Delegate
Methods included from Sgetter
Constructor Details
#initialize(agent, agency) ⇒ Delegate
Returns a new instance of Delegate.
37 38 39 40 41 42 43 |
# File 'lib/bristow/functions/delegate.rb', line 37 def initialize(agent, agency) raise ArgumentError, "Agent must not be nil" if agent.nil? @agent = agent @agency = agency super() end |
Class Method Details
.description ⇒ Object
8 9 10 |
# File 'lib/bristow/functions/delegate.rb', line 8 def self.description "Delegate a task to a specialized agent" end |
.parameters ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bristow/functions/delegate.rb', line 12 def self.parameters { type: "object", properties: { agent_name: { type: "string", description: "The name of the agent to delegate to" }, message: { type: "string", description: "The instructions for the agent being delegated to" } }, required: ["agent_name", "message"] } end |
Instance Method Details
#agency=(agency) ⇒ Object
45 46 47 |
# File 'lib/bristow/functions/delegate.rb', line 45 def agency=(agency) @agency = agency end |
#description ⇒ Object
29 30 31 |
# File 'lib/bristow/functions/delegate.rb', line 29 def description self.class.description end |
#parameters ⇒ Object
33 34 35 |
# File 'lib/bristow/functions/delegate.rb', line 33 def parameters self.class.parameters end |
#perform(agent_name:, message:) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bristow/functions/delegate.rb', line 49 def perform(agent_name:, message:) raise "Agency not set" if @agency.nil? if agent_name == @agent.agent_name { error: "Cannot delegate to self" } else agent = @agency.find_agent(agent_name) raise ArgumentError, "Agent #{agent_name} not found" unless agent Bristow.configuration.logger.info("Delegating to #{agent_name}: #{message}") response = agent.chat([{ "role" => "user", "content" => }]) = response&.last { response: &.[]("content") } end end |