Class AG2Agent (1.122.0)

AG2Agent(model:str,runnable_name:str,*,api_type:typing.Optional[str]=None,llm_config:typing.Optional[typing.Mapping[str,typing.Any]]=None,system_instruction:typing.Optional[str]=None,runnable_kwargs:typing.Optional[typing.Mapping[str,typing.Any]]=None,runnable_builder:typing.Optional[typing.Callable[[...],ConversableAgent]]=None,tools:typing.Optional[typing.Sequence[typing.Callable[[...],typing.Any]]]=None,enable_tracing:bool=False,instrumentor_builder:typing.Optional[typing.Callable[[...],typing.Any]]=None)

An AG2 Agent.

Methods

AG2Agent

AG2Agent(model:str,runnable_name:str,*,api_type:typing.Optional[str]=None,llm_config:typing.Optional[typing.Mapping[str,typing.Any]]=None,system_instruction:typing.Optional[str]=None,runnable_kwargs:typing.Optional[typing.Mapping[str,typing.Any]]=None,runnable_builder:typing.Optional[typing.Callable[[...],ConversableAgent]]=None,tools:typing.Optional[typing.Sequence[typing.Callable[[...],typing.Any]]]=None,enable_tracing:bool=False,instrumentor_builder:typing.Optional[typing.Callable[[...],typing.Any]]=None)

Initializes the AG2 Agent.

Under-the-hood, assuming .set_up() is called, this will correspond to

# runnable_builderrunnable = runnable_builder(    llm_config=llm_config,    system_message=system_instruction,    **runnable_kwargs,)

When everything is based on their default values, this corresponds to

# llm_configllm_config = {    "config_list": [{        "project_id":       initializer.global_config.project,        "location":         initializer.global_config.location,        "model":            "gemini-1.0-pro-001",        "api_type":         "google",    }]}# runnable_builderrunnable = ConversableAgent(    llm_config=llm_config,    name="Default AG2 Agent"    system_message="You are a helpful AI Assistant.",    human_input_mode="NEVER",)

By default, ifllm_config is not specified, a default configurationwill be created using the providedmodel andapi_type.

Ifrunnable_builder is not specified, a default runnable builder willbe used, configured with thesystem_instruction,runnable_name andrunnable_kwargs.

Parameters
NameDescription
modelstr

Required. The name of the model (e.g. "gemini-1.0-pro"). Used to create a defaultllm_config if one is not provided. This parameter is ignored ifllm_config is provided.

runnable_namestr

Required. The name of the runnable. This name is used as the defaultrunnable_kwargs["name"] unlessrunnable_kwargs already contains a "name", in which case the providedrunnable_kwargs["name"] will be used.

api_typestr

Optional. The API type to use for the language model. Used to create a defaultllm_config if one is not provided. This parameter is ignored ifllm_config is provided.

llm_configMapping[str, Any]

Optional. Configuration dictionary for the language model. If provided, this configuration will be used directly. Otherwise, a defaultllm_config will be created usingmodel andapi_type. Thisllm_config is used as the defaultrunnable_kwargs["llm_config"] unlessrunnable_kwargs already contains a "llm_config", in which case the providedrunnable_kwargs["llm_config"] will be used.

system_instructionstr

Optional. The system instruction for the agent. This instruction is used as the defaultrunnable_kwargs["system_message"] unlessrunnable_kwargs already contains a "system_message", in which case the providedrunnable_kwargs["system_message"] will be used.

runnable_kwargsMapping[str, Any]

Optional. Additional keyword arguments for the constructor of the runnable. Details of the kwargs can be found inhttps://docs.ag2.ai/docs/api-reference/autogen/ConversableAgent.runnable_kwargs only supportshuman_input_mode="NEVER". Otherhuman_input_mode values will trigger a warning.

runnable_builderCallable[..., "ConversableAgent"]

Optional. Callable that returns a new runnable. This can be used for customizing the orchestration logic of the Agent. If not provided, a default runnable builder will be used.

toolsSequence[Callable[..., Any]]

Optional. The tools for the agent to be able to use. All input callables (e.g. function or class method) will be converted to a AG2 tool . Defaults to None.

enable_tracingbool

Optional. Whether to enable tracing in Cloud Trace. Defaults to False.

instrumentor_builderCallable[..., Any]

Optional. Callable that returns a new instrumentor. This can be used for customizing the instrumentation logic of the Agent. If not provided, a default instrumentor builder will be used. This parameter is ignored ifenable_tracing is False.

clone

clone()->vertexai.agent_engines.templates.ag2.AG2Agent

Returns a clone of the AG2Agent.

query

query(*,input:typing.Union[str,typing.Mapping[str,typing.Any]],max_turns:typing.Optional[int]=None,**kwargs:typing.Any)->typing.Dict[str,typing.Any]

Queries the Agent with the given input.

Parameters
NameDescription
inputUnion[str, Mapping[str, Any]]

Required. The input to be passed to the Agent.

max_turnsint

Optional. The maximum number of turns to run the agent for. If not provided, the agent will run indefinitely. Ifmax_turns is afloat, it will be converted toint through rounding.

set_up

set_up()

Sets up the agent for execution of queries at runtime.

It initializes the runnable, binds the runnable with tools.

This method should not be called for an object that being passed tothe ReasoningEngine service for deployment, as it initializes clientsthat can not be serialized.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.