Class AG2Agent (1.122.0) Stay organized with collections Save and categorize content based on your preferences.
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 | |
|---|---|
| Name | Description |
model | strRequired. The name of the model (e.g. "gemini-1.0-pro"). Used to create a default |
runnable_name | strRequired. The name of the runnable. This name is used as the default |
api_type | strOptional. The API type to use for the language model. Used to create a default |
llm_config | Mapping[str, Any]Optional. Configuration dictionary for the language model. If provided, this configuration will be used directly. Otherwise, a default |
system_instruction | strOptional. The system instruction for the agent. This instruction is used as the default |
runnable_kwargs | Mapping[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_builder | Callable[..., "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. |
tools | Sequence[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_tracing | boolOptional. Whether to enable tracing in Cloud Trace. Defaults to False. |
instrumentor_builder | Callable[..., 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 if |
clone
clone()->vertexai.agent_engines.templates.ag2.AG2AgentReturns 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 | |
|---|---|
| Name | Description |
input | Union[str, Mapping[str, Any]]Required. The input to be passed to the Agent. |
max_turns | intOptional. The maximum number of turns to run the agent for. If not provided, the agent will run indefinitely. If |
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.