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 — timeouts stay here.

Diagram

Execution Control

Sequential

Parallel

Retry

📋 Task

Mode?

➡️ One by One

⚡ All at Once

🔄 Auto Retry

Quick Start

  1. Simple Usage
    typescript
    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
    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
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();

User Interaction Flow

Diagram
SystemAgentUserSystemAgentUseralt[Timeout]“Process this”ExecuteTimeoutRetryCompleteResult

Configuration Levels

typescript
// 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

OptionDefaultDescription
timeout60000Max time in ms
retries0Retry attempts
retryDelay1000Delay between retries
maxConcurrent5Parallel limit

API Reference

ExecutionConfig

Complete configuration options


Best Practices

Set reasonable timeouts

Most tasks complete in 30-60 seconds.

Use retries for flaky operations

Network calls and external APIs benefit from retries.

Limit concurrency

Too many parallel tasks can overwhelm resources.


Related