MCPcopy
hub / github.com/dataelement/Clawith / create_task

Function create_task

backend/app/api/tasks.py:63–97  ·  view source on GitHub ↗

Create a new task for an agent.

(
    agent_id: uuid.UUID,
    data: TaskCreate,
    current_user: User = Depends(get_current_user),
    db: AsyncSession = Depends(get_db),
)

Source from the content-addressed store, hash-verified

61
62@router.post("/", response_model=TaskOut, status_code=status.HTTP_201_CREATED)
63async def create_task(
64 agent_id: uuid.UUID,
65 data: TaskCreate,
66 current_user: User = Depends(get_current_user),
67 db: AsyncSession = Depends(get_db),
68):
69 """Create a new task for an agent."""
70 await check_agent_access(db, current_user, agent_id)
71 task = Task(
72 agent_id=agent_id,
73 title=data.title,
74 description=data.description,
75 type=data.type,
76 priority=data.priority,
77 due_date=data.due_date,
78 created_by=current_user.id,
79 supervision_target_name=data.supervision_target_name,
80 supervision_channel=data.supervision_channel,
81 remind_schedule=data.remind_schedule,
82 )
83 db.add(task)
84 await db.flush()
85
86 task_out = await _enrich_task_out(task, db)
87
88 # Commit so the background executor can see the task in its own session
89 await db.commit()
90
91 # Fire background execution for todo tasks
92 if data.type == "todo":
93 import asyncio
94 from app.services.task_executor import execute_task
95 asyncio.create_task(execute_task(task.id, agent_id))
96
97 return task_out
98
99
100@router.patch("/{task_id}", response_model=TaskOut)

Callers

nothing calls this directly

Calls 7

check_agent_accessFunction · 0.90
TaskClass · 0.90
execute_taskFunction · 0.90
_enrich_task_outFunction · 0.85
addMethod · 0.45
flushMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected