Class: Google::ADK::SimpleLlmAgent
- Inherits:
-
Object
- Object
- Google::ADK::SimpleLlmAgent
- Defined in:
- lib/google/adk/agents/simple_llm_agent.rb
Overview
Simplified LLM agent with actual Gemini integration
Instance Attribute Summary collapse
-
#instructions ⇒ Object
readonly
Returns the value of attribute instructions.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
-
#call(message) ⇒ Object
Simple synchronous call to Gemini.
-
#initialize(model:, name:, instructions: nil, tools: []) ⇒ SimpleLlmAgent
constructor
A new instance of SimpleLlmAgent.
-
#run_async(message, context: nil) ⇒ Object
Generate events for the runner.
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
#instructions ⇒ Object (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 |
#model ⇒ Object (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 |
#name ⇒ Object (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 |
#tools ⇒ Object (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() begin # Simple call without tools for now response = @client.generate_content( model: @model, messages: [{ role: "user", content: }], 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.}" 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(, context: nil) Enumerator.new do |yielder| begin response_text = call() 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.}" ) yielder << error_event end end end |