> ## 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.captainagent.AgentBuilder

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

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

```python theme={null}
AgentBuilder(
    config_file_or_env: str | None = 'OAI_CONFIG_LIST',
    config_file_location: str | None = '',
    llm_config: LLMConfig | dict[str, Any] | None = None,
    builder_model: str | list | None = [],
    agent_model: str | list | None = [],
    builder_model_tags: list | None = [],
    agent_model_tags: list | None = [],
    max_agents: int | None = 5
)
```

AgentBuilder can help user build an automatic task solving process powered by multi-agent system.<br />Specifically, our building pipeline includes initialize and build.<br />(These APIs are experimental and may change in the future.)

<b>Parameters:</b>

| Name                   | Description                                                                                                                            |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `config_file_or_env`   | **Type:** str \| None<br /><br />**Default:** 'OAI\_CONFIG\_LIST'                                                                      |
| `config_file_location` | **Type:** str \| None<br /><br />**Default:** ''                                                                                       |
| `llm_config`           | **Type:** [LLMConfig](/docs/api-reference/autogen/llm_config/LLMConfig) \| dict\[str, typing.Any] \| None<br /><br />**Default:** None |
| `builder_model`        | **Type:** str \| list \| None<br /><br />**Default:** \[]                                                                              |
| `agent_model`          | **Type:** str \| list \| None<br /><br />**Default:** \[]                                                                              |
| `builder_model_tags`   | **Type:** list \| None<br /><br />**Default:** \[]                                                                                     |
| `agent_model_tags`     | **Type:** list \| None<br /><br />**Default:** \[]                                                                                     |
| `max_agents`           | **Type:** int \| None<br /><br />**Default:** 5                                                                                        |

### Class Attributes

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

#### AGENT\_DESCRIPTION\_PROMPT

<br />

<br />

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

#### AGENT\_NAME\_PROMPT

<br />

<br />

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

#### AGENT\_SEARCHING\_PROMPT

<br />

<br />

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

#### AGENT\_SELECTION\_PROMPT

<br />

<br />

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

#### AGENT\_SYS\_MSG\_PROMPT

<br />

<br />

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

#### CODING\_AND\_TASK\_SKILL\_INSTRUCTION

<br />

<br />

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

#### CODING\_PROMPT

<br />

<br />

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

#### DEFAULT\_DESCRIPTION

<br />

<br />

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

#### DEFAULT\_PROXY\_AUTO\_REPLY

<br />

<br />

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

#### GROUP\_CHAT\_DESCRIPTION

<br />

<br />

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

#### online\_server\_name

<br />

<br />

### Instance Methods

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

#### build

```python theme={null}
build(
    self,
    building_task: str,
    default_llm_config: LLMConfig | dict[str, Any],
    coding: bool | None = None,
    code_execution_config: dict[str, Any] | None = None,
    use_oai_assistant: bool | None = False,
    user_proxy: ConversableAgent | None = None,
    max_agents: int | None = None,
    **kwargs: Any
) -> tuple[list[ConversableAgent], dict[str, Any]]
```

Auto build agents based on the building task.<br />

<b>Parameters:</b>

| Name                    | Description                                                                                                                                                                                       |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `building_task`         | instruction that helps build manager (gpt-4) to decide what agent should be built.<br /><br />**Type:** str                                                                                       |
| `default_llm_config`    | specific configs for LLM (e.g., config\_list, seed, temperature, ...).<br /><br />**Type:** [LLMConfig](/docs/api-reference/autogen/llm_config/LLMConfig) \| dict\[str, typing.Any]               |
| `coding`                | use to identify if the user proxy (a code interpreter) should be added.<br /><br />**Type:** bool \| None<br /><br />**Default:** None                                                            |
| `code_execution_config` | specific configs for user proxy (e.g., last\_n\_messages, work\_dir, ...).<br /><br />**Type:** dict\[str, typing.Any] \| None<br /><br />**Default:** None                                       |
| `use_oai_assistant`     | use OpenAI assistant api instead of self-constructed agent.<br /><br />**Type:** bool \| None<br /><br />**Default:** False                                                                       |
| `user_proxy`            | user proxy's class that can be used to replace the default user proxy.<br /><br />**Type:** [ConversableAgent](/docs/api-reference/autogen/ConversableAgent) \| None<br /><br />**Default:** None |
| `max_agents`            | Maximum number of agents to create for the task.<br /><br />If None, uses the value from self.max\_agents.<br /><br />**Type:** int \| None<br /><br />**Default:** None                          |
| `**kwargs`              | Additional arguments to pass to \_build\_agents.<br /><br />- agent\_configs: Optional list of predefined agent configurations to use.<br /><br />**Type:** Any                                   |

<b>Returns:</b>

| Type                                                                                                    | Description                                                     |
| ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| tuple\[list\[[ConversableAgent](/docs/api-reference/autogen/ConversableAgent)], dict\[str, typing.Any]] | agent\_list: a list of agents. cached\_configs: cached configs. |

<br />

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

#### build\_from\_library

```python theme={null}
build_from_library(
    self,
    building_task: str,
    library_path_or_json: str,
    default_llm_config: LLMConfig | dict[str, Any],
    top_k: int = 3,
    coding: bool | None = None,
    code_execution_config: dict[str, Any] | None = None,
    use_oai_assistant: bool | None = False,
    embedding_model: str | None = 'all-mpnet-base-v2',
    user_proxy: ConversableAgent | None = None,
    **kwargs: Any
) -> tuple[list[ConversableAgent], dict[str, Any]]
```

