> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ag2.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# autogen.agentchat.contrib.agent_optimizer.AgentOptimizer

<h2 id="autogen.agentchat.contrib.agent_optimizer.AgentOptimizer" class="doc doc-heading">
  <code class="doc-symbol doc-symbol-heading doc-symbol-class" />

  <span class="doc doc-object-name doc-class-name">AgentOptimizer</span>
</h2>

```python theme={null}
AgentOptimizer(
    max_actions_per_step: int,
    llm_config: LLMConfig | dict[str, Any],
    optimizer_model: str | None = 'gpt-4-1106-preview'
)
```

Base class for optimizing AG2 agents. Specifically, it is used to optimize the functions used in the agent.<br />More information could be found in the following paper: [https://arxiv.org/abs/2402.11359](https://arxiv.org/abs/2402.11359).<br />(These APIs are experimental and may change in the future.)

<b>Parameters:</b>

| Name                   | Description                                                                                       |
| ---------------------- | ------------------------------------------------------------------------------------------------- |
| `max_actions_per_step` | **Type:** int                                                                                     |
| `llm_config`           | **Type:** [LLMConfig](/docs/api-reference/autogen/llm_config/LLMConfig) \| dict\[str, typing.Any] |
| `optimizer_model`      | **Type:** str \| None<br /><br />**Default:** 'gpt-4-1106-preview'                                |

### Instance Methods

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### record\_one\_conversation

```python theme={null}
record_one_conversation(
    self,
    conversation_history: list[dict[str, Any]],
    is_satisfied: bool = None
) -> 
```

Record one conversation history.<br />

<b>Parameters:</b>

| Name                   | Description                                                                                                                                                                         |
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `conversation_history` | the chat messages of the conversation.<br /><br />**Type:** list\[dict\[str, typing.Any]]                                                                                           |
| `is_satisfied`         | whether the user is satisfied with the solution.<br /><br />If it is none, the user will be asked to input the satisfaction.<br /><br />**Type:** bool<br /><br />**Default:** None |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### reset\_optimizer

```python theme={null}
reset_optimizer(self) -> 
```

Reset the optimizer.

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### step

```python theme={null}
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.<br />See example: [https://github.com/ag2ai/ag2/blob/main/notebook/agentchat\_agentoptimizer.ipynb](https://github.com/ag2ai/ag2/blob/main/notebook/agentchat_agentoptimizer.ipynb)

<br />
