Skip to content

Commit

Permalink
inject pending tasks to context
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-XT committed Dec 23, 2024
1 parent a9cd7a4 commit db3949a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
49 changes: 49 additions & 0 deletions agixt/Agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
get_session,
UserOAuth,
OAuthProvider,
TaskItem,
)
from Providers import Providers
from Extensions import Extensions
Expand Down Expand Up @@ -750,3 +751,51 @@ def get_agent_id(self):
return None
session.close()
return agent.id

def get_conversation_tasks(self, conversation_id: str) -> str:
"""Get all tasks assigned to an agent"""
try:
session = get_session()
tasks = (
session.query(TaskItem)
.filter(
TaskItem.agent_id == self.agent_id,
TaskItem.user_id == self.user_id,
TaskItem.completed == False,
TaskItem.memory_collection == conversation_id,
)
.all()
)

markdown_tasks = "## The Assistant's Scheduled Tasks\n**The assistant currently has the following tasks scheduled:**\n"
for task in tasks:
markdown_tasks += (
f"### Task: {task.title}\n"
f"**Description:** {task.description}\n"
f"**Will be completed at:** {task.due_date}\n"
f"**Status:** {task.status}\n"
)
session.close()
except Exception as e:
logging.error(f"Error getting tasks by agent: {str(e)}")
session.close()
return ""

def get_all_pending_tasks(self) -> list:
"""Get all tasks assigned to an agent"""
try:
session = get_session()
tasks = (
session.query(TaskItem)
.filter(
TaskItem.agent_id == self.agent_id,
TaskItem.user_id == self.user_id,
TaskItem.completed == False,
)
.all()
)
session.close()
return tasks
except Exception as e:
logging.error(f"Error getting tasks by agent: {str(e)}")
return []
3 changes: 3 additions & 0 deletions agixt/Interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ async def format_prompt(
conversation_results = int(top_results) if top_results > 0 else 5
except:
conversation_results = 5
agent_tasks = self.agent.get_conversation_tasks(conversation_id=conversation_id)
if agent_tasks != "":
context.append(agent_tasks)
conversation_history = ""
conversation = c.get_conversation()
if "interactions" in conversation:
Expand Down
20 changes: 0 additions & 20 deletions agixt/Task.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,26 +183,6 @@ async def get_tasks_by_category(self, category_name: str) -> list:
session.close()
return tasks

async def get_tasks_by_agent(self, agent_name: str) -> list:
"""Get all tasks assigned to an agent"""
session = get_session()
agent = (
session.query(Agent)
.filter(Agent.name == agent_name, Agent.user_id == self.user_id)
.first()
)
if not agent:
session.close()
return []

tasks = (
session.query(TaskItem)
.filter(TaskItem.agent_id == agent.id, TaskItem.user_id == self.user_id)
.all()
)
session.close()
return tasks

async def update_task(
self,
task_id: str,
Expand Down

0 comments on commit db3949a

Please sign in to comment.