# Class LlmAgent

An agent that uses a large language model to generate responses.

#### Hierarchy (View Summary)

- BaseAgent
  - LlmAgent

- Defined in agents/llm_agent.ts:336

## Constructors

### constructor

- new LlmAgent(config: LlmAgentConfig): LlmAgent

  #### Parameters

  - config: LlmAgentConfig

  #### Returns LlmAgent

  Overrides BaseAgent.constructor

  - Defined in agents/llm_agent.ts:359

## Properties

### `Readonly`[BASE_AGENT_SIGNATURE_SYMBOL]

"[BASE_AGENT_SIGNATURE_SYMBOL]": true

A unique symbol to identify ADK agent classes.

Inherited from BaseAgent.[BASE_AGENT_SIGNATURE_SYMBOL]

- Defined in agents/base_agent.ts:78

### `Readonly`[LLM_AGENT_SIGNATURE_SYMBOL]

"[LLM_AGENT_SIGNATURE_SYMBOL]": true

A unique symbol to identify ADK LLM agent class.

- Defined in agents/llm_agent.ts:338

### `Readonly` afterAgentCallback

afterAgentCallback: SingleAgentCallback[]

Callback or list of callbacks to be invoked after the agent run.

When a list of callbacks is provided, the callbacks will be called in the order they are listed until a callback does not return undefined.

#### Param: callbackContext:

MUST be named 'callbackContext' (enforced).

#### Returns

Content: The content to return to the user. When the content is present, the provided content will be used as agent response and appended to event history as agent response.

Inherited from BaseAgent.afterAgentCallback

- Defined in agents/base_agent.ts:147

### `Optional` afterModelCallback

afterModelCallback?: AfterModelCallback

- Defined in agents/llm_agent.ts:352

### `Optional` afterToolCallback

afterToolCallback?: AfterToolCallback

- Defined in agents/llm_agent.ts:354

### `Readonly` beforeAgentCallback

beforeAgentCallback: SingleAgentCallback[]

Callback or list of callbacks to be invoked before the agent run.

When a list of callbacks is provided, the callbacks will be called in the order they are listed until a callback does not return undefined.

#### Param: callbackContext:

MUST be named 'callbackContext' (enforced).

#### Returns

Content: The content to return to the user. When the content is present, the agent run will be skipped and the provided content will be returned to user.

Inherited from BaseAgent.beforeAgentCallback

- Defined in agents/base_agent.ts:133

### `Optional` beforeModelCallback

beforeModelCallback?: BeforeModelCallback

- Defined in agents/llm_agent.ts:351

### `Optional` beforeToolCallback

beforeToolCallback?: BeforeToolCallback

- Defined in agents/llm_agent.ts:353

### `Optional` codeExecutor

codeExecutor?: BaseCodeExecutor

- Defined in agents/llm_agent.ts:357

### `Optional` `Readonly` description

description?: string

Description about the agent's capability.

The model uses this to determine whether to delegate control to the agent. One-line description is enough and preferred.

Inherited from BaseAgent.description

- Defined in agents/base_agent.ts:93

### disallowTransferToParent

disallowTransferToParent: boolean

- Defined in agents/llm_agent.ts:345

### disallowTransferToPeers

disallowTransferToPeers: boolean

- Defined in agents/llm_agent.ts:346

### `Optional` generateContentConfig

generateContentConfig?: GenerateContentConfig

- Defined in agents/llm_agent.ts:344

### globalInstruction

globalInstruction: string | InstructionProvider

- Defined in agents/llm_agent.ts:342

### includeContents

includeContents: "none" | "default"

- Defined in agents/llm_agent.ts:347

### `Optional` inputSchema

inputSchema?: Schema

- Defined in agents/llm_agent.ts:348

### instruction

instruction: string | InstructionProvider

- Defined in agents/llm_agent.ts:341

### `Optional` model

model?: string | BaseLlm

- Defined in agents/llm_agent.ts:340

### `Readonly` name

name: string

The agent's name. Agent name must be a JS identifier and unique within the agent tree. Agent name cannot be "user", since it's reserved for end-user's input.

Inherited from BaseAgent.name

- Defined in agents/base_agent.ts:85

### `Optional` outputKey

outputKey?: string

- Defined in agents/llm_agent.ts:350

### `Optional` outputSchema

outputSchema?: Schema

- Defined in agents/llm_agent.ts:349

### `Optional` parentAgent

parentAgent?: BaseAgent

The parent agent of this agent.

Note that an agent can ONLY be added as sub-agent once.

If you want to add one agent twice as sub-agent, consider to create two agent instances with identical config, but with different name and add them to the agent tree.

