> ## Documentation Index
> Fetch the complete documentation index at: https://docs.upsonic.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Basic Task Example

> Step-by-step guide to creating tasks in the Upsonic framework

Tasks in Upsonic are created directly in code using the `Task` class constructor. Each task can be customized with specific tools, response formats, caching options, and validation rules to meet your exact requirements.

## Basic Task Creation

```python theme={null}
from upsonic import Agent, Task

# Simple task with just a description
agent = Agent(model="anthropic/claude-sonnet-4-5")
task = Task(description="What is the capital of France?")

# Execute task
agent.print_do(task)
```

## Task with Tools

```python theme={null}
from upsonic import Agent, Task
from upsonic.tools import tool

# Create a simple tool
@tool
def calculator(operation: str, a: float, b: float) -> str:
    """Perform basic mathematical operations."""
    if operation == "add":
        return f"Result: {a + b}"
    elif operation == "multiply":
        return f"Result: {a * b}"
    return "Invalid operation"

# Create agent and task with tools
agent = Agent(model="anthropic/claude-sonnet-4-5")
task = Task(
    description="Calculate 10 + 5 using the calculator tool",
    tools=[calculator]
)

# Execute task
agent.print_do(task)
```

## Task with Response Format

```python theme={null}
from upsonic import Agent, Task
from pydantic import BaseModel

class AnalysisResult(BaseModel):
    summary: str
    confidence: float
    recommendations: list[str]

# Create agent and task with structured response
agent = Agent(model="anthropic/claude-sonnet-4-5")
task = Task(
    description="Analyze the current state of renewable energy and provide structured results",
    response_format=AnalysisResult
)

# Execute task
agent.print_do(task)
```

## Best Practices

* **Start Simple**: Begin with basic tasks and gradually add complexity
* **Clear Descriptions**: Write descriptive task descriptions that clearly state the objective
* **Tool Selection**: Choose appropriate tools for the task requirements
* **Error Handling**: Use guardrails for tasks that require specific output validation
* **Caching Strategy**: Enable caching for tasks that might be repeated with similar inputs
