Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tonic's Branch #1

Open
wants to merge 49 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
642de19
added intention mapper updated the readme
Feb 17, 2024
1b4a70a
Merge branch 'devbranch' into 'main'
Feb 18, 2024
51e3091
refactoring search.py
Feb 18, 2024
e8b2775
improve readme with community contributions
Feb 18, 2024
52c5c5b
add agentics
Feb 18, 2024
4a74d97
added main.py
Feb 18, 2024
920dbb9
testing
Feb 18, 2024
eacb135
added a local document loader
Feb 18, 2024
d145808
added config, vector store
Feb 18, 2024
0303af7
added references
Feb 18, 2024
449c7bb
added references
Feb 18, 2024
9f6a1db
removed blank example files
Feb 19, 2024
1963a59
removed empty documentation folder
Feb 19, 2024
f136427
refactor change / improve websearch + add web retrieval agent
Feb 19, 2024
b2484ed
refactor change / improve websearch + add web vector store agent
Feb 19, 2024
d5b19ed
refactor change / improve websearch + add web retrieval agent example
Feb 19, 2024
d461597
fix file path in search.py
Feb 19, 2024
26c16d7
additional small changes
Feb 19, 2024
4147b13
resolving conflicts
Feb 19, 2024
177001a
resolving conflicts
Feb 19, 2024
b53cbde
resolving conflicts
Feb 19, 2024
271a38d
resolving conflicts
Feb 19, 2024
812e905
resolving conflicts
Feb 19, 2024
80db3fc
adding plugins and prompts folders
Feb 19, 2024
c7fa10d
adding plugins and prompts folders
Feb 19, 2024
3dbd65f
loading prompts and assistants based on configs and prompt
Feb 20, 2024
e5e7b52
Merge branch 'devbranch' into 'tonic'
Feb 20, 2024
95afa91
adding assistants
Feb 20, 2024
64856d4
Merge branch 'tonic' of tonic-ai-git.eastus2.cloudapp.azure.com:aibur…
Feb 20, 2024
05e7106
created the agent builder
Feb 20, 2024
9902f1d
adding the system prompt builder
Feb 20, 2024
96f9d53
add assistant message extraction for assistant run
Feb 20, 2024
4f84a66
added the systemprompt builder
Feb 20, 2024
966cee9
added assistant creator
Feb 20, 2024
fc8d4a5
added response schema to agent creator
Feb 20, 2024
ded8a3c
added the env loading to systempromptmaker
Feb 20, 2024
c09fada
added the agent builder
Feb 20, 2024
4c44133
Merge branch 'devbranch' into 'tonic'
Feb 20, 2024
c330dc8
added ./src/agentics/tools.py
Feb 20, 2024
e556ec2
Merge branch 'tonic' of tonic-ai-git.eastus2.cloudapp.azure.com:aibur…
Feb 20, 2024
73731a0
adding loaders
Feb 21, 2024
4b84a76
the intention mapper now loads the openai key from config and returns…
Feb 21, 2024
3c625a2
startinng to add main.py logics
Feb 21, 2024
42e6725
Merge branch 'devbranch' into 'tonic'
Feb 21, 2024
40a30d1
adding teams creation logic wip
Feb 21, 2024
0b041ae
refactored main.py based on team logic
Feb 21, 2024
bffcfbe
Merge branch 'devbranch' into 'tonic'
Feb 21, 2024
71242d6
trying to close issues like this
Feb 21, 2024
38c33c6
Merge branch '2-compose-teams-on-the-fly-using-the-intention-mapper-f…
Feb 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 20 additions & 38 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,51 @@
# ./main.py
import os
import sys
from dotenv import load_dotenv
from autogen import GroupChat, GroupChatManager
from autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent
from src.mappers.team import teamMappers
from src.agentics.agentcreate import agentCreator
import autogen
from autogen.util import load_config, get_openai_keys
from autogen.util import load_config, get_openai_keys, config_list_from_json
from src.mappers.team import teamMappers
from src.agentics.teams import TeamManager

# Append the config directory to sys.path for importing config functionalities
sys.path.append(os.path.join(os.path.dirname(__file__), 'src', 'config'))

# Load environment variables
# Load environment variables for system messages and assistants
dotenv_system_messages_path = os.path.join(os.path.dirname(__file__), 'src', 'promptburo', 'system_messages.env')
dotenv_assistants_env_path = os.path.join(os.path.dirname(__file__), 'src', 'config', 'assistants.env')
load_dotenv(dotenv_system_messages_path)
load_dotenv(dotenv_assistants_env_path)

# Load OpenAI API key from config
config_path = os.path.join(os.path.dirname(__file__), '..', 'config', 'OAI_CONFIG.json')
config = load_config(config_path)
openai_keys = get_openai_keys(config)
if openai_keys:
openai_key = openai_keys[0]
print(f"Using OpenAI key: {openai_key}")
else:
raise ValueError("No OpenAI API keys found in the configuration.")

# Initialize TeamMapper and AgentCreator with API key
team_mapper = teamMappers(openai_key)
agent_creator = agentCreator(openai_key)

