agents / Exports / BaseAIProvider
Class: BaseAIProvider<TConfig, TMessage, TResponse>
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:
EXTEND THIS CLASS:
typescriptexport class OpenAIProvider extends BaseAIProvider { override readonly name = 'openai'; override readonly version = '1.0.0';
USE IMPORTS FROM @robota-sdk/agents:
typescriptimport { BaseAIProvider } from '@robota-sdk/agents'; import type { UniversalMessage, ChatOptions, ToolCall, ToolSchema, AssistantMessage } from '@robota-sdk/agents';
USE OVERRIDE KEYWORD FOR ALL INHERITED METHODS:
- override async chat(...)
- override async *chatStream(...)
- override supportsTools()
- override validateConfig()
- override async dispose()
DO NOT REDEFINE TYPES THAT EXIST IN @robota-sdk/agents:
- UniversalMessage
- ChatOptions
- ToolCall
- ToolSchema
- AssistantMessage
- SystemMessage
- UserMessage
- ToolMessage
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
CALL SUPER() IN CONSTRUCTOR:
typescriptconstructor(options: ProviderOptions) { super(); // provider-specific initialization }
This ensures ExecutionService can properly identify providers and prevents type conflicts across the codebase.
========================================
Type parameters
Name | Type | Description |
---|---|---|
TConfig | ProviderConfig | Provider configuration type (defaults to ProviderConfig for type safety) |
TMessage | UniversalMessage | Message type (defaults to UniversalMessage for backward compatibility) |
TResponse | UniversalMessage | Response type (defaults to UniversalMessage for backward compatibility) |
Implements
TypeSafeAIProvider
<TConfig
,TMessage
,TResponse
>
Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new BaseAIProvider<TConfig
, TMessage
, TResponse
>(): BaseAIProvider
<TConfig
, TMessage
, TResponse
>
Type parameters
Name | Type |
---|---|
TConfig | ProviderConfig |
TMessage | UniversalMessage |
TResponse | UniversalMessage |
Returns
BaseAIProvider
<TConfig
, TMessage
, TResponse
>
Properties
name
• Readonly
Abstract
name: string
Implementation of
Defined in
packages/agents/src/abstracts/base-ai-provider.ts:110
version
• Readonly
Abstract
version: string
Implementation of
Defined in
packages/agents/src/abstracts/base-ai-provider.ts:111
Methods
configure
▸ configure(config
): Promise
<void
>
Configure the provider with type-safe configuration
Parameters
Name | Type |
---|---|
config | TConfig |
Returns
Promise
<void
>
Implementation of
Defined in
packages/agents/src/abstracts/base-ai-provider.ts:117
chat
▸ chat(messages
, options?
): Promise
<TResponse
>
Each provider must implement chat using their own native SDK types internally
Parameters
Name | Type | Description |
---|---|---|
messages | TMessage [] | Array of messages from conversation history |
options? | ChatOptions | Chat options including tools, model settings, etc. |
Returns
Promise
<TResponse
>
Promise resolving to a response
Implementation of
Defined in
packages/agents/src/abstracts/base-ai-provider.ts:128
chatStream
▸ chatStream(messages
, options?
): AsyncIterable
<TResponse
, any
, any
>
Each provider must implement streaming chat using their own native SDK types internally
Parameters
Name | Type | Description |
---|---|---|
messages | TMessage [] | Array of messages from conversation history |
options? | ChatOptions | Chat options including tools, model settings, etc. |
Returns
AsyncIterable
<TResponse
, any
, any
>
AsyncIterable of response chunks
Implementation of
Defined in
packages/agents/src/abstracts/base-ai-provider.ts:136
supportsTools
▸ supportsTools(): boolean
Default implementation - most modern providers support tools
Returns
boolean
true if tool calling is supported
Implementation of
TypeSafeAIProvider.supportsTools
Defined in
packages/agents/src/abstracts/base-ai-provider.ts:142
validateConfig
▸ validateConfig(): boolean
Default implementation - providers can override for specific validation
Returns
boolean
true if configuration is valid
Implementation of
TypeSafeAIProvider.validateConfig
Defined in
packages/agents/src/abstracts/base-ai-provider.ts:150
dispose
▸ dispose(): Promise
<void
>
Default implementation - providers can override for cleanup
Returns
Promise
<void
>