Class: Google::ADK::BaseAgent
- Inherits:
-
Object
- Object
- Google::ADK::BaseAgent
- Defined in:
- lib/google/adk/agents/base_agent.rb
Direct Known Subclasses
Constant Summary collapse
- AGENT_NAME_REGEX =
/^[a-zA-Z][a-zA-Z0-9_-]*$/
Instance Attribute Summary collapse
-
#after_agent_callback ⇒ Object
readonly
Returns the value of attribute after_agent_callback.
-
#before_agent_callback ⇒ Object
readonly
Returns the value of attribute before_agent_callback.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent_agent ⇒ Object
readonly
Returns the value of attribute parent_agent.
-
#sub_agents ⇒ Object
readonly
Returns the value of attribute sub_agents.
Class Method Summary collapse
-
.from_config(config) ⇒ BaseAgent
Create an agent from configuration.
Instance Method Summary collapse
-
#clone(**attributes) ⇒ BaseAgent
Create a copy of the agent with optional updates.
-
#find_agent(agent_name) ⇒ BaseAgent?
Find an agent by name in the agent tree.
-
#find_sub_agent(agent_name) ⇒ BaseAgent?
Find a direct sub-agent by name.
-
#initialize(name:, description: nil, sub_agents: [], before_agent_callback: nil, after_agent_callback: nil) ⇒ BaseAgent
constructor
Initialize a new BaseAgent.
-
#run_async(message) ⇒ Object
Run the agent asynchronously with a text message.
-
#run_live ⇒ Object
Run the agent in live mode (video/audio).
Constructor Details
#initialize(name:, description: nil, sub_agents: [], before_agent_callback: nil, after_agent_callback: nil) ⇒ BaseAgent
Initialize a new BaseAgent
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/google/adk/agents/base_agent.rb', line 20 def initialize(name:, description: nil, sub_agents: [], before_agent_callback: nil, after_agent_callback: nil) raise ArgumentError, "name is required" if name.nil? validate_agent_name!(name) @name = name @description = description @parent_agent = nil @sub_agents = [] @before_agent_callback = before_agent_callback @after_agent_callback = after_agent_callback # Set up sub-agents with validation self.sub_agents = sub_agents end |
Instance Attribute Details
#after_agent_callback ⇒ Object (readonly)
Returns the value of attribute after_agent_callback.
8 9 10 |
# File 'lib/google/adk/agents/base_agent.rb', line 8 def after_agent_callback @after_agent_callback end |
#before_agent_callback ⇒ Object (readonly)
Returns the value of attribute before_agent_callback.
8 9 10 |
# File 'lib/google/adk/agents/base_agent.rb', line 8 def before_agent_callback @before_agent_callback end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
8 9 10 |
# File 'lib/google/adk/agents/base_agent.rb', line 8 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/google/adk/agents/base_agent.rb', line 8 def name @name end |
#parent_agent ⇒ Object (readonly)
Returns the value of attribute parent_agent.
8 9 10 |
# File 'lib/google/adk/agents/base_agent.rb', line 8 def parent_agent @parent_agent end |
#sub_agents ⇒ Object
Returns the value of attribute sub_agents.
8 9 10 |
# File 'lib/google/adk/agents/base_agent.rb', line 8 def sub_agents @sub_agents end |
Class Method Details
.from_config(config) ⇒ BaseAgent
Create an agent from configuration
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/google/adk/agents/base_agent.rb', line 99 def self.from_config(config) config = config.transform_keys(&:to_sym) # Recursively create sub-agents if present sub_agents = if config[:sub_agents] config[:sub_agents].map { |sub_config| from_config(sub_config) } else [] end new( name: config[:name], description: config[:description], sub_agents: sub_agents, before_agent_callback: config[:before_agent_callback], after_agent_callback: config[:after_agent_callback] ) end |
Instance Method Details
#clone(**attributes) ⇒ BaseAgent
Create a copy of the agent with optional updates
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/google/adk/agents/base_agent.rb', line 55 def clone(**attributes) # Deep clone sub_agents if present cloned_sub_agents = if attributes.key?(:sub_agents) attributes[:sub_agents] else @sub_agents.map(&:clone) end self.class.new( name: attributes.fetch(:name, @name), description: attributes.fetch(:description, @description), sub_agents: cloned_sub_agents, before_agent_callback: attributes.fetch(:before_agent_callback, @before_agent_callback), after_agent_callback: attributes.fetch(:after_agent_callback, @after_agent_callback) ) end |
#find_agent(agent_name) ⇒ BaseAgent?
Find an agent by name in the agent tree
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/google/adk/agents/base_agent.rb', line 76 def find_agent(agent_name) return self if @name == agent_name @sub_agents.each do |sub_agent| found = sub_agent.find_agent(agent_name) return found if found end nil end |
#find_sub_agent(agent_name) ⇒ BaseAgent?
Find a direct sub-agent by name
91 92 93 |
# File 'lib/google/adk/agents/base_agent.rb', line 91 def find_sub_agent(agent_name) @sub_agents.find { |agent| agent.name == agent_name } end |
#run_async(message) ⇒ Object
Run the agent asynchronously with a text message
40 41 42 |
# File 'lib/google/adk/agents/base_agent.rb', line 40 def run_async() raise NotImplementedError, "Subclasses must implement #run_async" end |
#run_live ⇒ Object
Run the agent in live mode (video/audio)
47 48 49 |
# File 'lib/google/adk/agents/base_agent.rb', line 47 def run_live raise NotImplementedError, "Subclasses must implement #run_live" end |