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

# Operations Overview

> Atomic building blocks of Conductor. Each operation does one thing well.

Agents use operations to do work. Ensembles orchestrate agents. Operations are where the rubber meets the road.

## Core Operations

### Compute Operations

Execute logic and transform data.

<CardGroup cols={2}>
  <Card title="think" icon="brain" href="/conductor/operations/think">
    AI reasoning with LLMs and ML models
  </Card>

  <Card title="code" icon="code" href="/conductor/operations/code">
    JavaScript/TypeScript execution
  </Card>

  <Card title="transform" icon="shuffle" href="/conductor/operations/transform">
    Declarative data transformations
  </Card>

  <Card title="convert" icon="arrows-rotate" href="/conductor/operations/convert">
    Document format conversion (HTML, Markdown, DOCX)
  </Card>
</CardGroup>

### Data Operations

Access and manipulate data stores.

<CardGroup cols={2}>
  <Card title="storage" icon="box" href="/conductor/operations/storage">
    KV, R2, Cache - Simple storage
  </Card>

  <Card title="data" icon="database" href="/conductor/operations/data">
    D1, Vectorize, Hyperdrive - Databases
  </Card>
</CardGroup>

### Communication Operations

Send messages and make requests.

<CardGroup cols={3}>
  <Card title="http" icon="globe" href="/conductor/operations/http">
    HTTP requests to APIs
  </Card>

  <Card title="email" icon="envelope" href="/conductor/operations/email">
    Send emails
  </Card>

  <Card title="sms" icon="message" href="/conductor/operations/sms">
    Send SMS messages
  </Card>
</CardGroup>

### Async Operations

Background processing and message queues.

<Card title="queue" icon="list" href="/conductor/operations/queue">
  Cloudflare Queue message processing
</Card>

### Presentation Operations

Render content for users.

<CardGroup cols={2}>
  <Card title="html" icon="window" href="/conductor/operations/html">
    Render HTML templates
  </Card>

  <Card title="pdf" icon="file-pdf" href="/conductor/operations/pdf">
    Generate PDF documents
  </Card>

  <Card title="form" icon="square-check" href="/conductor/operations/form">
    Generate validated forms
  </Card>

  <Card title="chart" icon="chart-bar" href="/conductor/operations/chart">
    Data visualization (bar, line, pie, etc.)
  </Card>
</CardGroup>

<Note>
  **Looking for API documentation?** The `docs/` directory is now a first-class component in Conductor.
  See [Building Documentation](/conductor/building/documentation) for details.
</Note>

### HTTP Context Operations

Manage HTTP-specific concerns.

<Card title="cookies" icon="cookie" href="/conductor/operations/cookies">
  Cookie management with consent awareness
</Card>

### Analytics Operations

Track metrics and emit events.

<Card title="telemetry" icon="chart-line" href="/conductor/operations/telemetry">
  Emit events to Cloudflare Analytics Engine
</Card>

### Extension Operations

Extend functionality with external tools.

<Card title="tools" icon="wrench" href="/conductor/operations/tools">
  MCP tools and custom skills
</Card>

## Quick Reference

| Operation     | Use Case                          | Example                                    |
| ------------- | --------------------------------- | ------------------------------------------ |
| **think**     | AI reasoning, text generation     | Analyze sentiment, generate content        |
| **code**      | Complex logic, calculations       | Calculate totals, custom algorithms        |
| **transform** | Declarative data shaping          | Pick/omit fields, merge data, mock data    |
| **convert**   | Document format conversion        | HTML→Markdown, DOCX extraction             |
| **chart**     | Data visualization                | Bar, line, pie charts as SVG or image URLs |
| **storage**   | Simple storage, caching           | Cache in KV, store files in R2             |
| **data**      | Database queries, structured data | Query D1, vector search in Vectorize       |
| **http**      | API calls, web requests           | Fetch external data                        |
| **email**     | Send notifications                | Order confirmations, alerts                |
| **sms**       | Send text messages                | 2FA codes, alerts                          |
| **html**      | Render web pages                  | Dashboard, reports                         |
| **pdf**       | Generate documents                | Invoices, reports                          |
| **form**      | Generate validated forms          | User registration, surveys                 |
| **queue**     | Message queue processing          | Background jobs, event processing          |
| **cookies**   | Cookie management                 | Sessions, tracking, consent                |
| **telemetry** | Analytics events                  | Track metrics, billing, costs              |
| **tools**     | External tool integration         | Web search, file operations                |

## Common Configuration

All operations support:

```yaml theme={null}
operations:
  - name: my-operation
    operation: think  # Operation type
    config:
      # Operation-specific config
    condition: ${some.condition}  # Optional: when to run
    cache:
      ttl: 3600  # Optional: cache duration (seconds)
      key: custom-key  # Optional: cache key
    retry:
      maxAttempts: 3  # Optional: retry count
      backoff: exponential  # Optional: exponential or linear
      initialDelay: 1000  # Optional: ms before first retry
      maxDelay: 30000  # Optional: max delay between retries
    timeout: 30000  # Optional: timeout in ms
```

