# Class Context

The context of various callbacks within an agent run.

This class provides the context for callbacks and tool invocations, including access to the invocation context, function call ID, event actions, and authentication response. It also provides methods for requesting credentials, retrieving authentication responses, loading and saving artifacts, and searching memory.

#### Hierarchy (View Summary)

- ReadonlyContext
  - Context

- Defined in agents/context.ts:29

## Constructors

### constructor

- new Context(
  options: {
  eventActions?: EventActions;
  functionCallId?: string;
  invocationContext: InvocationContext;
  toolConfirmation?: ToolConfirmation;
  },
  ): Context

  #### Parameters

  - options: {
    eventActions?: EventActions;
    functionCallId?: string;
    invocationContext: InvocationContext;
    toolConfirmation?: ToolConfirmation;
    }

    The configuration options for the Context.

    - ##### `Optional` eventActions?: EventActions

      The event actions of the current call.

    - ##### `Optional` functionCallId?: string

      The function call id of the current tool call. This id was returned in the function call event from LLM to identify a function call. If LLM didn't return this id, ADK will assign one to it. This id is used to map function call response to the original function call.

    - ##### invocationContext: InvocationContext

      The invocation context.

    - ##### `Optional` toolConfirmation?: ToolConfirmation

      The tool confirmation of the current tool call.

  #### Returns Context

  Overrides ReadonlyContext.constructor

  - Defined in agents/context.ts:48

## Properties

### `Readonly` eventActions

eventActions: EventActions

- Defined in agents/context.ts:32

### `Optional` `Readonly` functionCallId

functionCallId?: string

- Defined in agents/context.ts:33

### `Readonly` invocationContext

invocationContext: InvocationContext

Inherited from ReadonlyContext.invocationContext

- Defined in agents/readonly_context.ts:17

### `Optional` toolConfirmation

toolConfirmation?: ToolConfirmation

- Defined in agents/context.ts:34

## Accessors

### actions

- get actions(): EventActions

  #### Returns EventActions

  - Defined in agents/context.ts:71

### agentName

- get agentName(): string

  The current agent name.

  #### Returns string

  Inherited from ReadonlyContext.agentName

  - Defined in agents/readonly_context.ts:50

### invocationId

- get invocationId(): string

  The current invocation id.

  #### Returns string

  Inherited from ReadonlyContext.invocationId

  - Defined in agents/readonly_context.ts:29

### sessionId

- get sessionId(): string

  The ID of the current session.

  #### Returns string

  Inherited from ReadonlyContext.sessionId

  - Defined in agents/readonly_context.ts:43

### state

- get state(): State

  The delta-aware state of the current session.

  #### Returns State

  Overrides ReadonlyContext.state

  - Defined in agents/context.ts:67

### userContent

- get userContent(): Content | undefined

  The user content that started this invocation.

  #### Returns Content | undefined

  Inherited from ReadonlyContext.userContent

  - Defined in agents/readonly_context.ts:22

### userId

- get userId(): string

  The user ID of the current session.

  #### Returns string

  Inherited from ReadonlyContext.userId

  - Defined in agents/readonly_context.ts:36

## Methods

### getAuthResponse

- getAuthResponse(authConfig: AuthConfig): AuthCredential | undefined

  Gets the auth credential for the given auth config.

  #### Parameters

  - authConfig: AuthConfig

    The auth config to get the auth credential for.

  #### Returns AuthCredential | undefined

  The auth credential for the given auth config.

  - Defined in agents/context.ts:137

### listArtifacts

- listArtifacts(): Promise<string[]>

  Lists the filenames of the artifacts attached to the current session.

  #### Returns Promise<string[]>

  A promise that resolves to a list of artifact filenames.

  - Defined in agents/context.ts:148

### loadArtifact

- loadArtifact(filename: string, version?: number): Promise<Part | undefined>

  Loads an artifact attached to the current session.

  #### Parameters

  - filename: string

    The filename of the artifact.

  - `Optional` version: number

    The version of the artifact. If not provided, the latest version will be used.

  #### Returns Promise<Part | undefined>

  A promise that resolves to the loaded artifact.

  - Defined in agents/context.ts:83

### requestConfirmation

- requestConfirmation(
  __namedParameters: { hint?: string; payload?: unknown },
  ): void

  Requests confirmation for the current tool call.

  #### Parameters

  - __namedParameters: { hint?: string; payload?: unknown }

  #### Returns void

  - Defined in agents/context.ts:182

### requestCredential

- requestCredential(authConfig: AuthConfig): void

  #### Parameters

  - authConfig: AuthConfig

  #### Returns void

  - Defined in agents/context.ts:121

### saveArtifact

- saveArtifact(filename: string, artifact: Part): Promise<number>

  Saves an artifact attached to the current session.

  #### Parameters

  - filename: string

    The filename of the artifact.

  - artifact: Part

    The artifact to save.

  #### Returns Promise<number>

  A promise that resolves to the version of the saved artifact.

  - Defined in agents/context.ts:104

### searchMemory

- searchMemory(query: string): Promise<SearchMemoryResponse>

  Searches the memory of the current user.

  #### Parameters

  - query: string

    The query to search memory for.

  #### Returns Promise<SearchMemoryResponse>

  A promise that resolves to SearchMemoryResponse containing the matching memories.

  - Defined in agents/context.ts:167