# Task Server

The Task Server is a distributed task processing component in Canso's AI Agentic System that empowers AI agents the ability with to execute **long running** or **computationally intensive** tasks asynchronously.

The diagram below illustrates how the task server integrates with your AI Agent. ![Task Server Functionality](https://4002575704-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcE4BqP2R5KBg2It3L34D%2Fuploads%2Fgit-blob-586b282df5c745f97b964b2207fcf81a873784a0%2Ftask-server.png?alt=media)

The [tools](https://docs.canso.ai/ai-agents/toolkit) provided by Canso integrate seamlessly with the Task Server. All you need to do is set up the [Broker](https://docs.canso.ai/ai-agents/concepts/broker) and the Task Server, which involves executing a simple CLI command, and add the Canso tools to your AI Agent.

## Core Design Philosophy

The Task Server implements a fundamental architectural principle: the separation between agent decision-making and task execution. This separation provides several key advantages:

1. **Clean Separation of Concerns**
   * Agents focus purely on decision-making and workflow orchestration
   * Task execution is handled independently by specialized workers
   * Clear boundaries between thinking (agents) and doing (tasks)
2. **Scalability and Resource Optimization**
   * Agent processes remain lightweight and responsive
   * Compute-intensive tasks are offloaded to appropriate workers
   * Independent scaling of agent instances and task workers
3. **Enhanced Reliability**
   * Task failures don't impact agent stability
   * Retry mechanisms are handled separately from agent logic
   * Better error isolation and recovery

This architecture enables AI agents to orchestrate complex workflows while maintaining responsiveness and reliability, making it ideal for production deployments.

### Setting up the Task Server

To set up the task server, define a YAML file:

```yaml
task_server:
  type: celery
  name: task_server
  replicas: 4
  concurrency_per_replica: 1
  broker_resource_name: redis
```

The table below explains the configuration attribues:

| Attribute                 | Description                    | Example             |
| ------------------------- | ------------------------------ | ------------------- |
| `type`                    | Type of task server being used | `celery`            |
| `name`                    | Unique name of the task server | `agent-task-server` |
| `replicas`                | Number of worker replicas      | `4`                 |
| `concurrency_per_replica` | Tasks per worker               | `1`                 |
| `broker_resource_name`    | Associated broker instance     | `redis`             |

**Note**: Before setting up a task server, setting up a Broker is a prerequisite. See [Broker](https://docs.canso.ai/ai-agents/concepts/broker) for more details.

Run the `gru` command to to set up the task server:

```bash
gru component setup --cluster-name <cluster-name> --config-file config.yaml
```

## Tool Tips

* See [Broker](https://docs.canso.ai/ai-agents/concepts/broker) ➡️
* Learn about [Checkpoint DB](https://docs.canso.ai/ai-agents/concepts/db) ➡️
* Explore [Memory](https://docs.canso.ai/ai-agents/concepts/conversations) ➡
