Skip to main content

Overview

mcp-agent provides two execution engines that determine how agent workflows are executed and managed. Each engine offers different capabilities for reliability, persistence, and deployment scenarios.

Execution Engines

asyncio Engine

The asyncio engine runs workflows in-memory using Python’s native async/await capabilities. Characteristics:
  • In-memory execution
  • No external dependencies
  • Fast startup and iteration
  • Best for development and simple deployments
  • State lost on process restart
Configuration:
Use cases:
  • Local development
  • Quick prototyping
  • Stateless operations
  • Single-node deployments

Temporal Engine

The Temporal engine provides durable workflow execution with automatic state persistence. Characteristics:
  • Durable execution across restarts
  • Automatic retry with exponential backoff
  • Workflow history and replay
  • Distributed execution support
  • Requires Temporal server
Configuration:
Use cases:
  • Production deployments
  • Long-running workflows
  • Critical operations requiring reliability
  • Multi-node deployments
  • Workflows requiring pause/resume
📌 Example: The Temporal workflow gallery showcases orchestrator, router, and evaluator/optimizer patterns running on this engine.

Executors

Executors are the runtime components that actually execute workflows within an engine.

AsyncioExecutor

Handles workflow execution for the asyncio engine:
Features:
  • Direct Python function execution
  • Native async/await support
  • Minimal overhead
See it in action in the basic workflows examples where tasks run entirely in-process.

TemporalExecutor

Manages workflow execution for the Temporal engine:
Features:
  • Workflow versioning
  • Activity retries
  • Distributed execution
  • Workflow queries and signals
The examples/oauth/pre_authorize project combines this executor with OAuth-aware workflows.

Choosing an Execution Engine

Development Phase

Use asyncio engine during development:
  • Fast iteration cycles
  • No infrastructure requirements
  • Immediate feedback
  • Simple debugging

Production Phase

Consider Temporal engine for production:
  • Workflow reliability
  • Automatic failure handling
  • Audit trail via workflow history
  • Horizontal scaling

Execution Context

Both engines provide an execution context to workflows:

Engine-Specific Features

asyncio Features

  • Direct execution: Workflows run as standard Python functions
  • Memory state: State maintained in process memory
  • Simple cancellation: Standard asyncio cancellation

Temporal Features

  • Workflow replay: Deterministic replay from history
  • Signals: Send data to running workflows
  • Queries: Query workflow state without affecting execution
  • Child workflows: Spawn and manage child workflow instances
  • Timers: Durable sleep and timeouts
  • Activities: Retryable units of work

Migration Between Engines

Workflows written for mcp-agent can run on either engine without modification:

Performance Considerations

asyncio Engine

  • Latency: Microseconds for workflow start
  • Throughput: Limited by single process
  • Memory: All state in RAM
  • Reliability: No persistence

Temporal Engine

  • Latency: Milliseconds for workflow start
  • Throughput: Horizontally scalable
  • Memory: State persisted to database
  • Reliability: Survives crashes and restarts

Configuration Examples

Basic asyncio Setup

Production Temporal Setup

Accessing the executor in an application

MCPApp exposes the active executor and engine selection:
You typically call high-level helpers (workflow.execute(), executor.start_workflow) rather than invoking executor methods directly, but the property is available when you need advanced control or diagnostics.

Next Steps