# Load configuration list for Autogen
config_list = config_list_from_json(os.path.join(os.path.dirname(__file__), '..', 'config', 'OAI_CONFIG_LIST_sample.json'))

# Function to create a GPT agent on-the-fly based on input criteria
def create_dynamic_agent(name, role):
assistant_id = agent_creator.create_agent(name=name, role=role)
return GPTAssistantAgent(name=name, llm_config={"config_list": config_list, "assistant_id": assistant_id})
# Initialize the TeamMapper with the OpenAI API key
team_mapper = teamMappers(openai_key)

# Function to manage team composition and interaction
def manage_teams(user_input):
# Function to route the user input and manage the interaction based on the mapped team
def route_user_input(user_input):
# Map user input to a specific team
team = team_mapper.map_team(user_input)
print(f"Selected Team: {team}")

# Example Teams and their corresponding actions
teams_functions = {
"DefaultTeam": lambda: [
create_dynamic_agent("Default Assistant", "Handling default tasks")
],
# Add more teams and their corresponding dynamic agents creation logic
}

if team not in teams_functions:
print("No specific team mapped, using DefaultTeam.")
team = "DefaultTeam"

# Create Autogen GroupChat with the dynamically created agent(s)
agents = teams_functions[team]()
groupchat = GroupChat(agents=agents, messages=[], max_round=15)
group_chat_manager = GroupChatManager(groupchat=groupchat, llm_config={"config_list": config_list})
group_chat_manager.start()
print(f"User input routed to the following team: {team}")

# Initialize TeamManager with configuration and API key
team_manager = TeamManager(openai_key)

# Manage teams and interactions based on the mapped team
team_manager.manage_teams(team, user_input)

def main():
# Example user input
user_input = "I need help understanding Autogen library."
manage_teams(user_input)
route_user_input(user_input)

if __name__ == "__main__":
main()
62 changes: 62 additions & 0 deletions src/agentics/teams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# File: ./src/agentics/teams.py
import os
from dotenv import load_dotenv
from autogen import GroupChat, GroupChatManager
from autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent
from autogen.util import config_list_from_json
from src.agentics.agentcreate import agentCreator

class TeamManager:
def __init__(self, openai_key):
# Load environment variables for assistant IDs, system messages, and teams
dotenv_path_system_messages = os.path.join(os.getcwd(), 'src', 'promptburo', 'system_messages.env')
dotenv_path_assistants = os.path.join(os.getcwd(), 'src', 'config', 'assistants.env')
dotenv_path_teams = os.path.join(os.getcwd(), 'src', 'promptburo', 'teams.env')

load_dotenv(dotenv_path_system_messages)
load_dotenv(dotenv_path_assistants)
load_dotenv(dotenv_path_teams)

self.agent_creator = agentCreator(openai_key)
self.config_list = config_list_from_json(os.path.join(os.getcwd(), '..', 'config', 'OAI_CONFIG_LIST_sample.json'))

self.team_agents = self._load_teams_config()

def _load_teams_config(self):
teams_config = {}
for key in os.environ:
if key in ["DefaultTeam", "SalesIntelligence", "FinanceTeam", "CodingTeam", "MarketingIntelligenceTeam", "ConsultingTeam"]:
teams_config[key] = os.getenv(key).split(',')
return teams_config

def create_agent(self, role):
assistant_id = os.getenv(f"{role.upper()}_ASSISTANT_ID")
system_message = os.getenv(f"{role.upper()}_MESSAGE")
if not assistant_id:
raise ValueError(f"Assistant ID not found for role: {role}")
return GPTAssistantAgent(name=role, llm_config={"config_list": self.config_list, "assistant_id": assistant_id}, initial_msg=system_message)

def manage_teams(self, team, user_input):
agents = []

# Dynamically create agents based on the team's roles
if team in self.team_agents:
for role in self.team_agents[team]:
agents.append(self.create_agent(role))
else:
print(f"No specific team mapped or team not recognized: {team}, using DefaultTeam.")
for role in self.team_agents.get("DefaultTeam", []):
agents.append(self.create_agent(role))

# Create Autogen GroupChat with the created agents
groupchat = GroupChat(agents=agents, messages=[], max_round=15, user_initiated_content=user_input)
group_chat_manager = GroupChatManager(groupchat=groupchat, llm_config={"config_list": self.config_list})
group_chat_manager.start()

return group_chat_manager
# # Example usage (Note: adjust the paths and configuration as needed)
# if __name__ == "__main__":
# team_manager = TeamManager("your_openai_key_here")
# team_chosen = "CodingTeam" # Example team chosen
# user_input = "I need help with a Python project."
# team_manager.manage_teams(team_chosen, user_input)
7 changes: 7 additions & 0 deletions src/promptburo/teams.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# File: ./src/promptburo/teams.env
DefaultTeam=PROJECT_MANAGER,CODER,REVIEWER
SalesIntelligence=MARKETING_EXPERT
FinanceTeam=FINANCE_EXPERT,FINANCE_ANALYST
CodingTeam=CODER
MarketingIntelligenceTeam=MARKETING_EXPERT
ConsultingTeam=CONSULTING_PRO