Class: Google::ADK::Event

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

Overview

Represents an event in agent-user conversation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(invocation_id:, author:, id: nil, timestamp: nil, content: nil, function_calls: [], function_responses: [], long_running_tool_ids: nil, branch: nil, actions: nil) ⇒ Event

Initialize an event

Parameters:

  • id (String) (defaults to: nil)

    Unique event identifier (optional)

  • invocation_id (String)

    Invocation ID

  • author (String)

    Event author (user or agent name)

  • timestamp (Time) (defaults to: nil)

    Event timestamp (optional)

  • content (String) (defaults to: nil)

    Event content (optional)

  • function_calls (Array<FunctionCall>) (defaults to: [])

    Function calls (optional)

  • function_responses (Array<FunctionResponse>) (defaults to: [])

    Function responses (optional)

  • long_running_tool_ids (Set) (defaults to: nil)

    Long-running tool IDs (optional)

  • branch (String) (defaults to: nil)

    Conversation branch (optional)

  • actions (EventActions) (defaults to: nil)

    Event actions (optional)



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/google/adk/events.rb', line 139

def initialize(invocation_id:, author:, id: nil, timestamp: nil,
               content: nil, function_calls: [], function_responses: [],
               long_running_tool_ids: nil, branch: nil, actions: nil)
  @id = id || self.class.new_id
  @invocation_id = invocation_id
  @author = author
  @timestamp = timestamp || Time.now
  @content = content
  @function_calls = function_calls
  @function_responses = function_responses
  @long_running_tool_ids = long_running_tool_ids || Set.new
  @branch = branch
  @actions = actions
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



123
124
125
# File 'lib/google/adk/events.rb', line 123

def actions
  @actions
end

#authorObject (readonly)

Returns the value of attribute author.



123
124
125
# File 'lib/google/adk/events.rb', line 123

def author
  @author
end

#branchObject (readonly)

Returns the value of attribute branch.



123
124
125
# File 'lib/google/adk/events.rb', line 123

def branch
  @branch
end

#contentObject (readonly)

Returns the value of attribute content.



123
124
125
# File 'lib/google/adk/events.rb', line 123

def content
  @content
end

#function_callsObject (readonly)

Returns the value of attribute function_calls.



123
124
125
# File 'lib/google/adk/events.rb', line 123

def function_calls
  @function_calls
end

#function_responsesObject (readonly)

Returns the value of attribute function_responses.



123
124
125
# File 'lib/google/adk/events.rb', line 123

def function_responses
  @function_responses
end

#idObject (readonly)

Returns the value of attribute id.



123
124
125
# File 'lib/google/adk/events.rb', line 123

def id
  @id
end

#invocation_idObject (readonly)

Returns the value of attribute invocation_id.



123
124
125
# File 'lib/google/adk/events.rb', line 123

def invocation_id
  @invocation_id
end

#long_running_tool_idsObject (readonly)

Returns the value of attribute long_running_tool_ids.



123
124
125
# File 'lib/google/adk/events.rb', line 123

def long_running_tool_ids
  @long_running_tool_ids
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



123
124
125
# File 'lib/google/adk/events.rb', line 123

def timestamp
  @timestamp
end

Class Method Details

.new_idString

Generate a new event ID

Returns:

  • (String)

    New UUID-based ID



167
168
169
# File 'lib/google/adk/events.rb', line 167

def self.new_id
  SecureRandom.uuid
end

Instance Method Details

#is_final_response?Boolean

Check if this is a final response

Returns:

  • (Boolean)

    True if final response



157
158
159
160
161
162
# File 'lib/google/adk/events.rb', line 157

def is_final_response?
  return true if @author == "user"
  return true if @actions.nil?

  @actions.transfer_to_agent.nil?
end

#to_hHash

Convert to hash representation

Returns:

  • (Hash)

    Hash representation



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/google/adk/events.rb', line 174

def to_h
  result = {
    id: @id,
    invocation_id: @invocation_id,
    author: @author,
    timestamp: @timestamp.iso8601,
    content: @content,
    function_calls: @function_calls.map(&:to_h),
    function_responses: @function_responses.map(&:to_h),
    long_running_tool_ids: @long_running_tool_ids.to_a
  }
  result[:branch] = @branch unless @branch.nil?
  result[:actions] = @actions.to_h if @actions
  result
end