Skip to content

Commit f94cb6b

Browse files
authored
Add scheduled task endpoints (#1450)
* Improve JWT expiration time * Add scheduled task endpoints * Add router * get json response
1 parent 7ef3cbd commit f94cb6b

File tree

4 files changed

+160
-2
lines changed

4 files changed

+160
-2
lines changed

agixt/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from endpoints.Provider import app as provider_endpoints
1919
from endpoints.Auth import app as auth_endpoints
2020
from endpoints.Health import app as health_endpoints
21+
from endpoints.Tasks import app as tasks_endpoints
2122
from endpoints.TeslaIntegration import register_tesla_routes
2223
from Globals import getenv
2324
from contextlib import asynccontextmanager
@@ -86,6 +87,7 @@ def signal_handler(signum, frame):
8687

8788

8889
app.include_router(agent_endpoints)
90+
app.include_router(tasks_endpoints)
8991
app.include_router(chain_endpoints)
9092
app.include_router(completions_endpoints)
9193
app.include_router(conversation_endpoints)

agixt/endpoints/Tasks.py

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
from fastapi import APIRouter, Depends, Header
2+
from ApiClient import verify_api_key, get_api_client
3+
from Models import ResponseMessage
4+
from pydantic import BaseModel
5+
from Globals import getenv
6+
import logging
7+
import json
8+
9+
10+
app = APIRouter()
11+
12+
logging.basicConfig(
13+
level=getenv("LOG_LEVEL"),
14+
format=getenv("LOG_FORMAT"),
15+
)
16+
17+
18+
class TaskModel(BaseModel):
19+
agent_name: str
20+
title: str
21+
task_description: str
22+
days: int = 0
23+
hours: int = 0
24+
minutes: int = 0
25+
conversation_id: str = None
26+
27+
28+
class ReoccurringTaskModel(BaseModel):
29+
agent_name: str
30+
title: str
31+
task_description: str
32+
start_date: str
33+
end_date: str
34+
frequency: str = "daily"
35+
conversation_id: str = None
36+
37+
38+
class ModifyTaskModel(BaseModel):
39+
task_id: str
40+
title: str = None
41+
description: str = None
42+
due_date: str = None
43+
estimated_hours: str = None
44+
priority: str = None
45+
cancel_task: str = "false"
46+
agent_name: str = None
47+
conversation_id: str = None
48+
49+
50+
@app.post(
51+
"/v1/task",
52+
tags=["Tasks"],
53+
response_model=ResponseMessage,
54+
summary="Create a new task",
55+
description="Create a new task with the specified parameters.",
56+
dependencies=[Depends(verify_api_key)],
57+
)
58+
async def new_task(
59+
task: TaskModel,
60+
user=Depends(verify_api_key),
61+
authorization: str = Header(None),
62+
) -> ResponseMessage:
63+
agixt = get_api_client(authorization=authorization)
64+
response = agixt.execute_command(
65+
agent_name=task.agent_name,
66+
command_name="Schedule Task",
67+
command_args={
68+
"task_description": task.task_description,
69+
"days": task.days,
70+
"hours": task.hours,
71+
"minutes": task.minutes,
72+
},
73+
conversation_name=task.conversation_id,
74+
)
75+
return ResponseMessage(message=f"Task created for agent '{task.agent_name}'.")
76+
77+
78+
@app.post(
79+
"/v1/reoccurring_task",
80+
tags=["Tasks"],
81+
response_model=ResponseMessage,
82+
summary="Create a new reoccurring task",
83+
description="Create a new reoccurring task with the specified parameters.",
84+
dependencies=[Depends(verify_api_key)],
85+
)
86+
async def new_reoccurring_task(
87+
task: ReoccurringTaskModel,
88+
user=Depends(verify_api_key),
89+
authorization: str = Header(None),
90+
) -> ResponseMessage:
91+
agixt = get_api_client(authorization=authorization)
92+
response = agixt.execute_command(
93+
agent_name=task.agent_name,
94+
command_name="Schedule Reoccurring Task",
95+
command_args={
96+
"task_description": task.task_description,
97+
"start_date": task.start_date,
98+
"end_date": task.end_date,
99+
"frequency": task.frequency,
100+
},
101+
conversation_name=task.conversation_id,
102+
)
103+
return ResponseMessage(
104+
message=f"Reoccurring task created for agent '{task.agent_name}'."
105+
)
106+
107+
108+
@app.put(
109+
"/v1/task",
110+
tags=["Tasks"],
111+
response_model=ResponseMessage,
112+
summary="Modify an existing task",
113+
description="Modify an existing task with new information, or cancel it.",
114+
dependencies=[Depends(verify_api_key)],
115+
)
116+
async def modify_task(
117+
task: ModifyTaskModel,
118+
user=Depends(verify_api_key),
119+
authorization: str = Header(None),
120+
) -> ResponseMessage:
121+
agixt = get_api_client(authorization=authorization)
122+
response = agixt.execute_command(
123+
agent_name=task.agent_name,
124+
command_name="Modify Scheduled Task",
125+
command_args={
126+
"task_id": task.task_id,
127+
"title": task.title,
128+
"description": task.description,
129+
"due_date": task.due_date,
130+
"estimated_hours": task.estimated_hours,
131+
"priority": task.priority,
132+
"cancel_task": task.cancel_task,
133+
},
134+
conversation_name=task.conversation_id,
135+
)
136+
return ResponseMessage(message=f"Task modified for agent '{task.agent_name}'.")
137+
138+
139+
@app.get(
140+
"/v1/tasks",
141+
tags=["Tasks"],
142+
summary="Get all scheduled tasks",
143+
description="Get all scheduled tasks for the current agent.",
144+
dependencies=[Depends(verify_api_key)],
145+
)
146+
async def get_scheduled_tasks(
147+
user=Depends(verify_api_key), authorization: str = Header(None)
148+
):
149+
agixt = get_api_client(authorization=authorization)
150+
response = agixt.execute_command(
151+
agent_name="",
152+
command_name="Get Scheduled Tasks",
153+
command_args={},
154+
conversation_name="",
155+
)
156+
return json.loads(response)

agixt/extensions/scheduled_tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async def schedule_task(
103103
memory_collection=self.conversation_id, # This ensures context preservation
104104
)
105105

106-
return f"Scheduled follow-up task {task_id} for {due_date.strftime('%Y-%m-%d %H:%M:%S')}"
106+
return f"Scheduled task {task_id} for {due_date.strftime('%Y-%m-%d %H:%M:%S')}"
107107

108108
async def schedule_reoccurring_task(
109109
self,

agixt/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.7.8
1+
v1.7.9

0 commit comments

Comments
 (0)