<!--
 ⚠️  AUTO-GENERATED FILE - DO NOT EDIT MANUALLY
 This file is automatically generated by scripts/docs-generator.js
 To make changes, edit the source TypeScript files or update the generator script
-->

[agents](../../) / [Exports](../modules) / AbstractAIProvider

# Class: AbstractAIProvider\<TConfig\>

Base AI provider implementation with proper type constraints
All AI providers should extend this class

========================================
CRITICAL IMPLEMENTATION GUIDELINES
========================================

ALL AI PROVIDER IMPLEMENTATIONS (OpenAI, Anthropic, Google, etc.) MUST:

1. EXTEND THIS CLASS:

   ```typescript
   export class OpenAIProvider extends AbstractAIProvider {
       override readonly name = 'openai';
       override readonly version = '1.0.0';
   ```

2. USE IMPORTS FROM @robota-sdk/agent-core:

   ```typescript
   import { AbstractAIProvider } from '@robota-sdk/agent-core';
   import type {
     TUniversalMessage,
     ChatOptions,
     IToolCall,
     ToolSchema,
     AssistantMessage,
   } from '@robota-sdk/agent-core';
   ```

3. USE OVERRIDE KEYWORD FOR ALL INHERITED METHODS:
   - override async chat(...)
   - override async \*chatStream(...)
   - override supportsTools()
   - override validateConfig()
   - override async dispose()

4. DO NOT REDEFINE TYPES THAT EXIST IN @robota-sdk/agent-core:
   - TUniversalMessage
   - ChatOptions
   - IToolCall
   - ToolSchema
   - AssistantMessage
   - SystemMessage
   - UserMessage
   - ToolMessage

5. HANDLE MESSAGE CONTENT PROPERLY:
   - For tool calls: content should be null (not empty string)
   - For regular messages: content can be string or null
   - Always preserve null values from API responses

6. CALL SUPER() IN CONSTRUCTOR:
   ```typescript
   constructor(options: IProviderOptions) {
       super();
       // provider-specific initialization
   }
   ```

This ensures ExecutionService can properly identify providers
and prevents type conflicts across the codebase.

========================================

**`Template`**

Message type (defaults to TUniversalMessage for backward compatibility)

**`Template`**

Response type (defaults to TUniversalMessage for backward compatibility)

## Type parameters

| Name      | Type                                             | Description                                                              |
| :-------- | :----------------------------------------------- | :----------------------------------------------------------------------- |
| `TConfig` | [`ProviderConfig`](../interfaces/ProviderConfig) | Provider configuration type (defaults to ProviderConfig for type safety) |

## Implements

- [`TypeSafeAIProvider`](../interfaces/TypeSafeAIProvider)\<`TConfig`\>

## Table of contents

### Constructors

