-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
test.py
109 lines (90 loc) · 3.88 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import argparse
from datetime import datetime
from time import time
from superagi.lib.logger import logger
from sqlalchemy.orm import sessionmaker
from superagi.worker import execute_agent
from superagi.models.agent import Agent
from superagi.models.agent_config import AgentConfiguration
from superagi.models.agent_execution import AgentExecution
from superagi.models.db import connect_db
from superagi.models.organisation import Organisation
from superagi.models.project import Project
parser = argparse.ArgumentParser(description='Create a new agent.')
parser.add_argument('--name', type=str, help='Agent name for the script.')
parser.add_argument('--description', type=str, help='Agent description for the script.')
parser.add_argument('--goals', type=str, nargs='+', help='Agent goals for the script.')
args = parser.parse_args()
agent_name = args.name
agent_description = args.description
agent_goals = args.goals
engine = connect_db()
Session = sessionmaker(bind=engine)
session = Session()
def ask_user_for_goals():
goals = []
while True:
goal = input("Enter a goal (or 'q' to quit): ")
if goal == 'q':
break
goals.append(goal)
return goals
def run_superagi_cli(agent_name=None, agent_description=None, agent_goals=None):
# Create default organization
organization = Organisation(name='Default Organization', description='Default organization description')
session.add(organization)
session.flush() # Flush pending changes to generate the agent's ID
session.commit()
logger.info(organization)
# Create default project associated with the organization
project = Project(name='Default Project', description='Default project description',
organisation_id=organization.id)
session.add(project)
session.flush() # Flush pending changes to generate the agent's ID
session.commit()
logger.info(project)
# Agent
if agent_name is None:
agent_name = input("Enter agent name: ")
if agent_description is None:
agent_description = input("Enter agent description: ")
agent = Agent(name=agent_name, description=agent_description, project_id=project.id)
session.add(agent)
session.flush()
session.commit()
logger.info(agent)
# Agent Config
# Create Agent Configuration
agent_config_values = {
"goal": ask_user_for_goals() if agent_goals is None else agent_goals,
"agent_type": "Type Non-Queue",
"constraints": ["~4000 word limit for short term memory. ",
"Your short term memory is short, so immediately save important information to files.",
"If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.",
"No user assistance",
"Exclusively use the commands listed in double quotes e.g. \"command name\""
],
"tools": [],
"exit": "Default",
"iteration_interval": 0,
"model": "gpt-4",
"permission_type": "Default",
"LTM_DB": "Pinecone",
"memory_window": 10
}
agent_configurations = [
AgentConfiguration(agent_id=agent.id, key=key, value=str(value))
for key, value in agent_config_values.items()
]
session.add_all(agent_configurations)
session.commit()
logger.info("Agent Config : ")
logger.info(agent_configurations)
# Create agent execution in RUNNING state associated with the agent
execution = AgentExecution(status='RUNNING', agent_id=agent.id, last_execution_time=datetime.utcnow())
session.add(execution)
session.commit()
logger.info("Final Execution")
logger.info(execution)
execute_agent.delay(execution.id, datetime.now())
run_superagi_cli(agent_name=agent_name, agent_description=agent_description, agent_goals=agent_goals)