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
)
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
)
Initializes the AG2 Agent.
Under-the-hood, assuming .set_up() is called, this will correspond to
# runnable_builder
runnable = runnable_builder(
llm_config=llm_config,
system_message=system_instruction,
**runnable_kwargs,
)
When everything is based on their default values, this corresponds to
# llm_config
llm_config = {
"config_list": [{
"project_id": initializer.global_config.project,
"location": initializer.global_config.location,
"model": "gemini-1.0-pro-001",
"api_type": "google",
}]
}
# runnable_builder
runnable = ConversableAgent(
llm_config=llm_config,
name="Default AG2 Agent"
system_message="You are a helpful AI Assistant.",
human_input_mode="NEVER",
)
By default, if llm_config
is not specified, a default configuration
will be created using the provided model
and api_type
.
If runnable_builder
is not specified, a default runnable builder will
be used, configured with the system_instruction
, runnable_name
and
runnable_kwargs
.
Parameters | |
---|---|
Name | Description |
model |
str
Required. The name of the model (e.g. "gemini-1.0-pro"). Used to create a default |
runnable_name |
str
Required. The name of the runnable. This name is used as the default |
api_type |
str
Optional. 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 |
str
Optional. 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 in https://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 |
bool
Optional. Whether to enable tracing in Cloud Trace. Defaults to False. |
clone
clone() -> vertexai.preview.reasoning_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 | |
---|---|
Name | Description |
input |
Union[str, Mapping[str, Any]]
Required. The input to be passed to the Agent. |
max_turns |
int
Optional. 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 to the ReasoningEngine service for deployment, as it initializes clients that can not be serialized.