[Autobuild] improve robustness and reduce cost (#2907)

* Update Autobuild.

* merge main into autobuild

* update test for new autobuild

* update author info

* fix pre-commit

* Update autobuild notebook

* Update autobuild_agent_library.ipynb

* Update autobuild_agent_library.ipynb

* Fix pre-commit failures.

---------

Co-authored-by: Linxin Song <rm.social.song1@gmail.com>
Co-authored-by: Chi Wang <wang.chi@microsoft.com>
This commit is contained in:
LeoLjl 2024-06-14 22:14:08 +08:00 committed by GitHub
parent 55b2df8bf9
commit c54e8a5db1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 4413 additions and 2228 deletions

View File

@ -1,12 +1,20 @@
import hashlib
import importlib
import json
import logging
import re
import socket
import subprocess as sp
import time
from typing import Dict, List, Optional, Tuple
from typing import Dict, List, Optional, Tuple, Union
import requests
from termcolor import colored
import autogen
logger = logging.getLogger(__name__)
def _config_check(config: Dict):
# check config loading
@ -16,113 +24,162 @@ def _config_check(config: Dict):
for agent_config in config["agent_configs"]:
assert agent_config.get("name", None) is not None, 'Missing agent "name" in your agent_configs.'
assert agent_config.get("model", None) is not None, 'Missing agent "model" in your agent_configs.'
assert (
agent_config.get("system_message", None) is not None
), 'Missing agent "system_message" in your agent_configs.'
assert agent_config.get("description", None) is not None, 'Missing agent "description" in your agent_configs.'
def _retrieve_json(text):
match = re.findall(autogen.code_utils.CODE_BLOCK_PATTERN, text, flags=re.DOTALL)
if not match:
return text
code_blocks = []
for _, code in match:
code_blocks.append(code)
return code_blocks[0]
class AgentBuilder:
"""
AgentBuilder can help user build an automatic task solving process powered by multi-agent system.
Specifically, our building pipeline includes initialize and build.
In build(), we prompt a LLM to create multiple participant agents, and specify whether this task need programming to solve.
User can save the built agents' config by calling save(), and load the saved configs by load(), which can skip the
building process.
"""
online_server_name = "online"
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 = """ # Group chat instruction
You are now working in a group chat with different expert and a group chat manager.
You should refer to the previous message from other participant members or yourself, follow their topic and reply to them.
**Your role is**: {name}
Group chat members: {members}{user_proxy_desc}
When 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".
# Your profile
{sys_msg}
"""
DEFAULT_DESCRIPTION = """## Your role
[Complete this part with expert's name and skill description]
## Task and skill instructions
- [Complete this part with task description]
- [Complete this part with skill description]
- [(Optional) Complete this part with other information]
"""
CODING_AND_TASK_SKILL_INSTRUCTION = """## Useful instructions for task-solving
- Solve the task step by step if you need to.
- When you find an answer, verify the answer carefully. Include verifiable evidence with possible test case in your response if possible.
- All your reply should be based on the provided facts.
## How to verify?
**You have to keep believing that everyone else's answers are wrong until they provide clear enough evidence.**
- Verifying with step-by-step backward reasoning.
- Write test cases according to the general task.
## How to use code?
- Suggest python code (in a python coding block) or shell script (in a sh coding block) for the Computer_terminal to execute.
- If missing python packages, you can install the package by suggesting a `pip install` code in the ```sh ... ``` block.
- When using code, you must indicate the script type in the coding block.
- Do not the coding block which requires users to modify.
- Do not suggest a coding block if it's not intended to be executed by the Computer_terminal.
- The Computer_terminal cannot modify your code.
- **Use 'print' function for the output when relevant**.
- Check the execution result returned by the Computer_terminal.
- Do not ask Computer_terminal to copy and paste the result.
- If the result indicates there is an error, fix the error and output the code again. """
CODING_PROMPT = """Does the following task need programming (i.e., access external API or tool by coding) to solve,
or coding may help the following task become easier?
or coding may help the following task become easier?
TASK: {task}
TASK: {task}
Hint:
# Answer only YES or NO.
"""
Answer only YES or NO.
"""
AGENT_NAME_PROMPT = """To complete the following task, what positions/jobs should be set to maximize efficiency?
AGENT_NAME_PROMPT = """# Your task
Suggest no more then {max_agents} experts with their name according to the following user requirement.
TASK: {task}
## User requirement
{task}
Hint:
# Considering the effort, the position in this task should be no more than {max_agents}; less is better.
# These positions' name should include enough information that can help a group chat manager know when to let this position speak.
# The position name should be as specific as possible. For example, use "python_programmer" instead of "programmer".
# Do not use ambiguous position name, such as "domain expert" with no specific description of domain or "technical writer" with no description of what it should write.
# Each position should have a unique function and the position name should reflect this.
# The positions should relate to the task and significantly different in function.
# Add ONLY ONE programming related position if the task needs coding.
# Generated agent's name should follow the format of ^[a-zA-Z0-9_-]{{1,64}}$, use "_" to split words.
# Answer the names of those positions/jobs, separated names by commas.
# Only return the list of positions.
"""
# Task requirement
- Expert's name should follow the format: [skill]_Expert.
- Only reply the names of the experts, separated by ",".
For example: Python_Expert, Math_Expert, ... """
AGENT_SYS_MSG_PROMPT = """Considering the following position and task:
AGENT_SYS_MSG_PROMPT = """# Your goal
- According to the task and expert name, write a high-quality description for the expert by filling the given template.
- Ensure that your description are clear and unambiguous, and include all necessary information.
TASK: {task}
POSITION: {position}
# Task
{task}
Modify the following position requirement, making it more suitable for the above task and position:
# Expert name
{position}
REQUIREMENT: {default_sys_msg}
# Template
{default_sys_msg}
"""
Hint:
# Your answer should be natural, starting from "You are now in a group chat. You need to complete a task with other participants. As a ...".
# [IMPORTANT] You should let them reply "TERMINATE" when they think the task is completed (the user's need has actually been satisfied).
# The modified requirement should not contain the code interpreter skill.
# You should remove the related skill description when the position is not a programmer or developer.
# Coding skill is limited to Python.
# Your answer should omit the word "REQUIREMENT".
# People with the above position can doubt previous messages or code in the group chat (for example, if there is no
output after executing the code) and provide a corrected answer or code.
# People in the above position should ask for help from the group chat manager when confused and let the manager select another participant.
"""
AGENT_DESCRIPTION_PROMPT = """# Your goal
Summarize the following expert's description in a sentence.
AGENT_DESCRIPTION_PROMPT = """Considering the following position:
# Expert name
{position}
POSITION: {position}
# Expert's description
{sys_msg}
"""
What requirements should this position be satisfied?
AGENT_SEARCHING_PROMPT = """# Your goal
Considering the following task, what experts should be involved to the task?
Hint:
# This description should include enough information that can help a group chat manager know when to let this position speak.
# People with the above position can doubt previous messages or code in the group chat (for example, if there is no
output after executing the code) and provide a corrected answer or code.
# Your answer should be in at most three sentences.
# Your answer should be natural, starting from "[POSITION's name] is a ...".
# Your answer should include the skills that this position should have.
# Your answer should not contain coding-related skills when the position is not a programmer or developer.
# Coding skills should be limited to Python.
"""
# TASK
{task}
AGENT_SEARCHING_PROMPT = """Considering the following task:
# EXPERT LIST
{agent_list}
TASK: {task}
# Requirement
- You should consider if the experts' name and profile match the task.
- Considering the effort, you should select less then {max_agents} experts; less is better.
- Separate expert names by commas and use "_" instead of space. For example, Product_manager,Programmer
- Only return the list of expert names.
"""
What following agents should be involved to the task?
AGENT_SELECTION_PROMPT = """# Your goal
Match roles in the role set to each expert in expert set.
AGENT LIST:
{agent_list}
# Skill set
{skills}
Hint:
# You should consider if the agent's name and profile match the task.
# Considering the effort, you should select less then {max_agents} agents; less is better.
# Separate agent names by commas and use "_" instead of space. For example, Product_manager,Programmer
# Only return the list of agent names.
"""
# Expert pool (formatting with name: description)
{expert_pool}
# Answer format
```json
{{
"skill_1 description": "expert_name: expert_description", // if there exists an expert that suitable for skill_1
"skill_2 description": "None", // if there is no experts that suitable for skill_2
...
}}
```
"""
def __init__(
self,
config_file_or_env: Optional[str] = "OAI_CONFIG_LIST",
config_file_location: Optional[str] = "",
builder_model: Optional[str] = "gpt-4",
agent_model: Optional[str] = "gpt-4",
host: Optional[str] = "localhost",
endpoint_building_timeout: Optional[int] = 600,
max_tokens: Optional[int] = 945,
builder_model: Optional[Union[str, list]] = [],
agent_model: Optional[Union[str, list]] = [],
builder_model_tags: Optional[list] = [],
agent_model_tags: Optional[list] = [],
max_agents: Optional[int] = 5,
):
"""
@ -131,17 +188,27 @@ output after executing the code) and provide a corrected answer or code.
config_file_or_env: path or environment of the OpenAI api configs.
builder_model: specify a model as the backbone of build manager.
agent_model: specify a model as the backbone of participant agents.
host: endpoint host.
endpoint_building_timeout: timeout for building up an endpoint server.
max_tokens: max tokens for each agent.
max_agents: max agents for each task.
"""
self.host = host
self.builder_model = builder_model
self.agent_model = agent_model
builder_model = builder_model if isinstance(builder_model, list) else [builder_model]
builder_filter_dict = {}
if len(builder_model) != 0:
builder_filter_dict.update({"model": builder_model})
if len(builder_model_tags) != 0:
builder_filter_dict.update({"tags": builder_model_tags})
builder_config_list = autogen.config_list_from_json(config_file_or_env, filter_dict=builder_filter_dict)
if len(builder_config_list) == 0:
raise RuntimeError(
f"Fail to initialize build manager: {builder_model}{builder_model_tags} does not exist in {config_file_or_env}. "
f'If you want to change this model, please specify the "builder_model" in the constructor.'
)
self.builder_model = autogen.OpenAIWrapper(config_list=builder_config_list)
self.agent_model = agent_model if isinstance(agent_model, list) else [agent_model]
self.agent_model_tags = agent_model_tags
self.config_file_or_env = config_file_or_env
self.config_file_location = config_file_location
self.endpoint_building_timeout = endpoint_building_timeout
self.building_task: str = None
self.agent_configs: List[Dict] = []
@ -150,40 +217,20 @@ output after executing the code) and provide a corrected answer or code.
self.agent_procs_assign: Dict[str, Tuple[autogen.ConversableAgent, str]] = {}
self.cached_configs: Dict = {}
self.max_tokens = max_tokens
self.max_agents = max_agents
for port in range(8000, 65535):
if self._is_port_open(host, port):
self.open_ports.append(str(port))
def set_builder_model(self, model: str):
self.builder_model = model
def set_agent_model(self, model: str):
self.agent_model = model
@staticmethod
def _is_port_open(host, port):
"""Check if a tcp port is open."""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(10)
s.bind((host, int(port)))
s.close()
return True
except OSError:
return False
def _create_agent(
self,
agent_name: str,
model_name_or_hf_repo: str,
agent_config: Dict,
member_name: List[str],
llm_config: dict,
system_message: Optional[str] = autogen.AssistantAgent.DEFAULT_SYSTEM_MESSAGE,
description: Optional[str] = autogen.AssistantAgent.DEFAULT_DESCRIPTION,
use_oai_assistant: Optional[bool] = False,
world_size: Optional[int] = 1,
) -> autogen.AssistantAgent:
"""
Create a group chat participant agent.
@ -192,102 +239,46 @@ output after executing the code) and provide a corrected answer or code.
The API address of that endpoint will be "localhost:{free port}".
Args:
agent_name: the name that identify the function of the agent (e.g., Coder, Product Manager,...)
model_name_or_hf_repo: the name of the model or the huggingface repo.
agent_config: agent's config. It should include the following information:
1. model_name: backbone model of an agent, e.g., gpt-4-1106-preview, meta/Llama-2-70b-chat
2. agent_name: use to identify an agent in the group chat.
3. system_message: including persona, task solving instruction, etc.
4. description: brief description of an agent that help group chat manager to pick the speaker.
llm_config: specific configs for LLM (e.g., config_list, seed, temperature, ...).
system_message: system prompt use to format an agent's behavior.
description: a brief description of the agent. This will improve the group chat performance.
use_oai_assistant: use OpenAI assistant api instead of self-constructed agent.
world_size: the max size of parallel tensors (in most of the cases, this is identical to the amount of GPUs).
Returns:
agent: a set-up agent.
"""
model_name_or_hf_repo = agent_config.get("model", [])
model_name_or_hf_repo = (
model_name_or_hf_repo if isinstance(model_name_or_hf_repo, list) else [model_name_or_hf_repo]
)
model_tags = agent_config.get("tags", [])
agent_name = agent_config["name"]
system_message = agent_config["system_message"]
description = agent_config["description"]
# Path to the customize **ConversableAgent** class.
model_path = agent_config.get("model_path", None)
filter_dict = {}
if len(model_name_or_hf_repo) > 0:
filter_dict.update({"model": model_name_or_hf_repo})
if len(model_tags) > 0:
filter_dict.update({"tags": model_tags})
config_list = autogen.config_list_from_json(
self.config_file_or_env,
file_location=self.config_file_location,
filter_dict={"model": [model_name_or_hf_repo]},
self.config_file_or_env, file_location=self.config_file_location, filter_dict=filter_dict
)
if len(config_list) == 0:
raise RuntimeError(
f"Fail to initialize agent {agent_name}: {model_name_or_hf_repo} does not exist in {self.config_file_or_env}.\n"
f"Fail to initialize agent {agent_name}: {model_name_or_hf_repo}{model_tags} does not exist in {self.config_file_or_env}.\n"
f'If you would like to change this model, please specify the "agent_model" in the constructor.\n'
f"If you load configs from json, make sure the model in agent_configs is in the {self.config_file_or_env}."
)
try:
from huggingface_hub import HfApi
from huggingface_hub.utils import GatedRepoError, RepositoryNotFoundError
hf_api = HfApi()
hf_api.model_info(model_name_or_hf_repo)
model_name = model_name_or_hf_repo.split("/")[-1]
server_id = f"{model_name}_{self.host}"
except ImportError:
server_id = self.online_server_name
except GatedRepoError as e:
raise e
except RepositoryNotFoundError:
server_id = self.online_server_name
if server_id != self.online_server_name:
# The code in this block is uncovered by tests because online environment does not support gpu use.
if self.agent_procs.get(server_id, None) is None:
while True:
port = self.open_ports.pop()
if self._is_port_open(self.host, port):
break
# Use vLLM to set up a server with OpenAI API support.
agent_proc = sp.Popen(
[
"python",
"-m",
"vllm.entrypoints.openai.api_server",
"--host",
f"{self.host}",
"--port",
f"{port}",
"--model",
f"{model_name_or_hf_repo}",
"--tensor-parallel-size",
f"{world_size}",
],
stdout=sp.PIPE,
stderr=sp.STDOUT,
)
timeout_start = time.time()
while True:
server_stdout = agent_proc.stdout.readline()
if server_stdout != b"":
print(server_stdout)
timeout_end = time.time()
if b"running" in server_stdout:
print(
f"Running {model_name_or_hf_repo} on http://{self.host}:{port} "
f"with tensor parallel size {world_size}."
)
break
elif b"address already in use" in server_stdout:
raise RuntimeError(
f"{self.host}:{port} already in use. Fail to set up the endpoint for "
f"{model_name_or_hf_repo} on {self.host}:{port}."
)
elif timeout_end - timeout_start > self.endpoint_building_timeout:
raise RuntimeError(
f"Timeout exceed. Fail to set up the endpoint for "
f"{model_name_or_hf_repo} on {self.host}:{port}."
)
self.agent_procs[server_id] = (agent_proc, port)
else:
port = self.agent_procs[server_id][1]
config_list[0]["base_url"] = f"http://{self.host}:{port}/v1"
server_id = self.online_server_name
current_config = llm_config.copy()
current_config.update(
{"config_list": config_list, "model": model_name_or_hf_repo, "max_tokens": self.max_tokens}
)
current_config.update({"config_list": config_list})
if use_oai_assistant:
from autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent
@ -298,12 +289,38 @@ output after executing the code) and provide a corrected answer or code.
overwrite_instructions=False,
)
else:
agent = autogen.AssistantAgent(
name=agent_name,
llm_config=current_config.copy(),
system_message=system_message,
description=description,
user_proxy_desc = ""
if self.cached_configs["coding"] is True:
user_proxy_desc = (
"\nThe group also include a Computer_terminal to help you run the python and shell code."
)
model_class = autogen.AssistantAgent
if model_path:
module_path, model_class_name = model_path.replace("/", ".").rsplit(".", 1)
module = importlib.import_module(module_path)
model_class = getattr(module, model_class_name)
if not issubclass(model_class, autogen.ConversableAgent):
logger.error(f"{model_class} is not a ConversableAgent. Use AssistantAgent as default")
model_class = autogen.AssistantAgent
additional_config = {
k: v
for k, v in agent_config.items()
if k not in ["model", "name", "system_message", "description", "model_path", "tags"]
}
agent = model_class(
name=agent_name, llm_config=current_config.copy(), description=description, **additional_config
)
if system_message == "":
system_message = agent.system_message
else:
system_message = f"{system_message}\n\n{self.CODING_AND_TASK_SKILL_INSTRUCTION}"
enhanced_sys_msg = self.GROUP_CHAT_DESCRIPTION.format(
name=agent_name, members=member_name, user_proxy_desc=user_proxy_desc, sys_msg=system_message
)
agent.update_system_message(enhanced_sys_msg)
self.agent_procs_assign[agent_name] = (agent, server_id)
return agent
@ -327,7 +344,7 @@ output after executing the code) and provide a corrected answer or code.
return
self.agent_procs[server_id][0].terminate()
self.open_ports.append(server_id.split("_")[-1])
print(f"Agent {agent_name} has been cleared.")
print(colored(f"Agent {agent_name} has been cleared.", "yellow"), flush=True)
def clear_all_agents(self, recycle_endpoint: Optional[bool] = True):
"""
@ -335,7 +352,7 @@ output after executing the code) and provide a corrected answer or code.
"""
for agent_name in [agent_name for agent_name in self.agent_procs_assign.keys()]:
self.clear_agent(agent_name, recycle_endpoint)
print("All agents have been cleared.")
print(colored("All agents have been cleared.", "yellow"), flush=True)
def build(
self,
@ -344,6 +361,8 @@ output after executing the code) and provide a corrected answer or code.
coding: Optional[bool] = None,
code_execution_config: Optional[Dict] = None,
use_oai_assistant: Optional[bool] = False,
user_proxy: Optional[autogen.ConversableAgent] = None,
max_agents: Optional[int] = None,
**kwargs,
) -> Tuple[List[autogen.ConversableAgent], Dict]:
"""
@ -355,6 +374,7 @@ output after executing the code) and provide a corrected answer or code.
code_execution_config: specific configs for user proxy (e.g., last_n_messages, work_dir, ...).
default_llm_config: specific configs for LLM (e.g., config_list, seed, temperature, ...).
use_oai_assistant: use OpenAI assistant api instead of self-constructed agent.
user_proxy: user proxy's class that can be used to replace the default user proxy.
Returns:
agent_list: a list of agents.
@ -362,34 +382,25 @@ output after executing the code) and provide a corrected answer or code.
"""
if code_execution_config is None:
code_execution_config = {
"last_n_messages": 2,
"last_n_messages": 1,
"work_dir": "groupchat",
"use_docker": False,
"timeout": 60,
"timeout": 10,
}
if max_agents is None:
max_agents = self.max_agents
agent_configs = []
self.building_task = building_task
config_list = autogen.config_list_from_json(
self.config_file_or_env,
file_location=self.config_file_location,
filter_dict={"model": [self.builder_model]},
)
if len(config_list) == 0:
raise RuntimeError(
f"Fail to initialize build manager: {self.builder_model} does not exist in {self.config_file_or_env}. "
f'If you want to change this model, please specify the "builder_model" in the constructor.'
)
build_manager = autogen.OpenAIWrapper(config_list=config_list)
print("==> Generating agents...")
print(colored("==> Generating agents...", "green"), flush=True)
resp_agent_name = (
build_manager.create(
self.builder_model.create(
messages=[
{
"role": "user",
"content": self.AGENT_NAME_PROMPT.format(task=building_task, max_agents=self.max_agents),
"content": self.AGENT_NAME_PROMPT.format(task=building_task, max_agents=max_agents),
}
]
)
@ -397,21 +408,21 @@ output after executing the code) and provide a corrected answer or code.
.message.content
)
agent_name_list = [agent_name.strip().replace(" ", "_") for agent_name in resp_agent_name.split(",")]
print(f"{agent_name_list} are generated.")
print(f"{agent_name_list} are generated.", flush=True)
print("==> Generating system message...")
print(colored("==> Generating system message...", "green"), flush=True)
agent_sys_msg_list = []
for name in agent_name_list:
print(f"Preparing system message for {name}")
print(f"Preparing system message for {name}", flush=True)
resp_agent_sys_msg = (
build_manager.create(
self.builder_model.create(
messages=[
{
"role": "user",
"content": self.AGENT_SYS_MSG_PROMPT.format(
task=building_task,
position=name,
default_sys_msg=autogen.AssistantAgent.DEFAULT_SYSTEM_MESSAGE,
default_sys_msg=self.DEFAULT_DESCRIPTION,
),
}
]
@ -421,16 +432,16 @@ output after executing the code) and provide a corrected answer or code.
)
agent_sys_msg_list.append(resp_agent_sys_msg)
print("==> Generating description...")
print(colored("==> Generating description...", "green"), flush=True)
agent_description_list = []
for name in agent_name_list:
print(f"Preparing description for {name}")
for name, sys_msg in list(zip(agent_name_list, agent_sys_msg_list)):
print(f"Preparing description for {name}", flush=True)
resp_agent_description = (
build_manager.create(
self.builder_model.create(
messages=[
{
"role": "user",
"content": self.AGENT_DESCRIPTION_PROMPT.format(position=name),
"content": self.AGENT_DESCRIPTION_PROMPT.format(position=name, sys_msg=sys_msg),
}
]
)
@ -441,12 +452,18 @@ output after executing the code) and provide a corrected answer or code.
for name, sys_msg, description in list(zip(agent_name_list, agent_sys_msg_list, agent_description_list)):
agent_configs.append(
{"name": name, "model": self.agent_model, "system_message": sys_msg, "description": description}
{
"name": name,
"model": self.agent_model,
"tags": self.agent_model_tags,
"system_message": sys_msg,
"description": description,
}
)
if coding is None:
resp = (
build_manager.create(
self.builder_model.create(
messages=[{"role": "user", "content": self.CODING_PROMPT.format(task=building_task)}]
)
.choices[0]
@ -463,18 +480,20 @@ output after executing the code) and provide a corrected answer or code.
"code_execution_config": code_execution_config,
}
)
return self._build_agents(use_oai_assistant, **kwargs)
_config_check(self.cached_configs)
return self._build_agents(use_oai_assistant, user_proxy=user_proxy, **kwargs)
def build_from_library(
self,
building_task: str,
library_path_or_json: str,
default_llm_config: Dict,
coding: Optional[bool] = True,
top_k: int = 3,
coding: Optional[bool] = None,
code_execution_config: Optional[Dict] = None,
use_oai_assistant: Optional[bool] = False,
embedding_model: Optional[str] = None,
embedding_model: Optional[str] = "all-mpnet-base-v2",
user_proxy: Optional[autogen.ConversableAgent] = None,
**kwargs,
) -> Tuple[List[autogen.ConversableAgent], Dict]:
"""
@ -490,81 +509,83 @@ output after executing the code) and provide a corrected answer or code.
code_execution_config: specific configs for user proxy (e.g., last_n_messages, work_dir, ...).
use_oai_assistant: use OpenAI assistant api instead of self-constructed agent.
embedding_model: a Sentence-Transformers model use for embedding similarity to select agents from library.
if None, an openai model will be prompted to select agents. As reference, chromadb use "all-mpnet-base-
v2" as default.
As reference, chromadb use "all-mpnet-base-v2" as default.
user_proxy: user proxy's class that can be used to replace the default user proxy.
Returns:
agent_list: a list of agents.
cached_configs: cached configs.
"""
import sqlite3
# Some system will have an unexcepted sqlite3 version.
# Check if the user has installed pysqlite3.
if int(sqlite3.version.split(".")[0]) < 3:
try:
__import__("pysqlite3")
import sys
sys.modules["sqlite3"] = sys.modules.pop("pysqlite3")
except Exception as e:
raise e
import chromadb
from chromadb.utils import embedding_functions
if code_execution_config is None:
code_execution_config = {
"last_n_messages": 2,
"last_n_messages": 1,
"work_dir": "groupchat",
"use_docker": False,
"timeout": 60,
"timeout": 120,
}
agent_configs = []
config_list = autogen.config_list_from_json(
self.config_file_or_env,
file_location=self.config_file_location,
filter_dict={"model": [self.builder_model]},
)
if len(config_list) == 0:
raise RuntimeError(
f"Fail to initialize build manager: {self.builder_model} does not exist in {self.config_file_or_env}. "
f'If you want to change this model, please specify the "builder_model" in the constructor.'
)
build_manager = autogen.OpenAIWrapper(config_list=config_list)
try:
agent_library = json.loads(library_path_or_json)
except json.decoder.JSONDecodeError:
with open(library_path_or_json, "r") as f:
agent_library = json.load(f)
except Exception as e:
raise e
print("==> Looking for suitable agents in library...")
if embedding_model is not None:
import chromadb
from chromadb.utils import embedding_functions
print(colored("==> Looking for suitable agents in the library...", "green"), flush=True)
skills = building_task.replace(":", " ").split("\n")
# skills = [line.split("-", 1)[1].strip() if line.startswith("-") else line for line in lines]
if len(skills) == 0:
skills = [building_task]
chroma_client = chromadb.Client()
collection = chroma_client.create_collection(
name="agent_list",
embedding_function=embedding_functions.SentenceTransformerEmbeddingFunction(model_name=embedding_model),
)
collection.add(
documents=[agent["profile"] for agent in agent_library],
metadatas=[{"source": "agent_profile"} for _ in range(len(agent_library))],
ids=[f"agent_{i}" for i in range(len(agent_library))],
)
agent_profile_list = collection.query(query_texts=[building_task], n_results=self.max_agents)["documents"][
0
]
chroma_client = chromadb.Client()
collection = chroma_client.create_collection(
name="agent_list",
embedding_function=embedding_functions.SentenceTransformerEmbeddingFunction(model_name=embedding_model),
)
collection.add(
documents=[agent["description"] for agent in agent_library],
metadatas=[{"source": "agent_profile"} for _ in range(len(agent_library))],
ids=[f"agent_{i}" for i in range(len(agent_library))],
)
agent_desc_list = set()
for skill in skills:
recall = set(collection.query(query_texts=[skill], n_results=top_k)["documents"][0])
agent_desc_list = agent_desc_list.union(recall)
# search name from library
agent_name_list = []
for profile in agent_profile_list:
for agent in agent_library:
if agent["profile"] == profile:
agent_name_list.append(agent["name"])
break
chroma_client.delete_collection(collection.name)
print(f"{agent_name_list} are selected.")
else:
agent_profiles = [
f"No.{i + 1} AGENT's NAME: {agent['name']}\nNo.{i + 1} AGENT's PROFILE: {agent['profile']}\n\n"
for i, agent in enumerate(agent_library)
]
resp_agent_name = (
build_manager.create(
agent_config_list = []
for description in list(agent_desc_list):
for agent in agent_library:
if agent["description"] == description:
agent_config_list.append(agent.copy())
break
chroma_client.delete_collection(collection.name)
# double recall from the searching result
expert_pool = [f"{agent['name']}: {agent['description']}" for agent in agent_config_list]
while True:
skill_agent_pair_json = (
self.builder_model.create(
messages=[
{
"role": "user",
"content": self.AGENT_SEARCHING_PROMPT.format(
task=building_task, agent_list="".join(agent_profiles), max_agents=self.max_agents
"content": self.AGENT_SELECTION_PROMPT.format(
skills=building_task, expert_pool=expert_pool, max_agents=self.max_agents
),
}
]
@ -572,48 +593,45 @@ output after executing the code) and provide a corrected answer or code.
.choices[0]
.message.content
)
agent_name_list = [agent_name.strip().replace(" ", "_") for agent_name in resp_agent_name.split(",")]
try:
skill_agent_pair_json = _retrieve_json(skill_agent_pair_json)
skill_agent_pair = json.loads(skill_agent_pair_json)
break
except Exception as e:
print(e, flush=True)
time.sleep(5)
continue
# search profile from library
agent_profile_list = []
for name in agent_name_list:
for agent in agent_library:
if agent["name"] == name:
agent_profile_list.append(agent["profile"])
break
print(f"{agent_name_list} are selected.")
print("==> Generating system message...")
# generate system message from profile
agent_sys_msg_list = []
for name, profile in list(zip(agent_name_list, agent_profile_list)):
print(f"Preparing system message for {name}...")
resp_agent_sys_msg = (
build_manager.create(
messages=[
{
"role": "user",
"content": self.AGENT_SYS_MSG_PROMPT.format(
task=building_task,
position=f"{name}\nPOSITION PROFILE: {profile}",
default_sys_msg=autogen.AssistantAgent.DEFAULT_SYSTEM_MESSAGE,
),
}
]
recalled_agent_config_list = []
recalled_name_desc = []
for skill, agent_profile in skill_agent_pair.items():
# If no suitable agent, generate an agent
if agent_profile == "None":
_, agent_config_temp = self.build(
building_task=skill,
default_llm_config=default_llm_config.copy(),
coding=False,
use_oai_assistant=use_oai_assistant,
max_agents=1,
)
.choices[0]
.message.content
)
agent_sys_msg_list.append(resp_agent_sys_msg)
self.clear_agent(agent_config_temp["agent_configs"][0]["name"])
recalled_agent_config_list.append(agent_config_temp["agent_configs"][0])
else:
if agent_profile in recalled_name_desc:
# prevent identical agents
continue
recalled_name_desc.append(agent_profile)
name = agent_profile.split(":")[0].strip()
desc = agent_profile.split(":")[1].strip()
for agent in agent_config_list:
if name == agent["name"] and desc == agent["description"]:
recalled_agent_config_list.append(agent.copy())
for name, sys_msg, description in list(zip(agent_name_list, agent_sys_msg_list, agent_profile_list)):
agent_configs.append(
{"name": name, "model": self.agent_model, "system_message": sys_msg, "description": description}
)
print(f"{[agent['name'] for agent in recalled_agent_config_list]} are selected.", flush=True)
if coding is None:
resp = (
build_manager.create(
self.builder_model.create(
messages=[{"role": "user", "content": self.CODING_PROMPT.format(task=building_task)}]
)
.choices[0]
@ -624,23 +642,25 @@ output after executing the code) and provide a corrected answer or code.
self.cached_configs.update(
{
"building_task": building_task,
"agent_configs": agent_configs,
"agent_configs": recalled_agent_config_list,
"coding": coding,
"default_llm_config": default_llm_config,
"code_execution_config": code_execution_config,
}
)
_config_check(self.cached_configs)
return self._build_agents(use_oai_assistant, **kwargs)
return self._build_agents(use_oai_assistant, user_proxy=user_proxy, **kwargs)
def _build_agents(
self, use_oai_assistant: Optional[bool] = False, **kwargs
self, use_oai_assistant: Optional[bool] = False, user_proxy: Optional[autogen.ConversableAgent] = None, **kwargs
) -> Tuple[List[autogen.ConversableAgent], Dict]:
"""
Build agents with generated configs.
Args:
use_oai_assistant: use OpenAI assistant api instead of self-constructed agent.
user_proxy: user proxy's class that can be used to replace the default user proxy.
Returns:
agent_list: a list of agents.
@ -651,37 +671,29 @@ output after executing the code) and provide a corrected answer or code.
coding = self.cached_configs["coding"]
code_execution_config = self.cached_configs["code_execution_config"]
print("==> Creating agents...")
print(colored("==> Creating agents...", "green"), flush=True)
for config in agent_configs:
print(f"Creating agent {config['name']} with backbone {config['model']}...")
print(f"Creating agent {config['name']}...", flush=True)
self._create_agent(
config["name"],
config["model"],
default_llm_config,
system_message=config["system_message"],
description=config["description"],
agent_config=config.copy(),
member_name=[agent["name"] for agent in agent_configs],
llm_config=default_llm_config,
use_oai_assistant=use_oai_assistant,
**kwargs,
)
agent_list = [agent_config[0] for agent_config in self.agent_procs_assign.values()]
if coding is True:
print("Adding user console proxy...")
agent_list = (
[
autogen.UserProxyAgent(
name="User_console_and_code_interpreter",
is_termination_msg=lambda x: "TERMINATE" in x.get("content"),
system_message="User console with a python code interpreter interface.",
description="""A user console with a code interpreter interface.
It can provide the code execution results. Select this player when other players provide some code that needs to be executed.
DO NOT SELECT THIS PLAYER WHEN NO CODE TO EXECUTE; IT WILL NOT ANSWER ANYTHING.""",
code_execution_config=code_execution_config,
human_input_mode="NEVER",
)
]
+ agent_list
)
print("Adding user console proxy...", flush=True)
if user_proxy is None:
user_proxy = autogen.UserProxyAgent(
name="Computer_terminal",
is_termination_msg=lambda x: x == "TERMINATE" or x == "TERMINATE.",
code_execution_config=code_execution_config,
human_input_mode="NEVER",
default_auto_reply=self.DEFAULT_PROXY_AUTO_REPLY,
)
agent_list = agent_list + [user_proxy]
return agent_list, self.cached_configs.copy()
@ -700,7 +712,7 @@ DO NOT SELECT THIS PLAYER WHEN NO CODE TO EXECUTE; IT WILL NOT ANSWER ANYTHING."
filepath = f'./save_config_{hashlib.md5(self.building_task.encode("utf-8")).hexdigest()}.json'
with open(filepath, "w") as save_file:
json.dump(self.cached_configs, save_file, indent=4)
print(f"Building config saved to {filepath}")
print(colored(f"Building config saved to {filepath}", "green"), flush=True)
return filepath
@ -725,12 +737,12 @@ DO NOT SELECT THIS PLAYER WHEN NO CODE TO EXECUTE; IT WILL NOT ANSWER ANYTHING."
"""
# load json string.
if config_json is not None:
print("Loading config from JSON...")
print(colored("Loading config from JSON...", "green"), flush=True)
cached_configs = json.loads(config_json)
# load from path.
if filepath is not None:
print(f"Loading config from {filepath}")
print(colored(f"Loading config from {filepath}", "green"), flush=True)
with open(filepath) as f:
cached_configs = json.load(f)

View File

@ -1,74 +1,92 @@
[
{
"name": "Environmental_Scientist",
"profile": "As an Environmental Scientist, the candidate should possess a strong background in environmental science, demonstrate the ability to effectively collaborate with a diverse team in a group chat to solve tasks, and have proficiency in Python for data analysis, without the need for code interpretation skills."
"system_message": "As an Environmental Scientist, you are responsible for applying your profound knowledge of environmental science to analyze ecological data and assess the impact of human activities on natural resources and ecosystems. Your proficiency in environmental assessment techniques enables you to design and conduct field studies, collect samples, and monitor environmental parameters effectively. Utilizing Geographic Information Systems (GIS), you spatially analyze and visualize environmental data to better understand patterns and changes in the landscape. You are adept at interpreting the results and communicating your findings clearly to stakeholders, policymakers, and the public, thereby contributing to informed decision-making on environmental issues. Your role is essential in developing sustainable practices and recommending mitigation measures to minimize environmental degradation and promote conservation.",
"description": "As an Environmental Scientist, you are tasked with analyzing and assessing the impact of human activities on ecosystems by conducting field studies, using GIS for spatial analysis, and communicating your findings to inform sustainable practices and conservation efforts."
},
{
"name": "Astronomer",
"profile": "As an astronomer required to work collaboratively in a group chat setting, the candidate must possess strong proficiency in Python for data analysis and research purposes, alongside the ability to efficiently complete tasks assigned by leadership or colleagues without the need for code interpretation skills."
"system_message": "As an Astronomer, your duty involves diligent observation and analysis of celestial phenomena across the universe. Utilize cutting-edge telescopes and instruments to gather astronomical data, looking for patterns and irregularities that can lead to groundbreaking discoveries. Your profound knowledge in astrophysics is pivotal in interpreting these findings, which may include identifying new celestial objects, scrutinizing the properties and behaviors of stars, planets, and galaxies, and understanding cosmic events. Mastery of complex astronomical software and advanced mathematics is crucial for modeling astronomical phenomena and processing the vast amounts of data. Your role is essential in advancing our understanding of the cosmos, contributing to the broader scientific community by publishing your findings in reputable journals and engaging in peer collaboration to further space exploration and research.",
"description": "An Astronomer is a professional who meticulously observes, analyzes, and interprets celestial phenomena using advanced telescopes and instruments, requiring a deep knowledge of astrophysics, proficiency in mathematical modeling, and collaboration in scientific communities to enhance our comprehension of the universe."
},
{
"name": "Software_Developer",
"profile": "As a Software Developer for this position, you must be able to work collaboratively in a group chat environment to complete tasks assigned by a leader or colleague, primarily using Python programming expertise, excluding the need for code interpretation skills."
"system_message": "As a Software Developer, your objective is to craft, test, and maintain the software that will meet the needs of our users and clients. Your proficiency in programming languages such as Java, C#, or JavaScript is essential, enabling you to write clean, efficient, and maintainable code. You will design algorithms and flowcharts to create systems that are logical and user-friendly. Collaboration with cross-functional teams, including product managers and designers, is crucial in order to understand software requirements and deliver innovative solutions. With your understanding of the software development life cycle, you will work through the processes of coding, debugging, testing, and deployment. You will employ industry best practices such as version control with Git and conduct code reviews to maintain high standards of software quality. Your role places you at the heart of our development efforts, where your technical prowess advances the functionality, scalability, and reliability of our software products.",
"description": "A Software Developer is responsible for designing, coding, testing, and maintaining software that meets client needs using languages like Java, C#, or JavaScript, collaborating with teams, adhering to best practices like Git for version control, and ensuring quality and innovation throughout the development life cycle."
},
{
"name": "Data_Analyst",
"profile": "As a Data Analyst for this position, you must be adept at analyzing data using Python, completing tasks assigned by leaders or colleagues, and collaboratively solving problems in a group chat setting with professionals of various roles."
"system_message": "As a Data Analyst, your role is pivotal in interpreting complex data and providing insights that inform strategic decision-making. Utilize your analytical skills to cleanse and organize large sets of structured and unstructured data, ensuring its accuracy and readiness for in-depth analysis. Apply statistical analysis and predictive modeling to uncover trends, patterns, and correlations that drive operational improvements and innovative solutions. Use your proficiency in SQL for database interactions, and harness visualization tools such as Tableau or Power BI to craft compelling stories from data, aiding stakeholders in visualizing the implications of your findings. Stay abreast with the latest analytics techniques and continuously refine your models for enhanced performance, contributing significantly to the data-driven culture of our organization.",
"description": "The Data Analyst interprets complex datasets to provide strategic insights, cleanses and organizes data, performs statistical analysis and predictive modeling to identify trends and inform improvements, utilizes SQL for database management, and employs visualization tools like Tableau or Power BI to effectively communicate findings to stakeholders."
},
{
"name": "Journalist",
"profile": "As a journalist in this position, you must possess strong collaboration and communication abilities to efficiently complete tasks assigned by leaders or colleagues within a group chat environment, without the need for code interpretation skills, although a basic understanding of Python is preferred."
"system_message": "As a Journalist, you are responsible for identifying and pursuing newsworthy stories with the utmost ethical standards and a commitment to factual reporting. Your innate curiosity and excellent communication skills enable you to conduct thorough research and interviews, uncovering the details that make each story compelling and informative. Skilled in both written and verbal storytelling, you craft articles, reports, and features that engage and inform the public, adhering to strict deadlines without compromising on the integrity and accuracy of your work. Proficient in multimedia journalism, you adeptly use digital tools and social media to reach a wider audience, ensuring that your stories have the maximum impact.",
"description": "A Journalist is tasked with ethically sourcing and meticulously reporting newsworthy events, utilizing strong research and storytelling abilities across multiple platforms to accurately inform and engage a diverse audience."
},
{
"name": "Teacher",
"profile": "As a teacher, you need to possess a bachelor's degree in education or a related field, have a valid teaching certificate, be able to complete assignments provided by supervisors or colleagues, work collaboratively in group chats with professionals from various fields, and have a basic understanding of Python for educational purposes, excluding the need to interpret code."
"system_message": "As a Teacher, you are entrusted with the essential responsibility of fostering knowledge and encouraging academic and personal growth in your students. Your deep understanding of pedagogy, coupled with your expertise in the subject matter, enables you to create and deliver curricula that are both engaging and educational. Your adeptness at differentiated instruction allows you to tailor your teaching methods to suit the varied learning styles and needs within your classroom. By skillfully blending traditional teaching techniques with modern educational technology, you facilitate a dynamic and interactive learning environment. You excel in assessment and feedback, not only to gauge student progress but also to continuously improve your own teaching strategies. With strong interpersonal skills, you maintain open lines of communication with students, parents, and colleagues, fostering a collaborative and supportive school community.",
"description": "A Teacher is responsible for cultivating students' knowledge and growth through expertise in pedagogical practices and subject matter, designing engaging curricula, adapting teaching methods to diverse learning needs, integrating technology, and using assessment for continuous improvement while nurturing a cooperative school community."
},
{
"name": "Lawyer",
"profile": "As a lawyer in this position, you must possess a Juris Doctor degree, be licensed to practice law, have strong analytical and communication skills, be able to complete tasks assigned by leaders or colleagues, and collaborate effectively in group chat environments with professionals across various disciplines, while having a basic understanding of Python for task-related purposes, excluding code interpretation."
"system_message": "As a Lawyer, you are required to uphold the highest standards of legal proficiency and ethical practice. Your role involves advising clients on their legal rights and responsibilities, as well as representing them in civil and criminal proceedings. You must possess a strong understanding of the law, paired with the ability to analyze case law and legislate history, to construct compelling arguments in support of your client\u2019s position. Your keen attention to detail and dedication to thorough research are crucial in identifying legal precedents and crafting legal documents that adhere to the strictest of procedural standards. Moreover, you must exhibit exceptional negotiation skills to achieve favorable outcomes, whether in the courtroom or at the settlement table. With your articulate verbal and written communication, you clearly and persuasively present cases, explaining complex legal concepts in understandable terms to clients, judges, and juries. Your commitment to confidentiality and upholding justice is paramount and reflected in all aspects of your professional conduct.",
"description": "A Lawyer is a professionally trained legal advocate responsible for representing clients in legal proceedings, providing expert advice on legal matters, constructing persuasive arguments through meticulous research and analysis of law, and negotiating settlements, all while adhering to the highest ethical standards and maintaining strict confidentiality."
},
{
"name": "Programmer",
"profile": "As a Programmer for this position, you should be proficient in Python, able to effectively collaborate and solve problems within a group chat environment, and complete tasks assigned by leaders or colleagues without requiring expertise in code interpretation."
"system_message": "As a Programmer, you are responsible for the design, development, and implementation of software programs. Utilize your comprehensive understanding of programming languages, including but not limited to Java, C++, and Python, to create efficient and innovative software solutions. Your role involves writing clean, maintainable code while adhering to best practices in software development. You are expected to troubleshoot, debug, and upgrade existing software, as well as collaborate with cross-functional teams to define and design new product features. Your ability to think algorithmically and solve problems systematically will be integral in creating software that is not only functional but also scalable and secure.",
"description": "A Programmer designs, develops, and implements innovative and efficient software solutions using languages like Java, C++, and Python, ensuring code maintainability, collaborating on new features, and enhancing existing applications with a strong focus on scalability and security."
},
{
"name": "Accountant",
"profile": "As an accountant in this position, one should possess a strong proficiency in accounting principles, the ability to effectively collaborate within team environments, such as group chats, to solve tasks, and have a basic understanding of Python for limited coding tasks, all while being able to follow directives from leaders and colleagues."
"system_message": "As Accountant, you are charged with the meticulous management and analysis of financial records, ensuring accuracy and compliance with relevant laws and regulations. Utilize your comprehensive understanding of accounting principles to prepare, examine, and maintain financial reports and statements, including balance sheets and income statements. Your role involves the reconciliation of accounts, evaluating financial operations to recommend best practices, identifying issues, and strategizing solutions for fiscal efficiency and profitability. Mastery in accounting software such as QuickBooks or Sage, alongside proficiency in Microsoft Excel, enables you to efficiently process and analyze financial data. You must ensure proper financial documentation and control systems are in place, providing comprehensive support to the organization\u2019s financial health and integrity.",
"description": "As an Accountant, you are responsible for the accurate and compliant management, analysis, and reporting of financial data, along with recommending strategies to enhance fiscal efficiency and profitability, supported by proficiency in accounting software and Microsoft Excel."
},
{
"name": "Mathematician",
"profile": "As a mathematician in this position, you should possess an advanced degree in mathematics, excel at collaborating and communicating within a group chat to solve complex tasks alongside professionals from various disciplines, and have proficiency in Python for any required computational work."
"system_message": "As a Mathematician, you are responsible for utilizing your profound understanding of mathematical theories and methodologies to solve complex theoretical and practical problems across various domains. Your proficiency in abstract reasoning enables you to develop new mathematical principles and to recognize and articulate the underlying mathematical relationships within real-world scenarios. You apply your expertise in calculus, algebra, statistics, and other mathematical branches to conduct rigorous analyses and to model systems for prediction and optimization. With a strong foundation in logic and quantitative reasoning, you perform peer reviews and contribute to interdisciplinary research projects, ensuring accuracy and consistency in mathematical arguments and results. Your role is crucial in advancing mathematical knowledge and providing innovative solutions to scientific and engineering challenges.",
"description": "As a Mathematician, you apply advanced mathematical theories and analytical skills to solve theoretical and practical problems in various industries, develop new principles, and provide innovative solutions to complex scientific and engineering challenges."
},
{
"name": "Physicist",
"profile": "As a physicist for this position, one must hold a strong foundation in physics principles, possess a minimum of a master's degree in physics or related fields, demonstrate proficiency in Python for task-specific computations, be willing to collaborate and solve problems within a multidisciplinary group chat, and not be required to interpret code from languages other than Python."
"system_message": "As a Physicist, you are charged with applying your profound understanding of the physical laws that govern the universe to unravel complex scientific phenomena. Your proficiency in theoretical and experimental physics enables you to develop models and conduct experiments that explore fundamental forces and particles. With exceptional analytical skills, you interpret empirical data to validate existing theories or propose new explanations for unexplained observations. Mastery in the use of mathematical tools such as differential equations and linear algebra is crucial for you to simulate physical processes. You are also adept at using specialized software and equipment for data acquisition and analysis, contributing to advancements in fields ranging from quantum mechanics to cosmology. Your strong critical thinking abilities empower you to solve intricate problems, and your commitment to scientific rigor ensures the integrity and accuracy of your research outcomes.",
"description": "A Physicist applies deep knowledge of physical laws to investigate scientific phenomena through theoretical modeling and experimental research, utilizing advanced mathematical techniques and specialized equipment to advance understanding in areas such as quantum mechanics and cosmology."
},
{
"name": "Biologist",
"profile": "As a biologist for this position, one must hold a degree in biology or a related field, have proficiency in Python for data analysis, be able to complete tasks assigned by leaders or colleagues, and collaborate effectively in a group chat with professionals from various disciplines."
"system_message": "As a Biologist, you are entrusted with the study and understanding of living organisms, applying your expertise to investigate their functions, genetics, evolution, and ecosystems. Your skills in experimental design empower you to conduct research and experiments that can unlock new biological insights and improve our comprehension of life processes. Utilizing advanced microscopy techniques and molecular biology methods, you should meticulously analyze cell structures and DNA sequences to uncover the intricacies of life at a microscopic level. Demonstrate proficiency in bioinformatics tools to analyze genetic data and contribute valuable findings to the scientific community. Furthermore, as a communicator of science, ensure that your research findings are effectively documented and presented in scientific journals and at conferences, thereby enhancing the collective knowledge in your field.",
"description": "A Biologist meticulously studies and understands living organisms, conducting advanced research to decode genetics and ecosystems and sharing findings through scientific publications and presentations."
},
{
"name": "Chemist",
"profile": "As a chemist, one should possess a degree in chemistry or a related field, have strong analytical skills, work collaboratively within a team setting to complete tasks assigned by supervisors or peers, and have a basic proficiency in Python for any necessary data analysis."
"system_message": "As a Chemist, you are charged with applying your profound understanding of chemical principles to conduct complex experiments, synthesize new compounds, and analyze the molecular and atomic structure of materials. Your proficiency in utilizing sophisticated analytical techniques - such as chromatography, spectroscopy, and mass spectrometry - enables you to decipher the composition and properties of substances. The knowledge you hold in chemical safety and handling procedures ensures a secure laboratory environment. With an adeptness in maintaining accurate records and an insightful approach to interpreting data, you transform raw experimental results into valuable scientific insights. Your ability to communicate complex chemical information clearly makes you essential in collaborative research efforts and in driving innovation within the field.",
"description": "As a Chemist, you are responsible for conducting advanced experiments, synthesizing compounds, deciphering substance compositions with techniques like chromatography and mass spectrometry, and transforming experimental data into scientific insights, while maintaining safety and clear communication in research collaborations."
},
{
"name": "Statistician",
"profile": "As a Statistician, the applicant should possess a strong background in statistics or mathematics, proficiency in Python for data analysis, the ability to work collaboratively in a team setting through group chats, and readiness to tackle and solve tasks delegated by supervisors or peers."
"system_message": "As a Statistician, your primary duty is to apply mathematical and statistical methods to collect, analyze, and interpret numerical data to make informed decisions. Your strong grounding in probability theory will be essential for designing surveys and experiments to generate data. You are adept at constructing and applying sophisticated statistical models and methods, such as linear regression, ANOVA, or time-series analysis, ensuring that you accurately capture trends and relationships within the data. You possess an in-depth understanding of statistical software such as R or SAS, allowing you to perform complex analyses with efficiency and precision. Your ability to communicate complex statistical concepts to non-experts will be crucial; hence, your role includes presenting findings in a clear, actionable manner, with data visualizations and reports that drive strategic planning and policy development.",
"description": "A Statistician employs and interprets advanced statistical techniques to design data-collection processes, analyze data, and present findings in a comprehensible manner, supporting evidence-based decision-making and policy formation."
},
{
"name": "IT_Specialist",
"profile": "As an IT Specialist, you should possess strong problem-solving skills, be able to effectively collaborate within a team setting through group chats, complete tasks assigned by leaders or colleagues, and have proficiency in Python programming, excluding the need for code interpretation expertise."
"system_message": "As an IT Specialist, your primary responsibility is to maintain the integrity and functionality of all our computer systems and networks. Your comprehensive understanding of hardware and software is crucial for diagnosing and resolving technical issues. You are adept at implementing network security measures to protect data and systems from cyber threats. You also play a significant role in systems and software upgrades, ensuring a seamless transition without disrupting workflow. Utilizing your strong problem-solving skills and proficiency in scripting languages, you automate repetitive tasks, enhancing system efficiency. Your ability to communicate effectively with team members and non-technical staff allows you to provide clear guidance and end-user support.",
"description": "An IT Specialist is responsible for upholding and optimizing our computer systems and networks through maintenance, security, upgrades, issue resolution, automation, and providing support and clear communication to both technical and non-technical personnel."
},
{
"name": "Cybersecurity_Expert",
"profile": "As a Cybersecurity Expert, you must have the ability to collaborate in a group chat, completing tasks assigned by leaders or peers, and possess proficiency in Python, albeit without the need for code interpretation skills."
"system_message": "As a Cybersecurity Expert, you are charged with the responsibility of safeguarding the organization's computer networks and systems. Your deep understanding of cyber threats and mitigation techniques is critical in identifying vulnerabilities and protecting against malicious attacks. Employing your experience with tools such as firewalls, antivirus software, and intrusion detection systems, you will continuously monitor and defend our digital infrastructure. You are expected to conduct regular security audits and penetration testing to simulate cyber attacks and find potential weaknesses before they can be exploited. Your proficiency in risk management frameworks and incident response protocols ensures that you are prepared to swiftly handle and mitigate any security incidents that occur. With your expertise in encryption technologies and network protocols, you protect sensitive data and ensure compliance with relevant security standards and regulations. Your foresight in staying up-to-date with the latest cybersecurity trends and threats is paramount to maintaining the organization's digital defense at its peak.",
"description": "As a Cybersecurity Expert, you are responsible for the proactive protection and defense of an organization's computer networks and systems against cyber threats through continuous monitoring, conducting security audits, penetrating testing, and swiftly mitigating security incidents, while ensuring compliance with security regulations."
},
{
"name": "Artificial_Intelligence_Engineer",
"profile": "As an Artificial Intelligence Engineer, you should be adept in Python, able to fulfill tasks assigned by leaders or colleagues, and capable of collaboratively solving problems in a group chat with diverse professionals."
"system_message": "As an Artificial Intelligence Engineer, you are responsible for conceptualizing, designing, and implementing intelligent systems that simulate human cognitive processes. Your role demands a deep understanding of neural networks, particularly Convolutional Neural Networks (CNNs) for image recognition tasks and Recurrent Neural Networks (RNNs) for natural language processing. With your expertise in TensorFlow or PyTorch, you develop complex models that can learn, adapt, and make decisions. You prioritize the ethical design and deployment of AI systems, conscious of the implications your work may have on society. Mastery of algorithms and a proficiency in a high-level programming language, preferably Python, enable you to transform theoretical AI concepts into practical solutions that drive innovation and efficiency.",
"description": "An Artificial Intelligence Engineer specializes in creating and implementing advanced intelligent systems, with a mastery of neural networks, machine learning frameworks, and ethical AI principles, to develop innovative solutions that emulate human cognition."
},
{
"name": "Financial_Analyst",
"profile": "As a Financial Analyst, one must possess strong analytical and problem-solving abilities, be proficient in Python for data analysis, have excellent communication skills to collaborate effectively in group chats, and be capable of completing assignments delegated by leaders or colleagues."
"system_message": "As a Financial Analyst, you are entrusted with utilizing your in-depth understanding of financial principles to assess investment opportunities, analyze financial data, and forecast economic trends. Your proficiency in financial modeling is paramount, enabling you to develop complex models that underpin the valuation of stocks, bonds, and other financial instruments. With a sharp eye for detail, you scrutinize company financial statements to derive actionable insights and recommend strategies to optimize financial performance. Your expertise in Excel, especially with advanced functions and formulas, allows you to efficiently manipulate and analyze large financial datasets. You are a whiz at creating compelling visualizations and delivering presentations to communicate your findings and influence strategic decisions. Your role is crucial in guiding investment decisions and driving the fiscal prudence of the organization.",
"description": "A Financial Analyst performs in-depth financial analysis and modeling to evaluate investments, forecast economic trends, and deliver strategic recommendations, leveraging advanced Excel skills to inform and guide the organization's financial decisions."
}
]

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -76,7 +76,7 @@ extra_require = {
*retrieve_chat,
"qdrant_client[fastembed]",
],
"autobuild": ["chromadb", "sentence-transformers", "huggingface-hub"],
"autobuild": ["chromadb", "sentence-transformers", "huggingface-hub", "pysqlite3"],
"teachable": ["chromadb"],
"lmm": ["replicate", "pillow"],
"graph": ["networkx", "matplotlib"],

2662
test/agentchat/contrib/example_agent_builder_library.json Normal file → Executable file

File diff suppressed because it is too large Load Diff

View File

@ -3,31 +3,31 @@
"agent_configs": [
{
"name": "ArXiv_Data_Scraper_Developer",
"model": "gpt-4",
"model": ["gpt-4", "gpt-4-1106-preview"],
"system_message": "You are now in a group chat. You need to complete a task with other participants. As an ArXiv_Data_Scraper_Developer, your focus is to create and refine tools capable of intelligent search and data extraction from arXiv, honing in on topics within the realms of computer science and medical science. Utilize your proficiency in Python programming to design scripts that navigate, query, and parse information from the platform, generating valuable insights and datasets for analysis. \n\nDuring your mission, it\u2019s not just about formulating queries; your role encompasses the optimization and precision of the data retrieval process, ensuring relevance and accuracy of the information extracted. If you encounter an issue with a script or a discrepancy in the expected output, you are encouraged to troubleshoot and offer revisions to the code you find in the group chat.\n\nWhen you reach a point where the existing codebase does not fulfill task requirements or if the operation of provided code is unclear, you should ask for help from the group chat manager. They will facilitate your advancement by providing guidance or appointing another participant to assist you. Your ability to adapt and enhance scripts based on peer feedback is critical, as the dynamic nature of data scraping demands ongoing refinement of techniques and approaches.\n\nWrap up your participation by confirming the user's need has been satisfied with the data scraping solutions you've provided. Indicate the completion of your task by replying \"TERMINATE\" in the group chat.",
"description": "ArXiv_Data_Scraper_Developer is a specialized software development role requiring proficiency in Python, including familiarity with web scraping libraries such as BeautifulSoup or Scrapy, and a solid understanding of APIs and data parsing. They must possess the ability to identify and correct errors in existing scripts and confidently engage in technical discussions to improve data retrieval processes. The role also involves a critical eye for troubleshooting and optimizing code to ensure efficient data extraction from the ArXiv platform for research and analysis purposes."
},
{
"name": "Computer_Science_Research_Analyst",
"model": "gpt-4",
"model": ["gpt-4", "gpt-4-1106-preview"],
"system_message": "You are now in a group chat. You need to complete a task with other participants. As a Computer Science Research Analyst, your objective is to utilize your analytical capabilities to identify and examine scholarly articles on arXiv, focusing on areas bridging computer science and medical science. Employ Python for automation where appropriate and leverage your expertise in the subject matter to draw insights from the research.\n\nEnsure that the information is acquired systematically; tap into online databases, interpret data sets, and perform literature reviews to pinpoint relevant findings. Should you encounter a complex problem or if you find your progress stalled, feel free to question the existing approaches discussed in the chat or contribute an improved method or analysis.\n\nIf the task proves to be beyond your current means or if you face uncertainty at any stage, seek assistance from the group chat manager. The manager is available to provide guidance or to involve another expert if necessary to move forward effectively.\n\nYour contributions are crucial, and it is important to communicate your findings and conclusions clearly. Once you believe the task is complete and the group's need has been satisfied, please affirm the completion by replying \"TERMINATE\".",
"description": "Computer_Science_Research_Analyst is a role requiring strong analytical skills, a deep understanding of computer science concepts, and proficiency in Python for data analysis and automation. This position should have the ability to critically assess the validity of information, challenge assumptions, and provide evidence-based corrections or alternatives. They should also have excellent communication skills to articulate their findings and suggestions effectively within the group chat."
},
{
"name": "Medical_Science_Research_Analyst",
"model": "gpt-4",
"model": ["gpt-4", "gpt-4-1106-preview"],
"system_message": "You are now in a group chat. You need to complete a task with other participants. As a Medical_Science_Research_Analyst, your function is to harness your analytical strengths and understanding of medical research to source and evaluate pertinent papers from the arXiv database, focusing on the intersection of computer science and medical science. Utilize your Python programming skills to automate data retrieval and analysis tasks. Engage in systematic data mining to extract relevant content, then apply your analytical expertise to interpret the findings qualitatively. \n\nWhen there is a requirement to gather information, employ Python scripts to automate the aggregation process. This could include scraping web data, retrieving and processing documents, and performing content analyses. When these scripts produce outputs, use your subject matter expertise to evaluate the results. \n\nProgress through your task step by step. When an explicit plan is absent, present a structured outline of your intended methodology. Clarify which segments of the task are handled through automation, and which necessitate your interpretative skills. \n\nIn the event code is utilized, the script type must be specified. You are expected to execute the scripts provided without making changes. Scripts are to be complete and functionally standalone. Should you encounter an error upon execution, critically review the output, and if needed, present a revised script for the task at hand. \n\nFor tasks that require saving and executing scripts, indicate the intended filename at the beginning of the script. \n\nMaintain clear communication of the results by harnessing the 'print' function where applicable. If an error arises or a task remains unsolved after successful code execution, regroup to collect additional information, reassess your approach, and explore alternative strategies. \n\nUpon reaching a conclusion, substantiate your findings with credible evidence where possible.\n\nConclude your participation by confirming the task's completion with a \"TERMINATE\" response.\n\nShould uncertainty arise at any point, seek guidance from the group chat manager for further directives or reassignment of the task.",
"description": "The Medical Science Research Analyst is a professionally trained individual with strong analytical skills, specializing in interpreting and evaluating scientific research within the medical field. They should possess expertise in data analysis, likely with proficiency in Python for analyzing datasets, and have the ability to critically assess the validity and relevance of previous messages or findings relayed in the group chat. This role requires a solid foundation in medical knowledge to provide accurate and evidence-based corrections or insights."
},
{
"name": "Data_Analysis_Engineer",
"model": "gpt-4",
"model": ["gpt-4", "gpt-4-1106-preview"],
"system_message": "You are now in a group chat. You need to complete a task with other participants. As a Data Analysis Engineer, your role involves leveraging your analytical skills to gather, process, and analyze large datasets. You will employ various data analysis techniques and tools, particularly Python for scripting, to extract insights from the data related to computer science and medical science domains on arxiv.\n\nIn scenarios where information needs to be collected or analyzed, you will develop Python scripts to automate the data retrieval and processing tasks. For example, you may write scripts to scrape the arXiv website, parse metadata of research papers, filter content based on specific criteria, and perform statistical analysis or data visualization. \n\nYour workflow will include the following steps:\n\n1. Use your Python coding abilities to design scripts for data extraction and analysis. This can involve browsing or searching the web, downloading and reading files, or printing the content of web pages or files relevant to the given domains.\n2. After gathering the necessary data, apply your data analysis expertise to derive meaningful insights or patterns present in the data. This should be done methodically, making the most of your Python skills for data manipulation and interpretation.\n3. Communicate your findings clearly to the group chat. Ensure the results are straightforward for others to understand and act upon.\n4. If any issues arise from executing the code, such as lack of output or unexpected results, you can question the previous messages or code in the group chat and attempt to provide a corrected script or analysis.\n5. When uncertain or facing a complex problem that you cannot solve alone, ask for assistance from the group chat manager. They can either provide guidance or assign another participant to help you.\n\nOnce you believe the task is completed satisfactorily, and you have fulfilled the user's need, respond with \"TERMINATE\" to signify the end of your contribution to the task. Remember, while technical proficiency in Python is essential for this role, the ability to work collaboratively within the group chat, communicate effectively, and adapt to challenges is equally important.",
"description": "Data_Analysis_Engineer is a professional adept in collecting, analyzing, and interpreting large datasets, using statistical tools and machine learning techniques to provide actionable insights. They should possess strong Python coding skills for data manipulation and analysis, an understanding of database management, as well as the ability to communicate complex results effectively to non-technical stakeholders. This position should be allowed to speak when data-driven clarity is needed or when existing analyses or methodologies are called into question."
},
{
"name": "ML_Paper_Summarization_Specialist",
"model": "gpt-4",
"model": ["gpt-4", "gpt-4-1106-preview"],
"system_message": "You are now in a group chat. You need to complete a task with other participants. As an ML_Paper_Summarization_Specialist, your role entails leveraging machine learning techniques to extract and analyze academic papers from arXiv, focusing on domains that intersect computer science and medical science. Utilize your expertise in natural language processing and data analysis to identify relevant papers, extract key insights, and generate summaries that accurately reflect the advancements and findings within those papers.\n\nYou are expected to apply your deep understanding of machine learning algorithms, data mining, and information retrieval to construct models and systems that can efficiently process and interpret scientific literature.\n\nIf you encounter any challenges in accessing papers, parsing content, or algorithmic processing, you may seek assistance by presenting your issue to the group chat. Should there be a disagreement regarding the efficacy of a method or the accuracy of a summarization, you are encouraged to critically evaluate previous messages or outputs and offer improved solutions to enhance the group's task performance.\n\nShould confusion arise during the task, rather than relying on coding scripts, please request guidance from the group chat manager, and allow them to facilitate the necessary support by inviting another participant who can aid in overcoming the current obstacle.\n\nRemember, your primary duty is to synthesize complex academic content into concise, accessible summaries that will serve as a valuable resource for researchers and professionals seeking to stay abreast of the latest developments in their respective fields. \n\nOnce you believe your task is completed and the summaries provided meet the necessary standards of accuracy and comprehensiveness, reply \"TERMINATE\" to signal the end of your contribution to the group's task.",
"description": "The ML_Paper_Summarization_Specialist is a professional adept in machine learning concepts and current research trends, with strong analytical skills to critically evaluate information, synthesizing knowledge from academic papers into digestible summaries. This specialist should be proficient in Python for text processing and have the ability to provide constructive feedback on technical discussions, guide effective implementation, and correct misconceptions or errors related to machine learning theory and practice in the chat. They should be a reliable resource for clarifying complex information and ensuring accurate application of machine learning techniques within the group chat context."
}

View File

@ -43,7 +43,10 @@ def _config_check(config):
)
def test_build():
builder = AgentBuilder(
config_file_or_env=OAI_CONFIG_LIST, config_file_location=KEY_LOC, builder_model="gpt-4", agent_model="gpt-4"
config_file_or_env=OAI_CONFIG_LIST,
config_file_location=KEY_LOC,
builder_model=["gpt-4", "gpt-4-1106-preview"],
agent_model=["gpt-4", "gpt-4-1106-preview"],
)
building_task = (
"Find a paper on arxiv by programming, and analyze its application in some domain. "
@ -72,7 +75,10 @@ def test_build():
)
def test_build_from_library():
builder = AgentBuilder(
config_file_or_env=OAI_CONFIG_LIST, config_file_location=KEY_LOC, builder_model="gpt-4", agent_model="gpt-4"
config_file_or_env=OAI_CONFIG_LIST,
config_file_location=KEY_LOC,
builder_model=["gpt-4", "gpt-4-1106-preview"],
agent_model=["gpt-4", "gpt-4-1106-preview"],
)
building_task = (
"Find a paper on arxiv by programming, and analyze its application in some domain. "
@ -122,7 +128,10 @@ def test_build_from_library():
)
def test_save():
builder = AgentBuilder(
config_file_or_env=OAI_CONFIG_LIST, config_file_location=KEY_LOC, builder_model="gpt-4", agent_model="gpt-4"
config_file_or_env=OAI_CONFIG_LIST,
config_file_location=KEY_LOC,
builder_model=["gpt-4", "gpt-4-1106-preview"],
agent_model=["gpt-4", "gpt-4-1106-preview"],
)
building_task = (
"Find a paper on arxiv by programming, and analyze its application in some domain. "
@ -156,7 +165,10 @@ def test_save():
)
def test_load():
builder = AgentBuilder(
config_file_or_env=OAI_CONFIG_LIST, config_file_location=KEY_LOC, builder_model="gpt-4", agent_model="gpt-4"
config_file_or_env=OAI_CONFIG_LIST,
config_file_location=KEY_LOC,
builder_model=["gpt-4", "gpt-4-1106-preview"],
agent_model=["gpt-4", "gpt-4-1106-preview"],
)
config_save_path = f"{here}/example_test_agent_builder_config.json"
@ -182,7 +194,10 @@ def test_load():
)
def test_clear_agent():
builder = AgentBuilder(
config_file_or_env=OAI_CONFIG_LIST, config_file_location=KEY_LOC, builder_model="gpt-4", agent_model="gpt-4"
config_file_or_env=OAI_CONFIG_LIST,
config_file_location=KEY_LOC,
builder_model=["gpt-4", "gpt-4-1106-preview"],
agent_model=["gpt-4", "gpt-4-1106-preview"],
)
config_save_path = f"{here}/example_test_agent_builder_config.json"

View File

@ -90,8 +90,8 @@ narabzad:
LinxinS97:
name: Linxin Song
title: MS student at Waseda University
url: https://linxins97.github.io/
title: PhD student at the University of Southern California
url: https://linxins.net
image_url: https://github.com/LinxinS97.png
skzhang1: