Agent protocol now available

This commit is contained in:
SwiftyOS
2023-08-14 14:03:22 +02:00
parent ee6899c68a
commit 28f7a01797
3 changed files with 31 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
from agent_protocol import Agent, Step, Task
import time
import autogpt.utils
@@ -11,12 +11,15 @@ class AutoGPT:
async def task_handler(self, task: Task) -> None:
print(f"task: {task.input}")
await Agent.db.create_step(task.task_id, task.input, is_last=True)
time.sleep(2)
autogpt.utils.run(task.input)
await Agent.db.create_step(task.task_id, task.input)
async def step_handler(self, step: Step) -> Step:
print(f"step: {step.input}")
step = Agent.db.get_step(step.step_id)
updated_step: Step = Agent.db.update_step(step.step_id, status="completed")
updated_step.output = step.input
agent_step = await Agent.db.get_step(step.task_id, step.step_id)
updated_step: Step = await Agent.db.update_step(agent_step.task_id, agent_step.step_id, status="completed")
updated_step.output = agent_step.input
print(f"Step completed: {updated_step}")
return updated_step

View File

@@ -9,7 +9,7 @@ import sqlite3
from typing import Dict, List, Optional
from agent_protocol import Artifact, Step, Task, TaskDB
from agent_protocol.models import TaskInput
from agent_protocol.models import TaskInput, Status
class DataNotFoundError(Exception):
@@ -130,7 +130,15 @@ class AgentDB(TaskDB):
cursor = self.conn.cursor()
cursor.execute("SELECT * FROM tasks WHERE task_id=?", (task_id,))
if task := cursor.fetchone():
return Task(task_id=task[0], input=task[1], additional_input=task[2])
task = Task(task_id=task[0], input=task[1], additional_input=task[2])
cursor.execute("SELECT * FROM steps WHERE task_id=?", (task_id,))
steps = cursor.fetchall()
if steps:
for step in steps:
status = Status.created if step[3] == "created" else Status.completed
task.steps.append(Step(task_id=step[1], step_id=step[0], name=step[2], status=status, is_last=True if step[4] == 1 else False, additional_properties=step[5]))
print(f"Task: {task}")
return task
else:
raise DataNotFoundError("Task not found")

13
test.py Normal file
View File

@@ -0,0 +1,13 @@
DATABASE_NAME="agent.db"
import sqlite3
# Read all data from database
def read_all():
conn = sqlite3.connect(DATABASE_NAME)
cur = conn.cursor()
cur.execute("SELECT * FROM tasks")
rows = cur.fetchall()
conn.close()
return rows
print(read_all())