Class: Google::ADK::AgentTool

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/google/adk/tools/agent_tool.rb

Overview

Tool that wraps another agent

Instance Attribute Summary collapse

Attributes inherited from BaseTool

#description, #name

Instance Method Summary collapse

Constructor Details

#initialize(agent:) ⇒ AgentTool

Initialize an agent tool

Parameters:



14
15
16
17
# File 'lib/google/adk/tools/agent_tool.rb', line 14

def initialize(agent:)
  super(name: agent.name, description: agent.description)
  @agent = agent
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



9
10
11
# File 'lib/google/adk/tools/agent_tool.rb', line 9

def agent
  @agent
end

Instance Method Details

#call(params = {}) ⇒ Object

Execute the wrapped agent

Parameters:

  • params (Hash) (defaults to: {})

    Parameters (should include ‘message’)

Returns:

  • (Object)

    Agent response



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/google/adk/tools/agent_tool.rb', line 23

def call(params = {})
  message = params[:message] || params["message"] || ""
  context = params[:context]

  # In a real implementation, this would run the agent
  # and collect its response
  if @agent.respond_to?(:run_async)
    # Collect all events from the agent
    events = []
    @agent.run_async(message, context: context).each do |event|
      events << event
    end

    # Return the last event's content as the result
    events.last&.content || "No response"
  else
    "Agent #{@agent.name} cannot be executed"
  end
end

#schemaHash

Get parameter schema

Returns:

  • (Hash)

    JSON schema for agent invocation



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/google/adk/tools/agent_tool.rb', line 46

def schema
  {
    "type" => "object",
    "properties" => {
      "message" => {
        "type" => "string",
        "description" => "Message to send to the agent"
      }
    },
    "required" => ["message"]
  }
end