The parent agent is the agent that created this agent.

Inherited from BaseAgent.parentAgent

- Defined in agents/base_agent.ts:114

### requestProcessors

requestProcessors: BaseLlmRequestProcessor[]

- Defined in agents/llm_agent.ts:355

### responseProcessors

responseProcessors: BaseLlmResponseProcessor[]

- Defined in agents/llm_agent.ts:356

### `Readonly` subAgents

subAgents: BaseAgent[]

The sub-agents of this agent.

Inherited from BaseAgent.subAgents

- Defined in agents/base_agent.ts:119

### tools

tools: ToolUnion[]

- Defined in agents/llm_agent.ts:343

## Accessors

### canonicalAfterModelCallbacks

- get canonicalAfterModelCallbacks(): SingleAfterModelCallback[]

  The resolved afterModelCallback field as a list of SingleAfterModelCallback.

  This method is only for use by Agent Development Kit.

  #### Returns SingleAfterModelCallback[]

  - Defined in agents/llm_agent.ts:548

### canonicalAfterToolCallbacks

- get canonicalAfterToolCallbacks(): SingleAfterToolCallback[]

  The resolved afterToolCallback field as a list of AfterToolCallback.

  This method is only for use by Agent Development Kit.

  #### Returns SingleAfterToolCallback[]

  - Defined in agents/llm_agent.ts:567

### canonicalBeforeModelCallbacks

- get canonicalBeforeModelCallbacks(): SingleBeforeModelCallback[]

  The resolved beforeModelCallback field as a list of SingleBeforeModelCallback.

  This method is only for use by Agent Development Kit.

  #### Returns SingleBeforeModelCallback[]

  - Defined in agents/llm_agent.ts:538

### canonicalBeforeToolCallbacks

- get canonicalBeforeToolCallbacks(): SingleBeforeToolCallback[]

  The resolved beforeToolCallback field as a list of BeforeToolCallback.

  This method is only for use by Agent Development Kit.

  #### Returns SingleBeforeToolCallback[]

  - Defined in agents/llm_agent.ts:558

### canonicalModel

- get canonicalModel(): BaseLlm

  The resolved BaseLlm instance.

  When not set, the agent will inherit the model from its ancestor.

  #### Returns BaseLlm

  - Defined in agents/llm_agent.ts:441

### rootAgent

- get rootAgent(): BaseAgent

  Root agent of this agent. Computed dynamically by traversing up the parent chain.

  #### Returns BaseAgent

  Inherited from BaseAgent.rootAgent

  - Defined in agents/base_agent.ts:99

## Methods

### `Protected` callLlmAsync

- callLlmAsync(
  invocationContext: InvocationContext,
  llmRequest: LlmRequest,
  modelResponseEvent: Event,
  ): AsyncGenerator<LlmResponse, void, void>

  #### Parameters

  - invocationContext: InvocationContext
  - llmRequest: LlmRequest
  - modelResponseEvent: Event

  #### Returns AsyncGenerator<LlmResponse, void, void>

  - Defined in agents/llm_agent.ts:905

### canonicalGlobalInstruction

- canonicalGlobalInstruction(
  context: ReadonlyContext,
  ): Promise<{ instruction: string; requireStateInjection: boolean }>

  The resolved globalInstruction field to construct global instruction.

  This method is only for use by Agent Development Kit.

  #### Parameters

  - context: ReadonlyContext

    The context to retrieve the session state.

  #### Returns Promise<{ instruction: string; requireStateInjection: boolean }>

  The resolved globalInstruction field.

  - Defined in agents/llm_agent.ts:487

### canonicalInstruction

- canonicalInstruction(
  context: ReadonlyContext,
  ): Promise<{ instruction: string; requireStateInjection: boolean }>

  The resolved instruction field to construct instruction for this agent.

  This method is only for use by Agent Development Kit.

  #### Parameters

  - context: ReadonlyContext

    The context to retrieve the session state.

  #### Returns Promise<{ instruction: string; requireStateInjection: boolean }>

  The resolved instruction field.

  - Defined in agents/llm_agent.ts:468

### canonicalTools

- canonicalTools(context?: ReadonlyContext): Promise<BaseTool[]>

  The resolved tools field as a list of BaseTool based on the context.

  This method is only for use by Agent Development Kit.

  #### Parameters

  - `Optional` context: ReadonlyContext

  #### Returns Promise<BaseTool[]>

  - Defined in agents/llm_agent.ts:507

### `Protected` createInvocationContext