- [constructor](AbstractAIProvider#constructor)

### Properties

- [name](AbstractAIProvider#name)
- [version](AbstractAIProvider#version)

### Methods

- [configure](AbstractAIProvider#configure)
- [chat](AbstractAIProvider#chat)
- [chatStream](AbstractAIProvider#chatstream)
- [generateResponse](AbstractAIProvider#generateresponse)
- [generateStreamingResponse](AbstractAIProvider#generatestreamingresponse)
- [supportsTools](AbstractAIProvider#supportstools)
- [validateConfig](AbstractAIProvider#validateconfig)
- [dispose](AbstractAIProvider#dispose)

## Constructors

### constructor

• **new AbstractAIProvider**\<`TConfig`\>(`logger?`): [`AbstractAIProvider`](AbstractAIProvider)\<`TConfig`\>

#### Type parameters

| Name      | Type                                             |
| :-------- | :----------------------------------------------- |
| `TConfig` | [`ProviderConfig`](../interfaces/ProviderConfig) |

#### Parameters

| Name     | Type                                             | Default value             |
| :------- | :----------------------------------------------- | :------------------------ |
| `logger` | [`AbstractLogger`](../interfaces/AbstractLogger) | `DEFAULT_ABSTRACT_LOGGER` |

#### Returns

[`AbstractAIProvider`](AbstractAIProvider)\<`TConfig`\>

#### Defined in

[packages/agents/src/abstracts/abstract-ai-provider.ts:145](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/agents/src/abstracts/abstract-ai-provider.ts#L145)

## Properties

### name

• `Readonly` `Abstract` **name**: `string`

#### Implementation of

[TypeSafeAIProvider](../interfaces/TypeSafeAIProvider).[name](../interfaces/TypeSafeAIProvider#name)

#### Defined in

[packages/agents/src/abstracts/abstract-ai-provider.ts:139](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/agents/src/abstracts/abstract-ai-provider.ts#L139)

---

### version

• `Readonly` `Abstract` **version**: `string`

#### Implementation of

[TypeSafeAIProvider](../interfaces/TypeSafeAIProvider).[version](../interfaces/TypeSafeAIProvider#version)

#### Defined in

[packages/agents/src/abstracts/abstract-ai-provider.ts:140](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/agents/src/abstracts/abstract-ai-provider.ts#L140)

## Methods

### configure

▸ **configure**(`config`): `Promise`\<`void`\>

Configure the provider with type-safe configuration

#### Parameters

| Name     | Type      |
| :------- | :-------- |
| `config` | `TConfig` |

#### Returns

`Promise`\<`void`\>

#### Implementation of

[TypeSafeAIProvider](../interfaces/TypeSafeAIProvider).[configure](../interfaces/TypeSafeAIProvider#configure)

#### Defined in

[packages/agents/src/abstracts/abstract-ai-provider.ts:152](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/agents/src/abstracts/abstract-ai-provider.ts#L152)

---

### chat

▸ **chat**(`messages`, `options?`): `Promise`\<[`TUniversalMessage`](../modules#tuniversalmessage)\>

Each provider must implement chat using their own native SDK types internally

#### Parameters

| Name       | Type                                                  | Description                                        |
| :--------- | :---------------------------------------------------- | :------------------------------------------------- |
| `messages` | [`TUniversalMessage`](../modules#tuniversalmessage)[] | Array of messages from conversation history        |
| `options?` | [`IChatOptions`](../interfaces/IChatOptions)          | Chat options including tools, model settings, etc. |

#### Returns

`Promise`\<[`TUniversalMessage`](../modules#tuniversalmessage)\>

Promise resolving to a response

#### Implementation of

[TypeSafeAIProvider](../interfaces/TypeSafeAIProvider).[chat](../interfaces/TypeSafeAIProvider#chat)

#### Defined in

[packages/agents/src/abstracts/abstract-ai-provider.ts:171](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/agents/src/abstracts/abstract-ai-provider.ts#L171)

---

### chatStream

▸ **chatStream**(`messages`, `options?`): `AsyncIterable`\<[`TUniversalMessage`](../modules#tuniversalmessage), `any`, `any`\>

Each provider must implement streaming chat using their own native SDK types internally

#### Parameters

| Name       | Type                                                  | Description                                        |
| :--------- | :---------------------------------------------------- | :------------------------------------------------- |
| `messages` | [`TUniversalMessage`](../modules#tuniversalmessage)[] | Array of messages from conversation history        |
| `options?` | [`IChatOptions`](../interfaces/IChatOptions)          | Chat options including tools, model settings, etc. |

#### Returns

`AsyncIterable`\<[`TUniversalMessage`](../modules#tuniversalmessage), `any`, `any`\>

AsyncIterable of response chunks

#### Implementation of

[TypeSafeAIProvider](../interfaces/TypeSafeAIProvider).[chatStream](../interfaces/TypeSafeAIProvider#chatstream)

#### Defined in

[packages/agents/src/abstracts/abstract-ai-provider.ts:179](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/agents/src/abstracts/abstract-ai-provider.ts#L179)

---

### generateResponse

▸ **generateResponse**(`payload`): `Promise`\<[`IRawProviderResponse`](../interfaces/IRawProviderResponse)\>

Provider-agnostic raw response API.

This is the canonical "raw payload" entrypoint required by the AIProvider contract.
The default implementation delegates to `chat()` and adapts the result into a
RawProviderResponse shape.

#### Parameters

| Name      | Type                                                 |
| :-------- | :--------------------------------------------------- |
| `payload` | [`IProviderRequest`](../interfaces/IProviderRequest) |

#### Returns

`Promise`\<[`IRawProviderResponse`](../interfaces/IRawProviderResponse)\>

#### Implementation of

[TypeSafeAIProvider](../interfaces/TypeSafeAIProvider).[generateResponse](../interfaces/TypeSafeAIProvider#generateresponse)

#### Defined in

[packages/agents/src/abstracts/abstract-ai-provider.ts:188](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/agents/src/abstracts/abstract-ai-provider.ts#L188)

---

### generateStreamingResponse

▸ **generateStreamingResponse**(`payload`): `AsyncIterable`\<[`IRawProviderResponse`](../interfaces/IRawProviderResponse), `any`, `any`\>

Provider-agnostic raw streaming API.

If a provider does not implement chatStream, it does not support streaming.

#### Parameters

| Name      | Type                                                 |
| :-------- | :--------------------------------------------------- |
| `payload` | [`IProviderRequest`](../interfaces/IProviderRequest) |

#### Returns

`AsyncIterable`\<[`IRawProviderResponse`](../interfaces/IRawProviderResponse), `any`, `any`\>

#### Implementation of

[TypeSafeAIProvider](../interfaces/TypeSafeAIProvider).[generateStreamingResponse](../interfaces/TypeSafeAIProvider#generatestreamingresponse)

#### Defined in

[packages/agents/src/abstracts/abstract-ai-provider.ts:209](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/agents/src/abstracts/abstract-ai-provider.ts#L209)

---

### supportsTools

▸ **supportsTools**(): `boolean`

Default implementation - most modern providers support tools

#### Returns

`boolean`

true if tool calling is supported

#### Implementation of

[TypeSafeAIProvider](../interfaces/TypeSafeAIProvider).[supportsTools](../interfaces/TypeSafeAIProvider#supportstools)

#### Defined in

[packages/agents/src/abstracts/abstract-ai-provider.ts:233](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/agents/src/abstracts/abstract-ai-provider.ts#L233)

---

### validateConfig

▸ **validateConfig**(): `boolean`

Default implementation - providers can override for specific validation

#### Returns

`boolean`

true if configuration is valid

#### Implementation of

[TypeSafeAIProvider](../interfaces/TypeSafeAIProvider).[validateConfig](../interfaces/TypeSafeAIProvider#validateconfig)

#### Defined in

[packages/agents/src/abstracts/abstract-ai-provider.ts:241](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/agents/src/abstracts/abstract-ai-provider.ts#L241)

---

### dispose

▸ **dispose**(): `Promise`\<`void`\>

Clean up resources when provider is no longer needed
Override this method in subclasses for additional cleanup

#### Returns

`Promise`\<`void`\>

#### Implementation of

[TypeSafeAIProvider](../interfaces/TypeSafeAIProvider).[dispose](../interfaces/TypeSafeAIProvider#dispose)

#### Defined in

[packages/agents/src/abstracts/abstract-ai-provider.ts:363](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/agents/src/abstracts/abstract-ai-provider.ts#L363)
