# Agent Tasks



Acontext extracts tasks from agent conversations based on **user requirements**. Each distinct request the user makes becomes a separate, trackable task — the agent's plan steps are tracked as progress within that task.

## Quick Start [#quick-start]

<CodeGroup>
  ```python title="Python"
  import os
  from acontext import AcontextClient

  client = AcontextClient(api_key=os.getenv("ACONTEXT_API_KEY"))
  session = client.sessions.create()

  # Store conversation — each user request becomes a separate task
  messages = [
      {"role": "user", "content": "Research iPhone 15 specs and summarize the key features"},
      {"role": "assistant", "content": "Here are the key iPhone 15 specs:\n- A16 chip, 48MP camera, USB-C..."},
      {"role": "user", "content": "Now create a comparison table with iPhone 14"},
      {"role": "assistant", "content": "| Feature | iPhone 14 | iPhone 15 |\n|---|---|---|\n| Chip | A15 | A16 |..."},
  ]
  for msg in messages:
      client.sessions.store_message(session_id=session.id, blob=msg, format="openai")

  # Wait for extraction
  client.sessions.flush(session.id)

  # Get tasks — one per user request
  tasks = client.sessions.get_tasks(session.id)
  for task in tasks.items:
      print(f"Task #{task.order}: {task.data.task_description} | Status: {task.status}")
  ```

  ```typescript title="TypeScript"
  import { AcontextClient } from '@acontext/acontext';

  const client = new AcontextClient({
      apiKey: process.env.ACONTEXT_API_KEY,
  });
  const session = await client.sessions.create();

  // Store conversation — each user request becomes a separate task
  const messages = [
      { role: "user", content: "Research iPhone 15 specs and summarize the key features" },
      { role: "assistant", content: "Here are the key iPhone 15 specs:\n- A16 chip, 48MP camera, USB-C..." },
      { role: "user", content: "Now create a comparison table with iPhone 14" },
      { role: "assistant", content: "| Feature | iPhone 14 | iPhone 15 |\n|---|---|---|\n| Chip | A15 | A16 |..." },
  ];
  for (const msg of messages) {
      await client.sessions.storeMessage(session.id, msg, { format: "openai" });
  }

  // Wait for extraction
  await client.sessions.flush(session.id);

  // Get tasks — one per user request
  const tasks = await client.sessions.getTasks(session.id);
  for (const task of tasks.items) {
      console.log(`Task #${task.order}: ${task.data.task_description} | Status: ${task.status}`);
  }
  ```
</CodeGroup>

## Task Data [#task-data]

Each task contains:

* `task_description`: What the task is
* `status`: `pending`, `running`, `success`, or `failed`
* `progresses`: Agent's progress updates
* `user_preferences`: User requirements mentioned

<CodeGroup>
  ```python title="Python"
  for task in tasks.items:
      print(f"Task: {task.data.task_description}")
      
      if task.data.progresses:
          for p in task.data.progresses:
              print(f"  Progress: {p}")
      
      if task.data.user_preferences:
          for pref in task.data.user_preferences:
              print(f"  Preference: {pref}")
  ```

  ```typescript title="TypeScript"
  for (const task of tasks.items) {
      console.log(`Task: ${task.data.task_description}`);
      
      if (task.data.progresses) {
          for (const p of task.data.progresses) {
              console.log(`  Progress: ${p}`);
          }
      }
      
      if (task.data.user_preferences) {
          for (const pref of task.data.user_preferences) {
              console.log(`  Preference: ${pref}`);
          }
      }
  }
  ```
</CodeGroup>

## View in Dashboard [#view-in-dashboard]

<Frame caption="Task viewer showing extracted tasks">
  <img src="/images/dashboard/session_task_viewer.png" alt="Task list view" />
</Frame>

<Frame caption="Task details with progress and preferences">
  <img src="/images/dashboard/task_viewer.png" alt="Task detail view" />
</Frame>

## Next Steps [#next-steps]

<CardGroup cols="3">
  <Card title="Buffer" icon="clock" href="/observe/buffer">
    Understand task extraction timing
  </Card>

  <Card title="Dashboard" icon="chart-simple" href="/observe/dashboard">
    View all agent data
  </Card>

  <Card title="Skill Memory" icon="brain" href="/learn/quick">
    Build skills from agent sessions
  </Card>
</CardGroup>
