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

# Async Task Handling

> Learn how to handle asynchronous tasks with Xpander SDK using the @on_task decorator for background processing

<AccordionGroup>
  <Accordion title="Prerequisites">
    ### Virtual Environment Setup

    ```bash setup.sh theme={"dark"}
    python3 -m venv .venv
    source .venv/bin/activate
    pip install "xpander-sdk[agno]"
    ```

    ### Environment Setup

    The `.env` file is created when you download your agent code:

    ```bash theme={"dark"}
    xpander init
    ```

    This downloads your agent code from the platform with the `.env` file pre-configured with your keys.
  </Accordion>
</AccordionGroup>

```python async_task_example.py theme={"dark"}
from dotenv import load_dotenv
load_dotenv()

from xpander_sdk import Task, Backend, on_task
from agno.agent import Agent

@on_task
async def task_handler(task: Task):
    backend = Backend()
    agno_args = await backend.aget_args(task=task)
    agno_agent = Agent(**agno_args)
    
    # Get files and images for comprehensive processing
    files = task.get_files()    # PDF files as Agno File objects
    images = task.get_images()  # Image files as Agno Image objects
    
    # Process task asynchronously with file support
    result = await agno_agent.arun(
        input=task.to_message(),  # Includes text + file content
        files=files,              # PDF files
        images=images            # Image files
    )
    task.result = result.content
    return task
```

This example shows non-blocking task processing where multiple tasks can be handled concurrently without blocking other operations. It uses asynchronous backend initialization with `aget_args()` for optimal resource utilization, automatic file categorization and handling for Agno integration, and task-to-message conversion with proper result handling.

## Production Deployment

For creating and deploying agents to production, see the [Setup and Deployment Guide](/Examples/00-setup-deployment).
