mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-27 19:04:25 +01:00
Agent protocol now available
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user