Skip to main content

Usage

DeepAgent provides automatic todo tracking. Todos follow a strict lifecycle: pendingin_progresscompleted.

Todo Lifecycle

  1. Created as "pending" or "in_progress"
  2. Marked "in_progress" before starting work
  3. Marked "completed" immediately after finishing
  4. Agent continues until ALL todos are "completed"

Example

import asyncio
from upsonic.agent.deepagent import DeepAgent
from upsonic import Task

async def main():
    agent = DeepAgent(model="openai/gpt-4o")
    
    task = Task(description="""
    Research Python frameworks, compare their features, and write a comparison report.
    
    Execute all tasks and ensure everything is completed.
    Save findings to /research/frameworks.txt and report to /reports/comparison.txt
    """)
    
    result = await agent.do_async(task)
    
    # Get current todos
    todos = agent.get_current_plan()
    
    print(f"\nTodo Status:")
    completed = sum(1 for t in todos if t['status'] == 'completed')
    total = len(todos)
    print(f"  Completed: {completed}/{total}")
    
    for todo in todos:
        status_icon = "✅" if todo['status'] == 'completed' else "⏳"
        print(f"  {status_icon} [{todo['status']}] {todo['content']}")

asyncio.run(main())

Programmatic Access

import asyncio
from upsonic.agent.deepagent import DeepAgent
from upsonic import Task

async def main():
    agent = DeepAgent(model="openai/gpt-4o")
    
    task = Task(description="Create a 5-step plan and execute it")
    result = await agent.do_async(task)
    
    # Get current todos
    todos = agent.get_current_plan()
    
    # Access todo details
    for todo in todos:
        print(f"ID: {todo['id']}")
        print(f"Content: {todo['content']}")
        print(f"Status: {todo['status']}")
        print()

asyncio.run(main())

Key Points

  • Todos are automatically tracked per task
  • Agent updates todos after each completion
  • Use get_current_plan() to monitor progress
  • All todos must be completed before task finishes