LLM-based Agent

Type Parameters

Hierarchy (view full)

Constructors

Properties

name: string

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

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.

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.

subAgents: BaseAgent[] = []

The sub-agents of this agent.

beforeAgentCallback?: BeforeAgentCallback

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.

Args: callbackContext: The callback context.

Returns: Content | undefined: 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.

afterAgentCallback?: AfterAgentCallback

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.

Args: callbackContext: The callback context.

Returns: Content | undefined: 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.

model:
    | string
    | T
    | string & {}
    | LanguageModelV2

The model to use for the agent When not set, the agent will inherit the model from its ancestor

instruction: string | InstructionProvider

Instructions for the LLM model, guiding the agent's behavior

globalInstruction: string | InstructionProvider

Instructions for all the agents in the entire agent tree ONLY the global_instruction in root agent will take effect

tools: ToolUnion[]

Tools available to this agent

codeExecutor?: BaseCodeExecutor

Code executor for this agent

disallowTransferToParent: boolean

Disallows LLM-controlled transferring to the parent agent

disallowTransferToPeers: boolean

Disallows LLM-controlled transferring to the peer agents

includeContents: "default" | "none"

Whether to include contents in the model request

outputKey?: string

The output key in session state to store the output of the agent

planner?: BasePlanner

Instructs the agent to make a plan and execute it step by step

plugins?: BasePlugin[]

Plugins active on this agent, enabling lifecycle hooks for model requests, tools, events, and agent actions.

generateContentConfig?: GenerateContentConfig

Additional content generation configurations

inputSchema?: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

The input schema when agent is used as a tool

outputSchema?: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

The output schema when agent replies

beforeModelCallback?: BeforeModelCallback

Callback or list of callbacks to be called before calling the LLM

afterModelCallback?: AfterModelCallback

Callback or list of callbacks to be called after calling the LLM

beforeToolCallback?: BeforeToolCallback

Callback or list of callbacks to be called before calling a tool

afterToolCallback?: AfterToolCallback

Callback or list of callbacks to be called after calling a tool

logger: Logger = ...

Accessors

Methods

  • The resolved instruction field to construct instruction for this agent This method is only for use by Agent Development Kit

    Parameters

    Returns Promise<[string, boolean]>

  • The resolved global_instruction field to construct global instruction This method is only for use by Agent Development Kit

    Parameters

    Returns Promise<[string, boolean]>