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

# Execution

> Control how agents run

Agents can run with different execution settings - timeouts, retries, and parallel processing.

For user-driven stops (a Stop button), see [Cancellation](https://praison.ai/docs/js/cancellation.md) — timeouts stay here.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Execution Control"
        A[📋 Task] --> B{Mode?}
        B -->|Sequential| C[➡️ One by One]
        B -->|Parallel| D[⚡ All at Once]
        B -->|Retry| E[🔄 Auto Retry]
    end

    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef tool fill:#189AB4,stroke:#7C90A0,color:#fff
    class B agent
    class A,C,D,E tool
    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff

```

## Quick Start

**1. Simple Usage**

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent } from 'praisonai';

const agent = new Agent({
  instructions: 'You complete tasks',
  timeout: 30000  // 30 seconds max
});

await agent.chat('Analyze this document');
// Times out after 30 seconds if not complete
```

**2. With Configuration**

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
const agent = new Agent({
  timeout: 30000,
  retries: 3,
  retryDelay: 1000
});
```

***

## Running a task with `execute(task?, context?)`

`execute()` runs one task on an agent and matches Python's `Agent.execute(task, context=None)`.

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent } from 'praisonai';

const agent = new Agent({ instructions: 'You complete tasks' });

// A string runs as the task
await agent.execute('Summarise the Q3 revenue report.');

// Chain a prior result — substituted for {{previous}} in the prompt
await agent.execute('Improve this draft: {{previous}}', 'the rough draft');

// No task → runs the agent's own instructions
await agent.execute();
```

> [!WARNING]
>
> **Breaking change (v2).** Before this release, a single string argument was the previous result and the agent always ran its own `instructions`. That chaining call is now written `execute(undefined, previousResult)`. See [Agent → execute](https://praison.ai/docs/js/agent.md#execute-task-context) for the full resolution order.

***

## User Interaction Flow

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant System
    
    User->>Agent: "Process this"
    Agent->>System: Execute
    alt Timeout
        System-->>Agent: Timeout
        Agent->>System: Retry
    end
    System-->>Agent: Complete
    Agent-->>User: Result
```

***

## Configuration Levels

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
// Level 1: Number - Simple timeout
const agent = new Agent({
  timeout: 30000
});

// Level 2: Dict - Multiple options
const agent = new Agent({
  execution: {
    timeout: 30000,
    retries: 3,
    retryDelay: 1000
  }
});

// Level 3: Instance - Full control
const agent = new Agent({
  execution: {
    timeout: 60000,
    retries: 5,
    retryDelay: 2000,
    maxConcurrent: 3,
    onRetry: (attempt) => console.log(`Retry ${attempt}`)
  }
});
```

***

## Execution Options

| Option | Default | Description |
| - | - | - |
| `timeout` | `60000` | Max time in ms |
| `retries` | `0` | Retry attempts |
| `retryDelay` | `1000` | Delay between retries |
| `maxConcurrent` | `5` | Parallel limit |

***

## API Reference

> [card] [ExecutionConfig](https://praison.ai/docs/sdk/reference/typescript/classes/ExecutionConfig.md)
>
> Complete configuration options

***

## Best Practices

> [accordion] Set reasonable timeouts
>
> Most tasks complete in 30-60 seconds.

> [accordion] Use retries for flaky operations
>
> Network calls and external APIs benefit from retries.

> [accordion] Limit concurrency
>
> Too many parallel tasks can overwhelm resources.

***

## Related

> [card] [Workflows](https://praison.ai/docs/js/workflows.md)
>
> Multi-step workflows

> [card] [Failover](https://praison.ai/docs/js/failover.md)
>
> Automatic backup


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.