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.
Quick Start
- 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 - 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).
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
Configuration Levels
// 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
ExecutionConfigComplete 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.