Class: Google::ADK::SimpleLlmAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/google/adk/agents/simple_llm_agent.rb

Overview

Simplified LLM agent with actual Gemini integration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, name:, instructions: nil, tools: []) ⇒ SimpleLlmAgent

Returns a new instance of SimpleLlmAgent.



12
13
14
15
16
17
18
# File 'lib/google/adk/agents/simple_llm_agent.rb', line 12

def initialize(model:, name:, instructions: nil, tools: [])
  @model = model
  @name = name
  @instructions = instructions
  @tools = tools
  @client = GeminiClient.new
end

Instance Attribute Details

#instructionsObject (readonly)

Returns the value of attribute instructions.



10
11
12
# File 'lib/google/adk/agents/simple_llm_agent.rb', line 10

def instructions
  @instructions
end

#modelObject (readonly)

Returns the value of attribute model.



10
11
12
# File 'lib/google/adk/agents/simple_llm_agent.rb', line 10

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/google/adk/agents/simple_llm_agent.rb', line 10

def name
  @name
end

#toolsObject (readonly)

Returns the value of attribute tools.



10
11
12
# File 'lib/google/adk/agents/simple_llm_agent.rb', line 10

def tools
  @tools
end

Instance Method Details

#call(message) ⇒ Object

Simple synchronous call to Gemini



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/google/adk/agents/simple_llm_agent.rb', line 21

def call(message)
  begin
    # Simple call without tools for now
    response = @client.generate_content(
      model: @model,
      messages: [{ role: "user", content: message }],
      system_instruction: @instructions
    )
    
    if response.dig("candidates", 0, "content", "parts", 0, "text")
      response["candidates"][0]["content"]["parts"][0]["text"]
    else
      "I apologize, but I couldn't generate a response."
    end
  rescue => e
    "Error: #{e.message}"
  end
end

#run_async(message, context: nil) ⇒ Object

Generate events for the runner



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/google/adk/agents/simple_llm_agent.rb', line 41

def run_async(message, context: nil)
  Enumerator.new do |yielder|
    begin
      response_text = call(message)
      
      event = Event.new(
        invocation_id: context&.invocation_id || "inv-#{SecureRandom.uuid}",
        author: @name,
        content: response_text
      )
      
      yielder << event
      context&.add_event(event) if context
      
    rescue => e
      error_event = Event.new(
        invocation_id: context&.invocation_id || "inv-#{SecureRandom.uuid}",
        author: @name,
        content: "Error: #{e.message}"
      )
      yielder << error_event
    end
  end
end