AgentBuilder - AG2

AgentBuilder

autogen.agentchat.contrib.captainagent.AgentBuilder

AgentBuilder(config_file_or_env='OAI_CONFIG_LIST', config_file_location='', llm_config=None, builder_model=[], agent_model=[], builder_model_tags=[], agent_model_tags=[], max_agents=5)

AgentBuilder can help user build an automatic task solving process powered by multi-agent system. Specifically, our building pipeline includes initialize and build.

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

PARAMETER DESCRIPTION
config_file_or_env Path to the config file or name of the environment variable containing the OpenAI API configurations. Defaults to "OAI_CONFIG_LIST".
TYPE:Optional[str]DEFAULT:'OAI_CONFIG_LIST'
config_file_location Location of the config file if not in the current directory. Defaults to "".
TYPE:Optional[str]DEFAULT:''
llm_config Specific configs for LLM
TYPE:Optional[Union[LLMConfig, dict[str, Any]]]DEFAULT:None
builder_model Model identifier(s) to use as the builder/manager model that coordinates agent creation. Can be a string or list of strings. Filters the config list to match these models. Defaults to [].
TYPE:Optional[Union[str, list]]DEFAULT:[]
agent_model Model identifier(s) to use for the generated participant agents. Can be a string or list of strings. Defaults to [].
TYPE:Optional[Union[str, list]]DEFAULT:[]
builder_model_tags Tags to filter which models from the config can be used as builder models. Defaults to [].
TYPE:Optional[list]DEFAULT:[]
agent_model_tags Tags to filter which models from the config can be used as agent models. Defaults to [].
TYPE:Optional[list]DEFAULT:[]
max_agents Maximum number of agents to create for each task. Defaults to 5.
TYPE:Optional[int]DEFAULT:5

Source code in autogen/agentchat/contrib/captainagent/agent_builder.py

