> ## 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.

# Agent Classes

> Classes for creating and executing agents programmatically

## Agent

Execute individual agents with the Agent class.

### Constructor

```typescript theme={null}
import { Agent } from '@ensemble/conductor';

const agent = new Agent(name: string, conductor: Conductor);
```

### Methods

#### execute()

Execute the agent with inputs.

```typescript theme={null}
async execute(inputs: Record<string, any>): Promise<AgentResult>
```

**Example**:

```typescript theme={null}
const agent = new Agent('company-enricher', conductor);

const result = await agent.execute({
  company_name: 'Anthropic'
});

console.log('Company data:', result.output);
```

#### Result Type

```typescript theme={null}
interface AgentResult {
  output: any;
  duration: number;
  cached: boolean;
  operations: OperationResult[];
}

interface OperationResult {
  name: string;
  operation: string;
  output: any;
  duration: number;
  cached: boolean;
  error?: OperationError;
}
```

## AgentBuilder

Programmatically build agents without YAML.

### Constructor

```typescript theme={null}
import { AgentBuilder } from '@ensemble/conductor';

const builder = new AgentBuilder();
```

### Methods

#### name()

Set agent name.

```typescript theme={null}
name(name: string): AgentBuilder
```

#### description()

Set agent description.

```typescript theme={null}
description(desc: string): AgentBuilder
```

#### input()

Define an input.

```typescript theme={null}
input(name: string, schema: InputSchema): AgentBuilder
```

**Example**:

```typescript theme={null}
builder.input('company_name', {
  type: 'string',
  required: true,
  description: 'Company name to enrich'
});
```

#### operation()

Add an operation.

```typescript theme={null}
operation(
  name: string,
  operation: string,
  config: Record<string, any>
): AgentBuilder
```

**Example**:

```typescript theme={null}
builder.operation('search', 'http', {
  url: 'https://api.example.com/search',
  method: 'GET',
  params: {
    q: '${input.company_name}'
  }
});
```

#### output()

Define output mapping.

```typescript theme={null}
output(name: string, expression: string): AgentBuilder
```

#### cache()

Configure caching.

```typescript theme={null}
cache(config: CacheConfig): AgentBuilder
```

#### build()

Build the agent.

```typescript theme={null}
build(): Agent
```

### Complete Example

```typescript theme={null}
const agent = new AgentBuilder()
  .name('company-enricher')
  .description('Enrich company data')
  .input('company_name', {
    type: 'string',
    required: true
  })
  .operation('search', 'http', {
    url: 'https://api.duckduckgo.com/',
    params: {
      q: '${input.company_name}'
    }
  })
  .operation('scrape', 'http', {
    url: '${search.output.results[0].url}'
  })
  .operation('extract', 'think', {
    provider: 'openai',
    model: 'gpt-4o-mini',
    prompt: 'Extract company info from: ${scrape.output.body}'
  })
  .output('company_data', '${extract.output}')
  .cache({
    ttl: 86400,
    key: 'enrich-${input.company_name}'
  })
  .build();

const result = await agent.execute({
  company_name: 'Anthropic'
});
```

## createAgent()

Factory function for creating agents.

```typescript theme={null}
import { createAgent } from '@ensemble/conductor/sdk';

const agent = createAgent({
  name: 'my-agent',
  operations: [
    {
      name: 'step1',
      operation: 'think',
      config: {
        provider: 'openai',
        model: 'gpt-4o',
        prompt: 'Process: ${input.data}'
      }
    }
  ],
  outputs: {
    result: '${step1.output}'
  }
});
```

## Operation Helpers

Helper functions for common operation patterns.

### thinkOperation()

```typescript theme={null}
import { thinkOperation } from '@ensemble/conductor/sdk';

const op = thinkOperation({
  name: 'analyze',
  provider: 'openai',
  model: 'gpt-4o',
  prompt: 'Analyze: ${input.text}'
});
```

### httpOperation()

```typescript theme={null}
import { httpOperation } from '@ensemble/conductor/sdk';

const op = httpOperation({
  name: 'fetch',
  url: 'https://api.example.com/data',
  method: 'POST',
  body: {
    query: '${input.query}'
  }
});
```

### storageOperation()

```typescript theme={null}
import { storageOperation } from '@ensemble/conductor/sdk';

const op = storageOperation({
  name: 'query',
  type: 'd1',
  query: 'SELECT * FROM users WHERE id = ?',
  params: ['${input.user_id}']
});
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Core Classes" icon="cube" href="/api/typescript/core-classes">
    Conductor class
  </Card>

  <Card title="SDK Methods" icon="code" href="/api/typescript/sdk-methods">
    All SDK methods
  </Card>

  <Card title="Creating Agents" icon="hammer" href="/conductor/building/creating-agents">
    Agent guide
  </Card>

  <Card title="Operations" icon="bolt" href="/conductor/operations/overview">
    Operation reference
  </Card>
</CardGroup>