Build agents from a library.<br />The library is a list of agent configs, which contains the name and system\_message for each agent.<br />We use a build manager to decide what agent in that library should be involved to the task.<br />

<b>Parameters:</b>

| Name                    | Description                                                                                                                                                                                                                                  |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `building_task`         | instruction that helps build manager (gpt-4) to decide what agent should be built.<br /><br />**Type:** str                                                                                                                                  |
| `library_path_or_json`  | path or JSON string config of agent library.<br /><br />**Type:** str                                                                                                                                                                        |
| `default_llm_config`    | specific configs for LLM (e.g., config\_list, seed, temperature, ...).<br /><br />**Type:** [LLMConfig](/docs/api-reference/autogen/llm_config/LLMConfig) \| dict\[str, typing.Any]                                                          |
| `top_k`                 | number of results to return.<br /><br />**Type:** int<br /><br />**Default:** 3                                                                                                                                                              |
| `coding`                | use to identify if the user proxy (a code interpreter) should be added.<br /><br />**Type:** bool \| None<br /><br />**Default:** None                                                                                                       |
| `code_execution_config` | specific configs for user proxy (e.g., last\_n\_messages, work\_dir, ...).<br /><br />**Type:** dict\[str, typing.Any] \| None<br /><br />**Default:** None                                                                                  |
| `use_oai_assistant`     | use OpenAI assistant api instead of self-constructed agent.<br /><br />**Type:** bool \| None<br /><br />**Default:** False                                                                                                                  |
| `embedding_model`       | a Sentence-Transformers model use for embedding similarity to select agents from library.<br /><br />As reference, chromadb use "all-mpnet-base-v2" as default.<br /><br />**Type:** str \| None<br /><br />**Default:** 'all-mpnet-base-v2' |
| `user_proxy`            | user proxy's class that can be used to replace the default user proxy.<br /><br />**Type:** [ConversableAgent](/docs/api-reference/autogen/ConversableAgent) \| None<br /><br />**Default:** None                                            |
| `**kwargs`              | Additional arguments to pass to \_build\_agents.<br /><br />**Type:** Any                                                                                                                                                                    |

<b>Returns:</b>

| Type                                                                                                    | Description                                                     |
| ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| tuple\[list\[[ConversableAgent](/docs/api-reference/autogen/ConversableAgent)], dict\[str, typing.Any]] | agent\_list: a list of agents. cached\_configs: cached configs. |

<br />

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

#### clear\_agent

```python theme={null}
clear_agent(
    self,
    agent_name: str,
    recycle_endpoint: bool | None = True
) -> 
```

Clear a specific agent by name.<br />

<b>Parameters:</b>

| Name               | Description                                                                                                                                                                                    |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `agent_name`       | the name of agent.<br /><br />**Type:** str                                                                                                                                                    |
| `recycle_endpoint` | trigger for recycle the endpoint server.<br /><br />If true, the endpoint will be recycled when there is no agent depending on.<br /><br />**Type:** bool \| None<br /><br />**Default:** True |

<br />

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

#### clear\_all\_agents

```python theme={null}
clear_all_agents(self, recycle_endpoint: bool | None = True) -> 
```

Clear all cached agents.

<b>Parameters:</b>

| Name               | Description                                         |
| ------------------ | --------------------------------------------------- |
| `recycle_endpoint` | **Type:** bool \| None<br /><br />**Default:** True |

<br />

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

#### load

```python theme={null}
load(
    self,
    filepath: str | None = None,
    config_json: str | None = None,
    use_oai_assistant: bool | None = False,
    **kwargs: Any
) -> tuple[list[ConversableAgent], dict[str, Any]]
```

Load building configs and call the build function to complete building without calling online LLMs' api.<br />

<b>Parameters:</b>

| Name                | Description                                                                                                                                                                                                       |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `filepath`          | filepath or JSON string for the save config.<br /><br />**Type:** str \| None<br /><br />**Default:** None                                                                                                        |
| `config_json`       | JSON string for the save config.<br /><br />**Type:** str \| None<br /><br />**Default:** None                                                                                                                    |
| `use_oai_assistant` | use OpenAI assistant api instead of self-constructed agent.<br /><br />**Type:** bool \| None<br /><br />**Default:** False                                                                                       |
| `**kwargs`          | Additional arguments to pass to \_build\_agents: - code\_execution\_config (Optional\[dict\[str, Any]]): If provided, overrides the code execution configuration from the loaded config.<br /><br />**Type:** Any |

<b>Returns:</b>

| Type                                                                                                    | Description                                                     |
| ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| tuple\[list\[[ConversableAgent](/docs/api-reference/autogen/ConversableAgent)], dict\[str, typing.Any]] | agent\_list: a list of agents. cached\_configs: cached configs. |

<br />

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

#### save

```python theme={null}
save(self, filepath: str | None = None) -> str
```

Save building configs. If the filepath is not specific, this function will create a filename by encrypt the
building\_task string by md5 with "save\_config\_" prefix, and save config to the local path.<br />

<b>Parameters:</b>

| Name       | Description                                                              |
| ---------- | ------------------------------------------------------------------------ |
| `filepath` | save path.<br /><br />**Type:** str \| None<br /><br />**Default:** None |

<br />

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

#### set\_agent\_model

```python theme={null}
set_agent_model(self, model: str) -> 
```

<b>Parameters:</b>

| Name    | Description   |
| ------- | ------------- |
| `model` | **Type:** str |

<br />

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

#### set\_builder\_model

```python theme={null}
set_builder_model(self, model: str) -> 
```

<b>Parameters:</b>

| Name    | Description   |
| ------- | ------------- |
| `model` | **Type:** str |

<br />
