<!--
 ⚠️  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
-->

[openai](../../) / [Exports](../modules) / OpenAIConversationAdapter

# Class: OpenAIConversationAdapter

OpenAI Conversation Adapter

Converts between TUniversalMessage format and OpenAI native types.
Provides bidirectional conversion for seamless integration.

## Table of contents

### Constructors

- [constructor](OpenAIConversationAdapter#constructor)

### Methods

- [filterMessagesForOpenAI](OpenAIConversationAdapter#filtermessagesforopenai)
- [toOpenAIFormat](OpenAIConversationAdapter#toopenaiformat)
- [convertMessage](OpenAIConversationAdapter#convertmessage)
- [addSystemPromptIfNeeded](OpenAIConversationAdapter#addsystempromptifneeded)

## Constructors

### constructor

• **new OpenAIConversationAdapter**(): [`OpenAIConversationAdapter`](OpenAIConversationAdapter)

#### Returns

[`OpenAIConversationAdapter`](OpenAIConversationAdapter)

## Methods

### filterMessagesForOpenAI

▸ **filterMessagesForOpenAI**(`messages`): `TUniversalMessage`[]

Filter messages for OpenAI compatibility

OpenAI has specific requirements:

- Tool messages must have valid toolCallId
- Messages must be in proper sequence
- Tool messages without toolCallId should be excluded

#### Parameters

| Name       | Type                  |
| :--------- | :-------------------- |
| `messages` | `TUniversalMessage`[] |

#### Returns

`TUniversalMessage`[]

#### Defined in

[openai/src/adapter.ts:21](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/openai/src/adapter.ts#L21)

---

### toOpenAIFormat

▸ **toOpenAIFormat**(`messages`): `ChatCompletionMessageParam`[]

Convert TUniversalMessage array to OpenAI message format
Now properly handles tool messages for OpenAI's tool calling feature

#### Parameters

| Name       | Type                  |
| :--------- | :-------------------- |
| `messages` | `TUniversalMessage`[] |

#### Returns

`ChatCompletionMessageParam`[]

#### Defined in

[openai/src/adapter.ts:46](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/openai/src/adapter.ts#L46)

---

### convertMessage

▸ **convertMessage**(`msg`): `ChatCompletionMessageParam`

Convert a single TUniversalMessage to OpenAI format
Handles all message types including tool messages

#### Parameters

| Name  | Type                |
| :---- | :------------------ |
| `msg` | `TUniversalMessage` |

#### Returns

`ChatCompletionMessageParam`

#### Defined in

[openai/src/adapter.ts:56](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/openai/src/adapter.ts#L56)

---

### addSystemPromptIfNeeded

▸ **addSystemPromptIfNeeded**(`messages`, `systemPrompt?`): `ChatCompletionMessageParam`[]

Add system prompt to message array if needed

#### Parameters

| Name            | Type                           |
| :-------------- | :----------------------------- |
| `messages`      | `ChatCompletionMessageParam`[] |
| `systemPrompt?` | `string`                       |

#### Returns

`ChatCompletionMessageParam`[]

#### Defined in

[openai/src/adapter.ts:127](https://github.com/woojubb/robota/blob/4f4c8a3197e92ddd43d12dc9186b0771983054c9/packages/openai/src/adapter.ts#L127)
