- Add app/core/deep_agent.py with Home and Floating supervisor graphs using LangGraph create_react_agent (hierarchical pattern) - Strip ChatAgent classes from all 4 agent files, keep @tool functions - Rewrite output_formatter.py for event-based (token/tool_end/mutations) stream - Update device_ws.py to use run_home_stream/run_floating_stream - Rewrite chat.py REST route to use run_home - Add update_core_memory tool to both supervisors - Add langgraph>=0.3.0 to requirements.txt - Remove orchestrator.py, execution_plan.py, agent_registry.py, plans.py - Remove PlanAction, PlanStep, ExecutionPlan, execution_mode from schemas - Update all affected tests to match new API - Remove 6 deprecated test files for deleted modules - Clean up stale docstrings referencing removed orchestrator
203 lines
6.3 KiB
Python
203 lines
6.3 KiB
Python
"""Task agent — tool definitions for task and task comment CRUD."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime, timezone
|
|
from typing import Any
|
|
|
|
from langchain_core.tools import tool
|
|
|
|
from app.core.ws_context import execute_on_client
|
|
|
|
|
|
# ── Task tools ────────────────────────────────────────────────────────
|
|
|
|
|
|
@tool
|
|
async def list_tasks(
|
|
project_id: str = "",
|
|
status: str = "",
|
|
search: str = "",
|
|
order_by: str = "",
|
|
) -> str:
|
|
"""List tasks, optionally filtered by project_id, status (todo|in_progress|done),
|
|
a search string, or an order_by field name (dueDate|priority|createdAt)."""
|
|
result = await execute_on_client(
|
|
action="select",
|
|
table="tasks",
|
|
filters={
|
|
"projectId": project_id or None,
|
|
"status": status or None,
|
|
"search": search or None,
|
|
"orderBy": order_by or None,
|
|
},
|
|
)
|
|
rows = result.get("rows", [])
|
|
if not rows:
|
|
return "No tasks found matching the given filters."
|
|
lines = [
|
|
f"- {r['title']} (status: {r['status']}, priority: {r['priority']}, id: {r['id']})"
|
|
for r in rows
|
|
]
|
|
return f"Found {len(rows)} task(s):\n" + "\n".join(lines)
|
|
|
|
|
|
@tool
|
|
async def create_task(
|
|
title: str,
|
|
description: str = "",
|
|
status: str = "todo",
|
|
priority: str = "medium",
|
|
assignees: str = "[]",
|
|
due_date: int = 0,
|
|
project_id: str = "",
|
|
is_ai_suggested: int = 0,
|
|
is_approved: int = 0,
|
|
) -> str:
|
|
"""Create a new task.
|
|
title: task title (required)
|
|
description: optional details
|
|
status: todo | in_progress | done (default: todo)
|
|
priority: high | medium | low (default: medium)
|
|
assignees: JSON-encoded array of assignee names, e.g. '["Alice"]'
|
|
due_date: Unix timestamp in milliseconds; 0 means no due date
|
|
project_id: optional UUID of the parent project
|
|
is_ai_suggested: 1 if proactively suggested, 0 if user-requested
|
|
is_approved: 0 until the user confirms; 1 when confirmed
|
|
"""
|
|
result = await execute_on_client(
|
|
action="insert",
|
|
table="tasks",
|
|
data={
|
|
"title": title,
|
|
"description": description or None,
|
|
"status": status,
|
|
"priority": priority,
|
|
"assignee": assignees,
|
|
"dueDate": due_date or None,
|
|
"projectId": project_id or None,
|
|
"isAiSuggested": is_ai_suggested,
|
|
"isApproved": is_approved,
|
|
},
|
|
)
|
|
row = result["row"]
|
|
return (
|
|
f"Task created: '{row['title']}' "
|
|
f"(id: {row['id']}, status: {row['status']}, priority: {row['priority']})"
|
|
)
|
|
|
|
|
|
@tool
|
|
async def update_task(
|
|
task_id: str,
|
|
title: str = "",
|
|
description: str = "",
|
|
status: str = "",
|
|
priority: str = "",
|
|
assignees: str = "",
|
|
due_date: int = -1,
|
|
project_id: str = "",
|
|
is_approved: int = -1,
|
|
) -> str:
|
|
"""Update fields on an existing task. Only pass fields you want to change.
|
|
task_id: the task's UUID (required)
|
|
due_date: -1 means unchanged; 0 clears the due date; any positive value sets it
|
|
is_approved: -1 means unchanged; 0 or 1 sets the value
|
|
"""
|
|
updates: dict[str, Any] = {}
|
|
if title:
|
|
updates["title"] = title
|
|
if description:
|
|
updates["description"] = description
|
|
if status:
|
|
updates["status"] = status
|
|
if priority:
|
|
updates["priority"] = priority
|
|
if assignees:
|
|
updates["assignee"] = assignees
|
|
if due_date != -1:
|
|
updates["dueDate"] = due_date or None
|
|
if project_id:
|
|
updates["projectId"] = project_id
|
|
if is_approved != -1:
|
|
updates["isApproved"] = is_approved
|
|
result = await execute_on_client(
|
|
action="update",
|
|
table="tasks",
|
|
data={"id": task_id, "updates": updates},
|
|
)
|
|
row = result["row"]
|
|
return f"Task updated: '{row['title']}' (id: {row['id']}, status: {row['status']})"
|
|
|
|
|
|
@tool
|
|
async def delete_task(task_id: str) -> str:
|
|
"""Delete a task permanently by its UUID."""
|
|
await execute_on_client(action="delete", table="tasks", data={"id": task_id})
|
|
return f"Task {task_id} deleted."
|
|
|
|
|
|
@tool
|
|
async def list_tasks_due_today() -> str:
|
|
"""List all tasks whose due date falls on today's date."""
|
|
now = datetime.now(tz=timezone.utc)
|
|
start_ms = int(datetime(now.year, now.month, now.day, tzinfo=timezone.utc).timestamp() * 1000)
|
|
end_ms = start_ms + 86_400_000 - 1 # last ms of today
|
|
result = await execute_on_client(
|
|
action="select",
|
|
table="tasks",
|
|
filters={"dueDateFrom": start_ms, "dueDateTo": end_ms},
|
|
)
|
|
rows = result.get("rows", [])
|
|
if not rows:
|
|
return "No tasks are due today."
|
|
lines = [
|
|
f"- {r['title']} (priority: {r['priority']}, status: {r['status']}, id: {r['id']})"
|
|
for r in rows
|
|
]
|
|
return f"Tasks due today ({len(rows)}):\n" + "\n".join(lines)
|
|
|
|
|
|
# ── Task comment tools ────────────────────────────────────────────────
|
|
|
|
|
|
@tool
|
|
async def list_task_comments(task_id: str) -> str:
|
|
"""List all comments on a task by its UUID."""
|
|
result = await execute_on_client(
|
|
action="select",
|
|
table="taskComments",
|
|
filters={"taskId": task_id},
|
|
)
|
|
rows = result.get("rows", [])
|
|
if not rows:
|
|
return f"No comments found for task {task_id}."
|
|
lines = [f"- [{r['author']}]: {r['content']} (id: {r['id']})" for r in rows]
|
|
return f"Found {len(rows)} comment(s):\n" + "\n".join(lines)
|
|
|
|
|
|
@tool
|
|
async def add_task_comment(task_id: str, author: str, content: str) -> str:
|
|
"""Add a comment to a task.
|
|
task_id: UUID of the task to comment on
|
|
author: name or ID of the comment author
|
|
content: comment text
|
|
"""
|
|
result = await execute_on_client(
|
|
action="insert",
|
|
table="taskComments",
|
|
data={"taskId": task_id, "author": author, "content": content},
|
|
)
|
|
row = result["row"]
|
|
return f"Comment added by {row['author']} on task {row['taskId']} (comment id: {row['id']})."
|
|
|
|
|
|
@tool
|
|
async def delete_task_comment(comment_id: str) -> str:
|
|
"""Delete a task comment by its UUID."""
|
|
await execute_on_client(action="delete", table="taskComments", data={"id": comment_id})
|
|
return f"Comment {comment_id} deleted."
|
|
|
|
|
|
|