{"title":"Task-Driven Workflow","slug":"task-driven-workflow","category":"llm-cookbook","summary":"Use Synapse tasks to drive multi-step LLM workflows that survive across sessions.","audience":["llm"],"tags":["cookbook","tasks","workflow","persistence"],"difficulty":"intermediate","updated":"2026-06-27","word_count":263,"read_minutes":1,"lang":"en","translated":true,"requested_lang":"en","content_markdown":"\n# Task-Driven Workflow\n\nTasks aren't just todos — they're the backbone of persistent LLM workflows.\nBy creating tasks for multi-step work, you ensure continuity across sessions\nand provide audit trails for what was done.\n\n## Why Task-Driven?\n\nWithout tasks:\n- LLM starts each session unsure what to do\n- Multi-step work is forgotten mid-execution\n- No record of what's been done\n\nWith tasks:\n- LLM resumes in-progress tasks immediately\n- Multi-step work survives across sessions\n- Built-in audit trail of all work\n\n## The Pattern\n\n```\n1. At session start: check in_progress tasks\n2. If tasks exist: resume them\n3. If no tasks: create new tasks for current work\n4. Update task status as you progress\n5. Mark done when complete\n```\n\n## Implementation\n\n### Step 1: Create a task for multi-step work\n\n```python\ndef start_workflow(title, steps):\n    \"\"\"Create a task for multi-step work.\"\"\"\n    task_id = create_task(\n        title=title,\n        description=f\"Steps:\\n\" + \"\\n\".join(f\"  {i+1}. {s}\" for i, s in enumerate(steps)),\n        priority=\"high\"\n    )\n    return task_id\n\n# Example\ntask_id = start_workflow(\"Deploy Synapse v1.6.0\", [\n    \"Bump version in package.json\",\n    \"Update CHANGELOG.md\",\n    \"Commit and push\",\n    \"Wait for CI green\",\n    \"Verify deployment\"\n])\n```\n\n### Step 2: Track progress in task description\n\n```python\ndef update_progress(task_id, current_step, total_steps, status_note):\n    \"\"\"Update task with current progress.\"\"\"\n    description = f\"Progress: {current_step}/{total_steps}\\nStatus: {status_note}\"\n    update_task(task_id, status=\"in_progress\", description=description)\n\n# Example\nupdate_progress(task_id, 2, 5, \"CHANGELOG updated, committing now\")\n```\n\n### Step 3: Resume across sessions\n\n```python\ndef resume_work():\n    \"\"\"At session start, find and resume in-progress tasks.\"\"\"\n    tasks = list_tasks(status=\"in_progress\")\n    \n    for task in tasks:\n        print(f\"Resuming: {task['title']}\")\n        print(f\"Last status: {task['description']}\")\n        \n        # Parse progress from description\n        progress = parse_progress(task['description'])\n        next_step = progress['current_step'] + 1\n        \n        # Continue from next step\n        continue_from_step(task['id'], next_step)\n```\n\n### Step 4: Complete and archive\n\n```python\ndef complete_task(task_id, summary):\n    \"\"\"Mark task done with completion summary.\"\"\"\n    update_task(task_id, \n        status=\"done\",\n        description=f\"COMPLETED. Summary: {summary}\"\n    )\n    # Also store as memory for long-term reference\n    remember(\n        category=\"project\",\n        key=f\"completed_{task_id}\",\n        content=f\"Task: {task_id}\\nSummary: {summary}\",\n        tags=[\"completed\", \"task\"],\n        priority=\"normal\"\n    )\n```\n\n## Full Example: Deploy Workflow\n\n```python\nclass DeployWorkflow:\n    def __init__(self, version):\n        self.version = version\n        self.task_id = None\n        self.steps = [\n            (\"Bump version\", self.bump_version),\n            (\"Update changelog\", self.update_changelog),\n            (\"Commit and push\", self.commit_push),\n            (\"Wait for CI\", self.wait_for_ci),\n            (\"Verify deployment\", self.verify_deployment),\n        ]\n    \n    def run(self):\n        # Check if already in progress\n        existing = self.find_existing()\n        if existing:\n            self.task_id = existing['id']\n            start_step = self.parse_progress(existing['description'])\n        else:\n            self.task_id = create_task(\n                title=f\"Deploy Synapse v{self.version}\",\n                description=self.build_description(0),\n                priority=\"high\"\n            )\n            start_step = 0\n        \n        # Execute remaining steps\n        for i in range(start_step, len(self.steps)):\n            step_name, step_fn = self.steps[i]\n            self.update_progress(i, f\"Running: {step_name}\")\n            try:\n                step_fn()\n            except Exception as e:\n                self.update_progress(i, f\"FAILED at {step_name}: {e}\")\n                raise\n        \n        self.complete()\n    \n    def update_progress(self, step_idx, status):\n        update_task(self.task_id,\n            status=\"in_progress\",\n            description=f\"Step {step_idx+1}/{len(self.steps)}: {status}\"\n        )\n    \n    def complete(self):\n        complete_task(self.task_id, f\"Deployed v{self.version} successfully\")\n```\n\n## Task Hierarchy\n\nFor complex work, use parent-child task relationships:\n\n```python\n# Parent task\nparent_id = create_task(\"v1.6.0 Release\", priority=\"high\")\n\n# Sub-tasks (linked via tags)\ncreate_task(\"Bump version\", \n    description=f\"Parent: {parent_id}\",\n    tags=[\"v1.6.0\", f\"parent-{parent_id}\"],\n    priority=\"high\")\n\ncreate_task(\"Update docs\",\n    description=f\"Parent: {parent_id}\",\n    tags=[\"v1.6.0\", f\"parent-{parent_id}\"],\n    priority=\"normal\")\n```\n\nSearch for sub-tasks:\n\n```bash\ncurl -H \"Authorization: Bearer $KEY\" \\\n     \".../memory/search?q=parent-{parent_id}&tag=v1.6.0\"\n```\n\n## Status Workflow\n\n```\npending → in_progress → done\n                ↘ cancelled\n```\n\n### Pending\n\nTask created but not started. Use for planned work.\n\n### In Progress\n\nCurrently being worked on. **Update description with progress.**\n\n### Done\n\nCompleted successfully. Description should include summary.\n\n### Cancelled\n\nAbandoned. Description should include reason.\n\n## Best Practices\n\n> [!TIP]\n> - **Create tasks for multi-step work** — single-step work doesn't need a task\n> - **Update description with progress** — enables resumption\n> - **Use high priority for active work** — surfaces in recall\n> - **Complete tasks when done** — don't leave them in_progress\n> - **Store completion summaries as memories** — long-term reference\n\n## Common Patterns\n\n### Pattern: Bug Fix Workflow\n\n```python\ndef fix_bug(bug_id, description):\n    task_id = create_task(\n        title=f\"Fix bug {bug_id}\",\n        description=description,\n        priority=\"high\"\n    )\n    \n    # Investigate\n    update_progress(task_id, \"Investigating root cause\")\n    root_cause = investigate()\n    \n    # Fix\n    update_progress(task_id, f\"Applying fix: {root_cause}\")\n    apply_fix(root_cause)\n    \n    # Test\n    update_progress(task_id, \"Testing fix\")\n    run_tests()\n    \n    # Deploy\n    update_progress(task_id, \"Deploying fix\")\n    deploy()\n    \n    complete_task(task_id, f\"Fixed: {root_cause}\")\n```\n\n### Pattern: Research Workflow\n\n```python\ndef research_topic(topic):\n    task_id = create_task(\n        title=f\"Research: {topic}\",\n        priority=\"normal\"\n    )\n    \n    update_progress(task_id, \"Gathering sources\")\n    sources = gather_sources(topic)\n    \n    update_progress(task_id, \"Analyzing\")\n    analysis = analyze(sources)\n    \n    update_progress(task_id, \"Storing findings\")\n    remember(\"fact\", f\"research_{topic}\", analysis,\n             tags=[\"research\", topic], priority=\"normal\")\n    \n    complete_task(task_id, f\"Research complete: {len(sources)} sources\")\n```\n\n## Next Steps\n\n- [Session Start Pattern](/docs/llm-cookbook/session-start-pattern)\n- [Chat Polling Pattern](/docs/llm-cookbook/chat-polling-pattern)\n- [Error Recovery](/docs/llm-cookbook/error-recovery)\n","content_html":"<h1>Task-Driven Workflow</h1>\n<p>Tasks aren&#39;t just todos — they&#39;re the backbone of persistent LLM workflows.\nBy creating tasks for multi-step work, you ensure continuity across sessions\nand provide audit trails for what was done.</p>\n<h2>Why Task-Driven?</h2>\n<p>Without tasks:</p>\n<ul>\n<li>LLM starts each session unsure what to do</li>\n<li>Multi-step work is forgotten mid-execution</li>\n<li>No record of what&#39;s been done</li>\n</ul>\n<p>With tasks:</p>\n<ul>\n<li>LLM resumes in-progress tasks immediately</li>\n<li>Multi-step work survives across sessions</li>\n<li>Built-in audit trail of all work</li>\n</ul>\n<h2>The Pattern</h2>\n<pre><code class=\"hljs language-plaintext\">1. At session start: check in_progress tasks\n2. If tasks exist: resume them\n3. If no tasks: create new tasks for current work\n4. Update task status as you progress\n5. Mark done when complete</code></pre><h2>Implementation</h2>\n<h3>Step 1: Create a task for multi-step work</h3>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">start_workflow</span>(<span class=\"hljs-params\">title, steps</span>):\n    <span class=\"hljs-string\">&quot;&quot;&quot;Create a task for multi-step work.&quot;&quot;&quot;</span>\n    task_id = create_task(\n        title=title,\n        description=<span class=\"hljs-string\">f&quot;Steps:\\n&quot;</span> + <span class=\"hljs-string\">&quot;\\n&quot;</span>.join(<span class=\"hljs-string\">f&quot;  <span class=\"hljs-subst\">{i+<span class=\"hljs-number\">1</span>}</span>. <span class=\"hljs-subst\">{s}</span>&quot;</span> <span class=\"hljs-keyword\">for</span> i, s <span class=\"hljs-keyword\">in</span> <span class=\"hljs-built_in\">enumerate</span>(steps)),\n        priority=<span class=\"hljs-string\">&quot;high&quot;</span>\n    )\n    <span class=\"hljs-keyword\">return</span> task_id\n\n<span class=\"hljs-comment\"># Example</span>\ntask_id = start_workflow(<span class=\"hljs-string\">&quot;Deploy Synapse v1.6.0&quot;</span>, [\n    <span class=\"hljs-string\">&quot;Bump version in package.json&quot;</span>,\n    <span class=\"hljs-string\">&quot;Update CHANGELOG.md&quot;</span>,\n    <span class=\"hljs-string\">&quot;Commit and push&quot;</span>,\n    <span class=\"hljs-string\">&quot;Wait for CI green&quot;</span>,\n    <span class=\"hljs-string\">&quot;Verify deployment&quot;</span>\n])</code></pre><h3>Step 2: Track progress in task description</h3>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">update_progress</span>(<span class=\"hljs-params\">task_id, current_step, total_steps, status_note</span>):\n    <span class=\"hljs-string\">&quot;&quot;&quot;Update task with current progress.&quot;&quot;&quot;</span>\n    description = <span class=\"hljs-string\">f&quot;Progress: <span class=\"hljs-subst\">{current_step}</span>/<span class=\"hljs-subst\">{total_steps}</span>\\nStatus: <span class=\"hljs-subst\">{status_note}</span>&quot;</span>\n    update_task(task_id, status=<span class=\"hljs-string\">&quot;in_progress&quot;</span>, description=description)\n\n<span class=\"hljs-comment\"># Example</span>\nupdate_progress(task_id, <span class=\"hljs-number\">2</span>, <span class=\"hljs-number\">5</span>, <span class=\"hljs-string\">&quot;CHANGELOG updated, committing now&quot;</span>)</code></pre><h3>Step 3: Resume across sessions</h3>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">resume_work</span>():\n    <span class=\"hljs-string\">&quot;&quot;&quot;At session start, find and resume in-progress tasks.&quot;&quot;&quot;</span>\n    tasks = list_tasks(status=<span class=\"hljs-string\">&quot;in_progress&quot;</span>)\n    \n    <span class=\"hljs-keyword\">for</span> task <span class=\"hljs-keyword\">in</span> tasks:\n        <span class=\"hljs-built_in\">print</span>(<span class=\"hljs-string\">f&quot;Resuming: <span class=\"hljs-subst\">{task[<span class=\"hljs-string\">&#x27;title&#x27;</span>]}</span>&quot;</span>)\n        <span class=\"hljs-built_in\">print</span>(<span class=\"hljs-string\">f&quot;Last status: <span class=\"hljs-subst\">{task[<span class=\"hljs-string\">&#x27;description&#x27;</span>]}</span>&quot;</span>)\n        \n        <span class=\"hljs-comment\"># Parse progress from description</span>\n        progress = parse_progress(task[<span class=\"hljs-string\">&#x27;description&#x27;</span>])\n        next_step = progress[<span class=\"hljs-string\">&#x27;current_step&#x27;</span>] + <span class=\"hljs-number\">1</span>\n        \n        <span class=\"hljs-comment\"># Continue from next step</span>\n        continue_from_step(task[<span class=\"hljs-string\">&#x27;id&#x27;</span>], next_step)</code></pre><h3>Step 4: Complete and archive</h3>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">complete_task</span>(<span class=\"hljs-params\">task_id, summary</span>):\n    <span class=\"hljs-string\">&quot;&quot;&quot;Mark task done with completion summary.&quot;&quot;&quot;</span>\n    update_task(task_id, \n        status=<span class=\"hljs-string\">&quot;done&quot;</span>,\n        description=<span class=\"hljs-string\">f&quot;COMPLETED. Summary: <span class=\"hljs-subst\">{summary}</span>&quot;</span>\n    )\n    <span class=\"hljs-comment\"># Also store as memory for long-term reference</span>\n    remember(\n        category=<span class=\"hljs-string\">&quot;project&quot;</span>,\n        key=<span class=\"hljs-string\">f&quot;completed_<span class=\"hljs-subst\">{task_id}</span>&quot;</span>,\n        content=<span class=\"hljs-string\">f&quot;Task: <span class=\"hljs-subst\">{task_id}</span>\\nSummary: <span class=\"hljs-subst\">{summary}</span>&quot;</span>,\n        tags=[<span class=\"hljs-string\">&quot;completed&quot;</span>, <span class=\"hljs-string\">&quot;task&quot;</span>],\n        priority=<span class=\"hljs-string\">&quot;normal&quot;</span>\n    )</code></pre><h2>Full Example: Deploy Workflow</h2>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-keyword\">class</span> <span class=\"hljs-title class_\">DeployWorkflow</span>:\n    <span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">__init__</span>(<span class=\"hljs-params\">self, version</span>):\n        <span class=\"hljs-variable language_\">self</span>.version = version\n        <span class=\"hljs-variable language_\">self</span>.task_id = <span class=\"hljs-literal\">None</span>\n        <span class=\"hljs-variable language_\">self</span>.steps = [\n            (<span class=\"hljs-string\">&quot;Bump version&quot;</span>, <span class=\"hljs-variable language_\">self</span>.bump_version),\n            (<span class=\"hljs-string\">&quot;Update changelog&quot;</span>, <span class=\"hljs-variable language_\">self</span>.update_changelog),\n            (<span class=\"hljs-string\">&quot;Commit and push&quot;</span>, <span class=\"hljs-variable language_\">self</span>.commit_push),\n            (<span class=\"hljs-string\">&quot;Wait for CI&quot;</span>, <span class=\"hljs-variable language_\">self</span>.wait_for_ci),\n            (<span class=\"hljs-string\">&quot;Verify deployment&quot;</span>, <span class=\"hljs-variable language_\">self</span>.verify_deployment),\n        ]\n    \n    <span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">run</span>(<span class=\"hljs-params\">self</span>):\n        <span class=\"hljs-comment\"># Check if already in progress</span>\n        existing = <span class=\"hljs-variable language_\">self</span>.find_existing()\n        <span class=\"hljs-keyword\">if</span> existing:\n            <span class=\"hljs-variable language_\">self</span>.task_id = existing[<span class=\"hljs-string\">&#x27;id&#x27;</span>]\n            start_step = <span class=\"hljs-variable language_\">self</span>.parse_progress(existing[<span class=\"hljs-string\">&#x27;description&#x27;</span>])\n        <span class=\"hljs-keyword\">else</span>:\n            <span class=\"hljs-variable language_\">self</span>.task_id = create_task(\n                title=<span class=\"hljs-string\">f&quot;Deploy Synapse v<span class=\"hljs-subst\">{self.version}</span>&quot;</span>,\n                description=<span class=\"hljs-variable language_\">self</span>.build_description(<span class=\"hljs-number\">0</span>),\n                priority=<span class=\"hljs-string\">&quot;high&quot;</span>\n            )\n            start_step = <span class=\"hljs-number\">0</span>\n        \n        <span class=\"hljs-comment\"># Execute remaining steps</span>\n        <span class=\"hljs-keyword\">for</span> i <span class=\"hljs-keyword\">in</span> <span class=\"hljs-built_in\">range</span>(start_step, <span class=\"hljs-built_in\">len</span>(<span class=\"hljs-variable language_\">self</span>.steps)):\n            step_name, step_fn = <span class=\"hljs-variable language_\">self</span>.steps[i]\n            <span class=\"hljs-variable language_\">self</span>.update_progress(i, <span class=\"hljs-string\">f&quot;Running: <span class=\"hljs-subst\">{step_name}</span>&quot;</span>)\n            <span class=\"hljs-keyword\">try</span>:\n                step_fn()\n            <span class=\"hljs-keyword\">except</span> Exception <span class=\"hljs-keyword\">as</span> e:\n                <span class=\"hljs-variable language_\">self</span>.update_progress(i, <span class=\"hljs-string\">f&quot;FAILED at <span class=\"hljs-subst\">{step_name}</span>: <span class=\"hljs-subst\">{e}</span>&quot;</span>)\n                <span class=\"hljs-keyword\">raise</span>\n        \n        <span class=\"hljs-variable language_\">self</span>.complete()\n    \n    <span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">update_progress</span>(<span class=\"hljs-params\">self, step_idx, status</span>):\n        update_task(<span class=\"hljs-variable language_\">self</span>.task_id,\n            status=<span class=\"hljs-string\">&quot;in_progress&quot;</span>,\n            description=<span class=\"hljs-string\">f&quot;Step <span class=\"hljs-subst\">{step_idx+<span class=\"hljs-number\">1</span>}</span>/<span class=\"hljs-subst\">{<span class=\"hljs-built_in\">len</span>(self.steps)}</span>: <span class=\"hljs-subst\">{status}</span>&quot;</span>\n        )\n    \n    <span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">complete</span>(<span class=\"hljs-params\">self</span>):\n        complete_task(<span class=\"hljs-variable language_\">self</span>.task_id, <span class=\"hljs-string\">f&quot;Deployed v<span class=\"hljs-subst\">{self.version}</span> successfully&quot;</span>)</code></pre><h2>Task Hierarchy</h2>\n<p>For complex work, use parent-child task relationships:</p>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-comment\"># Parent task</span>\nparent_id = create_task(<span class=\"hljs-string\">&quot;v1.6.0 Release&quot;</span>, priority=<span class=\"hljs-string\">&quot;high&quot;</span>)\n\n<span class=\"hljs-comment\"># Sub-tasks (linked via tags)</span>\ncreate_task(<span class=\"hljs-string\">&quot;Bump version&quot;</span>, \n    description=<span class=\"hljs-string\">f&quot;Parent: <span class=\"hljs-subst\">{parent_id}</span>&quot;</span>,\n    tags=[<span class=\"hljs-string\">&quot;v1.6.0&quot;</span>, <span class=\"hljs-string\">f&quot;parent-<span class=\"hljs-subst\">{parent_id}</span>&quot;</span>],\n    priority=<span class=\"hljs-string\">&quot;high&quot;</span>)\n\ncreate_task(<span class=\"hljs-string\">&quot;Update docs&quot;</span>,\n    description=<span class=\"hljs-string\">f&quot;Parent: <span class=\"hljs-subst\">{parent_id}</span>&quot;</span>,\n    tags=[<span class=\"hljs-string\">&quot;v1.6.0&quot;</span>, <span class=\"hljs-string\">f&quot;parent-<span class=\"hljs-subst\">{parent_id}</span>&quot;</span>],\n    priority=<span class=\"hljs-string\">&quot;normal&quot;</span>)</code></pre><p>Search for sub-tasks:</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer <span class=\"hljs-variable\">$KEY</span>&quot;</span> \\\n     <span class=\"hljs-string\">&quot;.../memory/search?q=parent-{parent_id}&amp;tag=v1.6.0&quot;</span></code></pre><h2>Status Workflow</h2>\n<pre><code class=\"hljs language-plaintext\">pending → in_progress → done\n                ↘ cancelled</code></pre><h3>Pending</h3>\n<p>Task created but not started. Use for planned work.</p>\n<h3>In Progress</h3>\n<p>Currently being worked on. <strong>Update description with progress.</strong></p>\n<h3>Done</h3>\n<p>Completed successfully. Description should include summary.</p>\n<h3>Cancelled</h3>\n<p>Abandoned. Description should include reason.</p>\n<h2>Best Practices</h2>\n<div class=\"callout callout-ok\"></div><h2>Common Patterns</h2>\n<h3>Pattern: Bug Fix Workflow</h3>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">fix_bug</span>(<span class=\"hljs-params\">bug_id, description</span>):\n    task_id = create_task(\n        title=<span class=\"hljs-string\">f&quot;Fix bug <span class=\"hljs-subst\">{bug_id}</span>&quot;</span>,\n        description=description,\n        priority=<span class=\"hljs-string\">&quot;high&quot;</span>\n    )\n    \n    <span class=\"hljs-comment\"># Investigate</span>\n    update_progress(task_id, <span class=\"hljs-string\">&quot;Investigating root cause&quot;</span>)\n    root_cause = investigate()\n    \n    <span class=\"hljs-comment\"># Fix</span>\n    update_progress(task_id, <span class=\"hljs-string\">f&quot;Applying fix: <span class=\"hljs-subst\">{root_cause}</span>&quot;</span>)\n    apply_fix(root_cause)\n    \n    <span class=\"hljs-comment\"># Test</span>\n    update_progress(task_id, <span class=\"hljs-string\">&quot;Testing fix&quot;</span>)\n    run_tests()\n    \n    <span class=\"hljs-comment\"># Deploy</span>\n    update_progress(task_id, <span class=\"hljs-string\">&quot;Deploying fix&quot;</span>)\n    deploy()\n    \n    complete_task(task_id, <span class=\"hljs-string\">f&quot;Fixed: <span class=\"hljs-subst\">{root_cause}</span>&quot;</span>)</code></pre><h3>Pattern: Research Workflow</h3>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">research_topic</span>(<span class=\"hljs-params\">topic</span>):\n    task_id = create_task(\n        title=<span class=\"hljs-string\">f&quot;Research: <span class=\"hljs-subst\">{topic}</span>&quot;</span>,\n        priority=<span class=\"hljs-string\">&quot;normal&quot;</span>\n    )\n    \n    update_progress(task_id, <span class=\"hljs-string\">&quot;Gathering sources&quot;</span>)\n    sources = gather_sources(topic)\n    \n    update_progress(task_id, <span class=\"hljs-string\">&quot;Analyzing&quot;</span>)\n    analysis = analyze(sources)\n    \n    update_progress(task_id, <span class=\"hljs-string\">&quot;Storing findings&quot;</span>)\n    remember(<span class=\"hljs-string\">&quot;fact&quot;</span>, <span class=\"hljs-string\">f&quot;research_<span class=\"hljs-subst\">{topic}</span>&quot;</span>, analysis,\n             tags=[<span class=\"hljs-string\">&quot;research&quot;</span>, topic], priority=<span class=\"hljs-string\">&quot;normal&quot;</span>)\n    \n    complete_task(task_id, <span class=\"hljs-string\">f&quot;Research complete: <span class=\"hljs-subst\">{<span class=\"hljs-built_in\">len</span>(sources)}</span> sources&quot;</span>)</code></pre><h2>Next Steps</h2>\n<ul>\n<li><a href=\"/docs/llm-cookbook/session-start-pattern\">Session Start Pattern</a></li>\n<li><a href=\"/docs/llm-cookbook/chat-polling-pattern\">Chat Polling Pattern</a></li>\n<li><a href=\"/docs/llm-cookbook/error-recovery\">Error Recovery</a></li>\n</ul>\n","urls":{"html":"/docs/llm-cookbook/task-driven-workflow","text":"/docs/llm-cookbook/task-driven-workflow?format=text","json":"/docs/llm-cookbook/task-driven-workflow?format=json","llm":"/docs/llm-cookbook/task-driven-workflow?format=llm"},"translations_available":["en","zh","hi","es","fr","ar","pt","ru","ja","de","it","ko","nl","pl","tr","sv","vi","th","id","uk"]}