Class: Google::ADK::ToolContext

Inherits:
CallbackContext show all
Defined in:
lib/google/adk/context.rb

Overview

Context for tool execution

Instance Attribute Summary collapse

Attributes inherited from CallbackContext

#session

Attributes inherited from ReadonlyContext

#agent_name, #invocation_id, #state

Instance Method Summary collapse

Methods inherited from CallbackContext

#state, #update_state

Constructor Details

#initialize(invocation_id:, agent_name:, session:, auth_service: nil, artifact_service: nil, memory_service: nil) ⇒ ToolContext

Initialize tool context

Parameters:

  • invocation_id (String)

    Unique invocation ID

  • agent_name (String)

    Current agent name

  • session (Object)

    Session object

  • auth_service (Object) (defaults to: nil)

    Authentication service (optional)

  • artifact_service (Object) (defaults to: nil)

    Artifact service (optional)

  • memory_service (Object) (defaults to: nil)

    Memory service (optional)



102
103
104
105
106
107
108
# File 'lib/google/adk/context.rb', line 102

def initialize(invocation_id:, agent_name:, session:,
               auth_service: nil, artifact_service: nil, memory_service: nil)
  super(invocation_id: invocation_id, agent_name: agent_name, session: session)
  @auth_service = auth_service
  @artifact_service = artifact_service
  @memory_service = memory_service
end

Instance Attribute Details

#artifact_serviceObject (readonly)

Returns the value of attribute artifact_service.



92
93
94
# File 'lib/google/adk/context.rb', line 92

def artifact_service
  @artifact_service
end

#auth_serviceObject (readonly)

Returns the value of attribute auth_service.



92
93
94
# File 'lib/google/adk/context.rb', line 92

def auth_service
  @auth_service
end

#memory_serviceObject (readonly)

Returns the value of attribute memory_service.



92
93
94
# File 'lib/google/adk/context.rb', line 92

def memory_service
  @memory_service
end

Instance Method Details

#list_artifactsArray

List artifacts

Returns:

  • (Array)

    List of artifacts



123
124
125
126
127
# File 'lib/google/adk/context.rb', line 123

def list_artifacts
  return [] unless @artifact_service

  @artifact_service.list_artifacts
end

#request_auth(auth_type, **options) ⇒ Object

Request authentication

Parameters:

  • auth_type (String)

    Type of authentication

  • options (Hash)

    Authentication options

Raises:



114
115
116
117
118
# File 'lib/google/adk/context.rb', line 114

def request_auth(auth_type, **options)
  raise AgentError, "Auth service not available" unless @auth_service

  @auth_service.request_auth(auth_type, options)
end

#search_memory(query) ⇒ Array

Search memory

Parameters:

  • query (String)

    Search query

Returns:

  • (Array)

    Search results



133
134
135
136
137
# File 'lib/google/adk/context.rb', line 133

def search_memory(query)
  return [] unless @memory_service

  @memory_service.search(query)
end