## Output Access

Reference operation outputs:

```yaml theme={null}
${operation-name.output}          # Full output
${operation-name.output.field}    # Specific field
${operation-name.executed}        # true if ran
${operation-name.failed}          # true if failed
${operation-name.cached}          # true if from cache
${operation-name.duration}        # Execution time (ms)
${operation-name.retry_count}     # Number of retries
```

## Performance Features

### Automatic Parallelization

Operations without dependencies run in parallel:

```yaml theme={null}
operations:
  # These 3 run in parallel
  - name: fetch-a
    operation: http
    config:
      url: https://api-a.com

  - name: fetch-b
    operation: http
    config:
      url: https://api-b.com

  - name: fetch-c
    operation: http
    config:
      url: https://api-c.com

  # This waits for all 3
  - name: merge
    operation: code
    config:
      script: scripts/merge-fetch-results
    input:
      fetchA: ${fetch-a.output}
      fetchB: ${fetch-b.output}
      fetchC: ${fetch-c.output}
```

```typescript theme={null}
// scripts/merge-fetch-results.ts
import type { AgentExecutionContext } from '@ensemble-edge/conductor'

export default function mergeFetchResults(context: AgentExecutionContext) {
  const { fetchA, fetchB, fetchC } = context.input
  return {
    a: fetchA,
    b: fetchB,
    c: fetchC
  }
}
```

### Built-in Caching

Cache expensive operations:

```yaml theme={null}
operations:
  - name: expensive-ai
    operation: think
    config:
      provider: openai
      model: gpt-4o
      prompt: ${input.text}
    cache:
      ttl: 3600  # Cache for 1 hour
      key: ai-${input.text}
```

### Automatic Retry

Retry failed operations:

```yaml theme={null}
operations:
  - name: flaky-api
    operation: http
    config:
      url: https://api.example.com
    retry:
      maxAttempts: 3
      backoff: exponential
      initialDelay: 1000
```

## Error Handling

### Conditional Execution

Skip operations on failure:

```yaml theme={null}
operations:
  - name: try-operation
    operation: http
    config:
      url: https://api.example.com

  - name: fallback
    condition: ${try-operation.failed}
    operation: http
    config:
      url: https://backup-api.com

outputs:
  data: ${try-operation.output || fallback.output}
```

### Error Context

Access error details:

```yaml theme={null}
operations:
  - name: risky-op
    operation: http
    config:
      url: https://api.example.com

  - name: log-error
    condition: ${risky-op.failed}
    operation: data
    config:
      backend: d1
      binding: DB
      operation: execute
      sql: INSERT INTO errors (error, timestamp) VALUES (?, ?)
      params:
        - ${risky-op.error}
        - ${Date.now()}
```

## Best Practices

1. **Use the Right Operation** - Each is optimized for its use case
2. **Cache Aggressively** - Cache expensive operations
3. **Handle Failures** - Use conditions and fallbacks
4. **Parallel by Default** - Don't create unnecessary dependencies
5. **Set Timeouts** - Prevent hanging operations
6. **Monitor Performance** - Track operation durations
7. **Test Thoroughly** - Unit test each operation
8. **Version Components** - Use Edgit for prompts/configs

## Operation Comparison

### When to Use What

**think vs code vs transform vs convert**:

* Use `think` for AI reasoning, natural language
* Use `code` for complex logic, conditionals, loops
* Use `transform` for simple data shaping (pick/omit/merge)
* Use `convert` for format conversion (HTML↔Markdown, DOCX)

**storage vs data**:

* Use `storage` (KV) for caching, simple key-value
* Use `data` (D1) for structured data, complex queries

**http vs tools**:

* Use `http` for direct API calls
* Use `tools` for MCP-compatible tools

**email vs sms**:

* Use `email` for rich content, attachments
* Use `sms` for urgent, short messages

**html vs page**:

* Use `html` for simple rendering
* Use `page` for full-stack, interactive UIs

## Next Steps

<CardGroup cols={2}>
  <Card title="think" icon="brain" href="/conductor/operations/think">
    AI reasoning operation
  </Card>

  <Card title="storage" icon="box" href="/conductor/operations/storage">
    Simple storage operation
  </Card>

  <Card title="data" icon="database" href="/conductor/operations/data">
    Database operation
  </Card>

  <Card title="http" icon="globe" href="/conductor/operations/http">
    HTTP request operation
  </Card>

  <Card title="All Operations" icon="bolt" href="/conductor/core-concepts/operations">
    Core concepts guide
  </Card>
</CardGroup>
