Class: Google::ADK::InvocationContext
- Inherits:
-
Object
- Object
- Google::ADK::InvocationContext
- Defined in:
- lib/google/adk/context.rb
Overview
Full invocation context for agent execution
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#agent_states ⇒ Object
readonly
Returns the value of attribute agent_states.
-
#artifact_service ⇒ Object
readonly
Returns the value of attribute artifact_service.
-
#context_cache_config ⇒ Object
readonly
Returns the value of attribute context_cache_config.
-
#invocation_id ⇒ Object
readonly
Returns the value of attribute invocation_id.
-
#memory_service ⇒ Object
readonly
Returns the value of attribute memory_service.
-
#run_config ⇒ Object
readonly
Returns the value of attribute run_config.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#session_service ⇒ Object
readonly
Returns the value of attribute session_service.
Instance Method Summary collapse
-
#add_event(event) ⇒ Object
Add event to session.
-
#events ⇒ Array<Event>
Get conversation history.
-
#get_agent_state(agent_name) ⇒ Hash
Get agent state.
-
#initialize(session:, agent:, invocation_id:, session_service:, artifact_service: nil, memory_service: nil, context_cache_config: nil, run_config: nil) ⇒ InvocationContext
constructor
Initialize invocation context.
-
#state ⇒ Hash
Get current session state.
-
#to_callback_context ⇒ CallbackContext
Create callback context.
-
#to_tool_context(auth_service: nil) ⇒ ToolContext
Create tool context.
-
#update_agent_state(agent_name, state) ⇒ Object
Update agent state.
-
#update_state(updates) ⇒ Object
Update session state.
Constructor Details
#initialize(session:, agent:, invocation_id:, session_service:, artifact_service: nil, memory_service: nil, context_cache_config: nil, run_config: nil) ⇒ InvocationContext
Initialize invocation context
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/google/adk/context.rb', line 156 def initialize(session:, agent:, invocation_id:, session_service:, artifact_service: nil, memory_service: nil, context_cache_config: nil, run_config: nil) @session = session @agent = agent @invocation_id = invocation_id @session_service = session_service @artifact_service = artifact_service @memory_service = memory_service @agent_states = {} @context_cache_config = context_cache_config || ContextCacheConfig.new @run_config = run_config || RunConfig.new end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
142 143 144 |
# File 'lib/google/adk/context.rb', line 142 def agent @agent end |
#agent_states ⇒ Object (readonly)
Returns the value of attribute agent_states.
142 143 144 |
# File 'lib/google/adk/context.rb', line 142 def agent_states @agent_states end |
#artifact_service ⇒ Object (readonly)
Returns the value of attribute artifact_service.
142 143 144 |
# File 'lib/google/adk/context.rb', line 142 def artifact_service @artifact_service end |
#context_cache_config ⇒ Object (readonly)
Returns the value of attribute context_cache_config.
142 143 144 |
# File 'lib/google/adk/context.rb', line 142 def context_cache_config @context_cache_config end |
#invocation_id ⇒ Object (readonly)
Returns the value of attribute invocation_id.
142 143 144 |
# File 'lib/google/adk/context.rb', line 142 def invocation_id @invocation_id end |
#memory_service ⇒ Object (readonly)
Returns the value of attribute memory_service.
142 143 144 |
# File 'lib/google/adk/context.rb', line 142 def memory_service @memory_service end |
#run_config ⇒ Object (readonly)
Returns the value of attribute run_config.
142 143 144 |
# File 'lib/google/adk/context.rb', line 142 def run_config @run_config end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
142 143 144 |
# File 'lib/google/adk/context.rb', line 142 def session @session end |
#session_service ⇒ Object (readonly)
Returns the value of attribute session_service.
142 143 144 |
# File 'lib/google/adk/context.rb', line 142 def session_service @session_service end |
Instance Method Details
#add_event(event) ⇒ Object
Add event to session
203 204 205 |
# File 'lib/google/adk/context.rb', line 203 def add_event(event) @session.events << event end |
#events ⇒ Array<Event>
Get conversation history
210 211 212 |
# File 'lib/google/adk/context.rb', line 210 def events @session.events end |
#get_agent_state(agent_name) ⇒ Hash
Get agent state
174 175 176 |
# File 'lib/google/adk/context.rb', line 174 def get_agent_state(agent_name) @agent_states[agent_name] || {} end |
#state ⇒ Hash
Get current session state
189 190 191 |
# File 'lib/google/adk/context.rb', line 189 def state @session.state end |
#to_callback_context ⇒ CallbackContext
Create callback context
217 218 219 220 221 222 223 |
# File 'lib/google/adk/context.rb', line 217 def to_callback_context CallbackContext.new( invocation_id: @invocation_id, agent_name: @agent.name, session: @session ) end |
#to_tool_context(auth_service: nil) ⇒ ToolContext
Create tool context
229 230 231 232 233 234 235 236 237 238 |
# File 'lib/google/adk/context.rb', line 229 def to_tool_context(auth_service: nil) ToolContext.new( invocation_id: @invocation_id, agent_name: @agent.name, session: @session, auth_service: auth_service, artifact_service: @artifact_service, memory_service: @memory_service ) end |
#update_agent_state(agent_name, state) ⇒ Object
Update agent state
182 183 184 |
# File 'lib/google/adk/context.rb', line 182 def update_agent_state(agent_name, state) @agent_states[agent_name] = state end |
#update_state(updates) ⇒ Object
Update session state
196 197 198 |
# File 'lib/google/adk/context.rb', line 196 def update_state(updates) @session.state.merge!(updates) end |