Workflow ที่ขับเคลื่อนด้วย Task
ใช้ task ของ Synapse เพื่อขับเคลื่อน workflow LLM หลายขั้นตอนที่อยู่รอดข้าม session
Workflow ที่ขับเคลื่อนด้วย Task
task ไม่ใช่แค่ todo — แต่เป็นกระดูกสันหลังของ workflow LLM ที่ถาวร โดยการสร้าง task สำหรับงานหลายขั้นตอน คุณรับประกัน continuity ข้าม session และให้ audit trail ของสิ่งที่ทำ
ทำไมต้อง Task-Driven?
ไม่มี task:
- LLM เริ่มแต่ละ session โดยไม่แน่ใจว่าจะทำอะไร
- งานหลายขั้นตอนถูกลืมกลางการปฏิบัติ
- ไม่มี record ของสิ่งที่ทำ
มี task:
- LLM ทำ task ที่กำลังดำเนินการต่อทันที
- งานหลายขั้นตอนอยู่รอดข้าม session
- audit trail ในตัวของงานทั้งหมด
รูปแบบ
1. ที่จุดเริ่มต้น session: ตรวจ task in_progress
2. หากมี task: ทำต่อ
3. หากไม่มี task: สร้าง task ใหม่สำหรับงานปัจจุบัน
4. อัปเดตสถานะ task ขณะคืบหน้า
5. ทำเครื่องหมายเสร็จเมื่อเสร็จสิ้นการ implement
ขั้นตอนที่ 1: สร้าง task สำหรับงานหลายขั้นตอน
def start_workflow(title, steps):
"""Create a task for multi-step work."""
task_id = create_task(
title=title,
description=f"Steps:\n" + "\n".join(f" {i+1}. {s}" for i, s in enumerate(steps)),
priority="high"
)
return task_id
# Example
task_id = start_workflow("Deploy Synapse v1.6.0", [
"Bump version in package.json",
"Update CHANGELOG.md",
"Commit and push",
"Wait for CI green",
"Verify deployment"
])ขั้นตอนที่ 2: ติดตามความคืบหน้าใน description ของ task
def update_progress(task_id, current_step, total_steps, status_note):
"""Update task with current progress."""
description = f"Progress: {current_step}/{total_steps}\nStatus: {status_note}"
update_task(task_id, status="in_progress", description=description)
# Example
update_progress(task_id, 2, 5, "CHANGELOG updated, committing now")ขั้นตอนที่ 3: ทำต่อข้าม session
def resume_work():
"""At session start, find and resume in-progress tasks."""
tasks = list_tasks(status="in_progress")
for task in tasks:
print(f"Resuming: {task['title']}")
print(f"Last status: {task['description']}")
# Parse progress from description
progress = parse_progress(task['description'])
next_step = progress['current_step'] + 1
# Continue from next step
continue_from_step(task['id'], next_step)ขั้นตอนที่ 4: ทำเสร็จและเก็บถาวร
def complete_task(task_id, summary):
"""Mark task done with completion summary."""
update_task(task_id,
status="done",
description=f"COMPLETED. Summary: {summary}"
)
# Also store as memory for long-term reference
remember(
category="project",
key=f"completed_{task_id}",
content=f"Task: {task_id}\nSummary: {summary}",
tags=["completed", "task"],
priority="normal"
)ตัวอย่างเต็ม: Deploy Workflow
class DeployWorkflow:
def __init__(self, version):
self.version = version
self.task_id = None
self.steps = [
("Bump version", self.bump_version),
("Update changelog", self.update_changelog),
("Commit and push", self.commit_push),
("Wait for CI", self.wait_for_ci),
("Verify deployment", self.verify_deployment),
]
def run(self):
# Check if already in progress
existing = self.find_existing()
if existing:
self.task_id = existing['id']
start_step = self.parse_progress(existing['description'])
else:
self.task_id = create_task(
title=f"Deploy Synapse v{self.version}",
description=self.build_description(0),
priority="high"
)
start_step = 0
# Execute remaining steps
for i in range(start_step, len(self.steps)):
step_name, step_fn = self.steps[i]
self.update_progress(i, f"Running: {step_name}")
try:
step_fn()
except Exception as e:
self.update_progress(i, f"FAILED at {step_name}: {e}")
raise
self.complete()
def update_progress(self, step_idx, status):
update_task(self.task_id,
status="in_progress",
description=f"Step {step_idx+1}/{len(self.steps)}: {status}"
)
def complete(self):
complete_task(self.task_id, f"Deployed v{self.version} successfully")ลำดับชั้น Task
สำหรับงานซับซ้อน ใช้ความสัมพันธ์ parent-child task:
# Parent task
parent_id = create_task("v1.6.0 Release", priority="high")
# Sub-tasks (linked via tags)
create_task("Bump version",
description=f"Parent: {parent_id}",
tags=["v1.6.0", f"parent-{parent_id}"],
priority="high")
create_task("Update docs",
description=f"Parent: {parent_id}",
tags=["v1.6.0", f"parent-{parent_id}"],
priority="normal")ค้นหา sub-task:
curl -H "Authorization: Bearer $KEY" \
".../memory/search?q=parent-{parent_id}&tag=v1.6.0"Workflow สถานะ
pending → in_progress → done
↘ cancelledPending
task สร้างแล้วแต่ยังไม่เริ่ม ใช้สำหรับงานที่วางแผนไว้
In Progress
กำลังดำเนินการ อัปเดต description ด้วยความคืบหน้า
Done
เสร็จสิ้นสำเร็จ description ควรรวมสรุป
Cancelled
ถูกยกเลิก description ควรรวมเหตุผล
แนวทางปฏิบัติที่ดีที่สุด
รูปแบบทั่วไป
รูปแบบ: Bug Fix Workflow
def fix_bug(bug_id, description):
task_id = create_task(
title=f"Fix bug {bug_id}",
description=description,
priority="high"
)
# Investigate
update_progress(task_id, "Investigating root cause")
root_cause = investigate()
# Fix
update_progress(task_id, f"Applying fix: {root_cause}")
apply_fix(root_cause)
# Test
update_progress(task_id, "Testing fix")
run_tests()
# Deploy
update_progress(task_id, "Deploying fix")
deploy()
complete_task(task_id, f"Fixed: {root_cause}")รูปแบบ: Research Workflow
def research_topic(topic):
task_id = create_task(
title=f"Research: {topic}",
priority="normal"
)
update_progress(task_id, "Gathering sources")
sources = gather_sources(topic)
update_progress(task_id, "Analyzing")
analysis = analyze(sources)
update_progress(task_id, "Storing findings")
remember("fact", f"research_{topic}", analysis,
tags=["research", topic], priority="normal")
complete_task(task_id, f"Research complete: {len(sources)} sources")