``` ...

online_server_name class-attribute

online_server_name = 'online'

DEFAULT_PROXY_AUTO_REPLY class-attribute

DEFAULT_PROXY_AUTO_REPLY = 'There is no code from the last 1 message for me to execute. Group chat manager should let other participants to continue the conversation. If the group chat manager want to end the conversation, you should let other participant reply me only with "TERMINATE"'

GROUP_CHAT_DESCRIPTION class-attribute

GROUP_CHAT_DESCRIPTION = ' # Group chat instruction\nYou are now working in a group chat with different expert and a group chat manager.\nYou should refer to the previous message from other participant members or yourself, follow their topic and reply to them.\n\n**Your role is**: {name}\nGroup chat members: {members}{user_proxy_desc}\n\nWhen the task is complete and the result has been carefully verified, after obtaining agreement from the other members, you can end the conversation by replying only with "TERMINATE".\n\n# Your profile\n{sys_msg}\n'

DEFAULT_DESCRIPTION class-attribute

DEFAULT_DESCRIPTION = "## Your role\n[Complete this part with expert's name and skill description]\n\n## Task and skill instructions\n- [Complete this part with task description]\n- [Complete this part with skill description]\n- [(Optional) Complete this part with other information]\n"

CODING_AND_TASK_SKILL_INSTRUCTION class-attribute

CODING_AND_TASK_SKILL_INSTRUCTION = "## Useful instructions for task-solving\n- Solve the task step by step if you need to.\n- When you find an answer, verify the answer carefully. Include verifiable evidence with possible test case in your response if possible.\n- All your reply should be based on the provided facts.\n\n## How to verify?\n**You have to keep believing that everyone else's answers are wrong until they provide clear enough evidence.**\n- Verifying with step-by-step backward reasoning.\n- Write test cases according to the general task.\n\n## How to use code?\n- Suggest python code (in a python coding block) or shell script (in a sh coding block) for the Computer_terminal to execute.\n- If missing python packages, you can install the package by suggesting a `pip install` code in the ```sh ... ``` block.\n- When using code, you must indicate the script type in the coding block.\n- Do not the coding block which requires users to modify.\n- Do not suggest a coding block if it's not intended to be executed by the Computer_terminal.\n- The Computer_terminal cannot modify your code.\n- **Use 'print' function for the output when relevant**.\n- Check the execution result returned by the Computer_terminal.\n- Do not ask Computer_terminal to copy and paste the result.\n- If the result indicates there is an error, fix the error and output the code again."

CODING_PROMPT class-attribute

CODING_PROMPT = 'Does the following task need programming (i.e., access external API or tool by coding) to solve,\nor coding may help the following task become easier?\n\nTASK: {task}\n\nAnswer only YES or NO.\n'

AGENT_NAME_PROMPT class-attribute

AGENT_NAME_PROMPT = '# Your task\nSuggest no more than {max_agents} experts with their name according to the following user requirement.\n\n## User requirement\n{task}\n\n# Task requirement\n- Expert's name should follow the format: [skill]_Expert.\n- Only reply the names of the experts, separated by ",".\n- If coding skills are required, they should be limited to Python and Shell.\nFor example: Python_Expert, Math_Expert, ... '

AGENT_SYS_MSG_PROMPT class-attribute

AGENT_SYS_MSG_PROMPT = '# Your goal\n- According to the task and expert name, write a high-quality description for the expert by filling the given template.\n- Ensure that your description are clear and unambiguous, and include all necessary information.\n\n# Task\n{task}\n\n# Expert name\n{position}\n\n# Template\n{default_sys_msg}\n'

AGENT_DESCRIPTION_PROMPT class-attribute

AGENT_DESCRIPTION_PROMPT = "# Your goal\nSummarize the following expert's description in a sentence.\n\n# Expert name\n{position}\n\n# Expert's description\n{sys_msg}\n"

AGENT_SEARCHING_PROMPT class-attribute

AGENT_SEARCHING_PROMPT = '# Your goal\nConsidering the following task, what experts should be involved to the task?\n\n# TASK\n{task}\n\n# EXPERT LIST\n{agent_list}\n\n# Requirement\n- You should consider if the experts\' name and profile match the task.\n- Considering the effort, you should select less then {max_agents} experts; less is better.\n- Separate expert names by commas and use "_" instead of space. For example, Product_manager,Programmer\n- Only return the list of expert names.\n'

AGENT_SELECTION_PROMPT class-attribute

AGENT_SELECTION_PROMPT = '# Your goal\nMatch roles in the role set to each expert in expert set.\n\n# Skill set\n{skills}\n\n# Expert pool (formatting with name: description)\n{expert_pool}\n\n# Answer format\n```json\n{{\n    "skill_1 description": "expert_name: expert_description", // if there exists an expert that suitable for skill_1\n    "skill_2 description": "None", // if there is no experts that suitable for skill_2\n    ...\n}}\n```\n'

builder_model instance-attribute

builder_model = OpenAIWrapper(config_list=builder_config_list)

agent_model instance-attribute

agent_model = agent_model if isinstance(agent_model, list) else [agent_model]

agent_model_tags instance-attribute

agent_model_tags = agent_model_tags

config_file_or_env instance-attribute

config_file_or_env = config_file_or_env

config_file_location instance-attribute

config_file_location = config_file_location

llm_config instance-attribute

llm_config = llm_config

building_task instance-attribute

building_task = None

agent_configs instance-attribute

agent_configs = []

open_ports instance-attribute

open_ports = []

agent_procs instance-attribute

agent_procs = {}

agent_procs_assign instance-attribute

agent_procs_assign = {}

cached_configs instance-attribute

cached_configs = {}

max_agents instance-attribute

max_agents = max_agents

set_builder_model

def set_builder_model(self, model):
    self.builder_model = model

set_agent_model

def set_agent_model(self, model: str):
    self.agent_model = model

clear_agent

clear_agent(agent_name, recycle_endpoint=True)

Clear a specific agent by name.

PARAMETER DESCRIPTION
agent_name the name of agent.
TYPE:str
recycle_endpoint trigger for recycle the endpoint server. If true, the endpoint will be recycled when there is no agent depending on.
TYPE:`bool

Source code in autogen/agentchat/contrib/captainagent/agent_builder.py

``` ...

clear_all_agents

clear_all_agents(recycle_endpoint=True)

Clear all cached agents.

Source code in autogen/agentchat/contrib/captainagent/agent_builder.py

``` ...

build

build(building_task, default_llm_config, coding=None, code_execution_config=None, use_oai_assistant=False, user_proxy=None, max_agents=None, **kwargs)

Auto build agents based on the building task.

PARAMETER DESCRIPTION
building_task instruction that helps build manager (gpt-4) to decide what agent should be built.
TYPE:str
default_llm_config specific configs for LLM (e.g., config_list, seed, temperature, ...).
TYPE:`LLMConfig
coding use to identify if the user proxy (a code interpreter) should be added.
TYPE:`bool
code_execution_config specific configs for user proxy (e.g., last_n_messages, work_dir, ...).
TYPE:`dict[str, Any]
use_oai_assistant use OpenAI assistant api instead of self-constructed agent.
TYPE:`bool
user_proxy user proxy's class that can be used to replace the default user proxy.
TYPE:`ConversableAgent
max_agents Maximum number of agents to create for the task. If None, uses the value from self.max_agents.
TYPE:Optional[int], default=NoneDEFAULT:None
**kwargs Additional arguments to pass to _build_agents. - agent_configs: Optional list of predefined agent configurations to use.
TYPE:AnyDEFAULT:{}
RETURNS DESCRIPTION
agent_list a list of agents.
TYPE:list[ConversableAgent]
cached_configs cached configs.
TYPE:dict[str, Any]