mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-17 14:04:27 +01:00
Deletes old output renderer and renames AutonomousAI folder to scripts
This commit is contained in:
68
scripts/agent_manager.py
Normal file
68
scripts/agent_manager.py
Normal file
@@ -0,0 +1,68 @@
|
||||
import openai
|
||||
|
||||
next_key = 0
|
||||
agents = {} # key, (task, full_message_history, model)
|
||||
|
||||
# Create new GPT agent
|
||||
def create_agent(task, prompt, model):
|
||||
global next_key
|
||||
global agents
|
||||
|
||||
messages = [{"role": "user", "content": prompt},]
|
||||
|
||||
# Start GTP3 instance
|
||||
response = openai.ChatCompletion.create(
|
||||
model=model,
|
||||
messages=messages,
|
||||
)
|
||||
|
||||
agent_reply = response.choices[0].message["content"]
|
||||
|
||||
# Update full message history
|
||||
messages.append({"role": "assistant", "content": agent_reply})
|
||||
|
||||
key = next_key
|
||||
next_key += 1 # This is done instead of len(agents) to make keys unique even if agents are deleted
|
||||
|
||||
agents[key] = (task, messages, model)
|
||||
|
||||
return key, agent_reply
|
||||
|
||||
def message_agent(key, message):
|
||||
global agents
|
||||
|
||||
task, messages, model = agents[int(key)]
|
||||
|
||||
# Add user message to message history before sending to agent
|
||||
messages.append({"role": "user", "content": message})
|
||||
|
||||
# Start GTP3 instance
|
||||
response = openai.ChatCompletion.create(
|
||||
model=model,
|
||||
messages=messages,
|
||||
)
|
||||
|
||||
# Get agent response
|
||||
agent_reply = response.choices[0].message["content"]
|
||||
|
||||
# Update full message history
|
||||
messages.append({"role": "assistant", "content": agent_reply})
|
||||
|
||||
return agent_reply
|
||||
|
||||
def list_agents():
|
||||
global agents
|
||||
|
||||
# Return a list of agent keys and their tasks
|
||||
return [(key, task) for key, (task, _, _) in agents.items()]
|
||||
|
||||
def delete_agent(key):
|
||||
global agents
|
||||
|
||||
try:
|
||||
del agents[key]
|
||||
return True
|
||||
except KeyError:
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user