Class: Phronomy::Agent::Handoff

Inherits:
Object
  • Object
show all
Defined in:
lib/phronomy/agent/handoff.rb

Overview

Represents a transfer edge from one agent to another. Creates an anonymous Phronomy::Tool::Base subclass that the source agent exposes to the LLM as a +transfer_to_+ function. The tool's execute method returns a sentinel string that Runner uses to detect which target agent to route to next.

Examples:

billing = BillingAgent.new
handoff = Phronomy::Agent::Handoff.new(target_agent: billing)
tool_class = handoff.to_tool_class

Constant Summary collapse

SENTINEL_PREFIX =

Prefix embedded in tool results so Runner can detect handoffs.

"__PHRONOMY_HANDOFF__"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_agent:, description: nil) ⇒ Handoff

Returns a new instance of Handoff.

Parameters:

  • target_agent (Phronomy::Agent::Base)

    the agent to hand off to

  • description (String, nil) (defaults to: nil)

    overrides the auto-generated tool description



23
24
25
26
27
28
# File 'lib/phronomy/agent/handoff.rb', line 23

def initialize(target_agent:, description: nil)
  @target_agent = target_agent
  klass_name = target_agent.class.name&.split("::")&.last || "Agent"
  @tool_name = "transfer_to_#{snake_case(klass_name)}"
  @description = description || "Transfer the conversation to #{klass_name}."
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



19
20
21
# File 'lib/phronomy/agent/handoff.rb', line 19

def description
  @description
end

#target_agentObject (readonly)

Returns the value of attribute target_agent.



19
20
21
# File 'lib/phronomy/agent/handoff.rb', line 19

def target_agent
  @target_agent
end

#tool_nameObject (readonly)

Returns the value of attribute tool_name.



19
20
21
# File 'lib/phronomy/agent/handoff.rb', line 19

def tool_name
  @tool_name
end

Instance Method Details

#sentinelString

The sentinel string embedded in the tool result.

Returns:

  • (String)


45
46
47
# File 'lib/phronomy/agent/handoff.rb', line 45

def sentinel
  "#{SENTINEL_PREFIX}:#{target_agent.class.name}"
end

#to_tool_classClass<Phronomy::Tool::Base>

Builds an anonymous Phronomy::Tool::Base subclass for this handoff.

Returns:



32
33
34
35
36
37
38
39
40
41
# File 'lib/phronomy/agent/handoff.rb', line 32

def to_tool_class
  sentinel_value = sentinel
  tn = tool_name
  desc = description
  Class.new(Phronomy::Tool::Base) do
    tool_name tn
    description desc
    define_method(:execute) { sentinel_value }
  end
end