- createInvocationContext(parentContext: InvocationContext): InvocationContext

  Creates an invocation context for this agent.

  #### Parameters

  - parentContext: InvocationContext

    The invocation context of the parent agent.

  #### Returns InvocationContext

  The invocation context for this agent.

  Inherited from BaseAgent.createInvocationContext

  - Defined in agents/base_agent.ts:297

### findAgent

- findAgent(name: string): BaseAgent | undefined

  Finds the agent with the given name in this agent and its descendants.

  #### Parameters

  - name: string

    The name of the agent to find.

  #### Returns BaseAgent | undefined

  The agent with the given name, or undefined if not found.

  Inherited from BaseAgent.findAgent

  - Defined in agents/base_agent.ts:266

### findSubAgent

- findSubAgent(name: string): BaseAgent | undefined

  Finds the agent with the given name in this agent's descendants.

  #### Parameters

  - name: string

    The name of the agent to find.

  #### Returns BaseAgent | undefined

  The agent with the given name, or undefined if not found.

  Inherited from BaseAgent.findSubAgent

  - Defined in agents/base_agent.ts:280

### `Protected` handleAfterAgentCallback

- handleAfterAgentCallback(
  invocationContext: InvocationContext,
  ): Promise<Event | undefined>

  Runs the after agent callback if it exists.

  #### Parameters

  - invocationContext: InvocationContext

    The invocation context of the agent.

  #### Returns Promise<Event | undefined>

  The event to return to the user, or undefined if no event is generated.

  Inherited from BaseAgent.handleAfterAgentCallback

  - Defined in agents/base_agent.ts:356

### `Protected` handleBeforeAgentCallback

- handleBeforeAgentCallback(
  invocationContext: InvocationContext,
  ): Promise<Event | undefined>

  Runs the before agent callback if it exists.

  #### Parameters

  - invocationContext: InvocationContext

    The invocation context of the agent.

  #### Returns Promise<Event | undefined>

  The event to return to the user, or undefined if no event is generated.

  Inherited from BaseAgent.handleBeforeAgentCallback

  - Defined in agents/base_agent.ts:313

### `Protected` runAndHandleError

- runAndHandleError<T extends LlmResponse | Event>(
  responseGenerator: AsyncGenerator<T, void, void>,
  invocationContext: InvocationContext,
  llmRequest: LlmRequest,
  modelResponseEvent: Event,
  ): AsyncGenerator<T, void, void>

  #### Type Parameters

  - T extends LlmResponse | Event

  #### Parameters

  - responseGenerator: AsyncGenerator<T, void, void>
  - invocationContext: InvocationContext
  - llmRequest: LlmRequest
  - modelResponseEvent: Event

  #### Returns AsyncGenerator<T, void, void>

  - Defined in agents/llm_agent.ts:1031

### runAsync

- runAsync(parentContext: InvocationContext): AsyncGenerator<Event, void, void>

  Entry method to run an agent via text-based conversation.

  #### Parameters

  - parentContext: InvocationContext

    The invocation context of the parent agent.

  #### Returns AsyncGenerator<Event, void, void>

  An AsyncGenerator that yields the events generated by the agent.

  #### Yields

  The events generated by the agent.

  Inherited from BaseAgent.runAsync

  - Defined in agents/base_agent.ts:169

### `Protected` runAsyncImpl

- runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>

  Core logic to run this agent via text-based conversation.

  #### Parameters

  - context: InvocationContext

    The invocation context of the agent.

  #### Returns AsyncGenerator<Event, void, void>

  An AsyncGenerator that yields the events generated by the agent.

  #### Yields

  The events generated by the agent.

  Overrides BaseAgent.runAsyncImpl

  - Defined in agents/llm_agent.ts:632

### runLive

- runLive(parentContext: InvocationContext): AsyncGenerator<Event, void, void>

  Entry method to run an agent via video/audio-based conversation.

  #### Parameters

  - parentContext: InvocationContext

    The invocation context of the parent agent.

  #### Returns AsyncGenerator<Event, void, void>

  An AsyncGenerator that yields the events generated by the agent.

  #### Yields

  The events generated by the agent.

  Inherited from BaseAgent.runLive

  - Defined in agents/base_agent.ts:219

### `Protected` runLiveImpl

- runLiveImpl(context: InvocationContext): AsyncGenerator<Event, void, void>

  Core logic to run this agent via video/audio-based conversation.

  #### Parameters

  - context: InvocationContext

    The invocation context of the agent.

  #### Returns AsyncGenerator<Event, void, void>

  An AsyncGenerator that yields the events generated by the agent.

  #### Yields

  The events generated by the agent.

  Overrides BaseAgent.runLiveImpl

  - Defined in agents/llm_agent.ts:653