AgentOptimizer

AgentOptimizer(
    max_actions_per_step: int,
    llm_config: dict,
    optimizer_model: str | None = 'gpt-4-1106-preview'
)

Base class for optimizing AutoGen agents. Specifically, it is used to optimize the functions used in the agent. More information could be found in the following paper: https://arxiv.org/abs/2402.11359.

(These APIs are experimental and may change in the future.)

Parameters:
NameDescription
max_actions_per_stepthe maximum number of actions that the optimizer can take in one step.

Type: int
llm_configllm inference configuration.

Please refer to OpenAIWrapper.create for available options.

When using OpenAI or Azure OpenAI endpoints, please specify a non-empty ‘model’ either in llm_config or in each config of ‘config_list’ in llm_config.

Type: dict
optimizer_modelthe model used for the optimizer.

Type: str | None

Default: ‘gpt-4-1106-preview’

Instance Methods

record_one_conversation

record_one_conversation(
    self,
    conversation_history: list[dict],
    is_satisfied: bool = None
) -> 

Record one conversation history.

Parameters:
NameDescription
conversation_historythe chat messages of the conversation.

Type: list[dict]
is_satisfiedwhether the user is satisfied with the solution.

If it is none, the user will be asked to input the satisfaction.

Type: bool

Default: None

reset_optimizer

reset_optimizer(self) -> 

Reset the optimizer.


step

step(self) -> 

One step of training. It will return register_for_llm and register_for_executor at each iteration, which are subsequently utilized to update the assistant and executor agents, respectively. See example: https://github.com/ag2ai/ag2/blob/main/notebook/agentchat_agentoptimizer.ipynb