@devries-cameron20 / composio Mirror · read-only / commits / a1ae274e5
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 16:00 UTC

docs(openai): replace assistants examples with responses

Updated documentation to reflect changes in OpenAI Provider usage, including the transition from OpenAI Assistants to OpenAI Responses API and the introduction of OpenAIResponsesProvider.

Srija Vuppala committed Aug 18, 2026 at 11:01 UTC a1ae274e549dfb5c787d05b08e80a385c30946f6
1 file changed +20 -129
ts/docs/providers/openai.md
+20 -129
@@ -8,8 +8,7 @@ The OpenAI Provider allows you to:
8
9 1. Format Composio tools as OpenAI function tools
10 2. Handle tool calls from OpenAI chat completions
11 -3. Handle tool calls from OpenAI assistants
12 -4. Process streaming responses from OpenAI with tool calls
11 +3. Handle tool calls from the OpenAI Responses API through `OpenAIResponsesProvider`
12
13 ## Basic Usage
14
@@ -132,131 +131,48 @@ if (completion.choices[0].message.tool_calls) {
131 }
132 ```
133
135 -## Working with OpenAI Assistants
134 +## Working with OpenAI Responses
135
137 -The OpenAI Provider includes helper methods for working with OpenAI Assistants:
136 +Use `OpenAIResponsesProvider` for new agentic flows. It formats Composio tools for the Responses API and returns `function_call_output` items that you can pass back with `previous_response_id`.
137
138 ```typescript
139 import { Composio } from '@composio/core';
141 -import { OpenAIProvider } from '@composio/openai';
142 -import OpenAI from 'openai';
143 -
144 -const composio = new Composio({
145 - apiKey: 'your-composio-api-key',
146 -});
147 -
148 -const openai = new OpenAI({
149 - apiKey: 'your-openai-api-key',
150 -});
151 -
152 -// Get the OpenAI Provider
153 -const openaiProvider = composio.provider as OpenAIProvider;
154 -
155 -// Get GitHub tools
156 -const tools = await composio.tools.get('default', {
157 - toolkits: ['github'],
158 -});
159 -
160 -// Create an assistant with Composio tools
161 -const assistant = await openai.beta.assistants.create({
162 - name: 'GitHub Assistant',
163 - instructions: 'You are a helpful assistant with GitHub tools.',
164 - model: 'gpt-4',
165 - tools,
166 -});
167 -
168 -// Create a thread
169 -const thread = await openai.beta.threads.create();
170 -
171 -// Add a message to the thread
172 -await openai.beta.threads.messages.create(thread.id, {
173 - role: 'user',
174 - content: 'Find information about the Composio SDK repository',
175 -});
176 -
177 -// Run the assistant
178 -const run = await openai.beta.threads.runs.create(thread.id, {
179 - assistant_id: assistant.id,
180 -});
181 -
182 -// Wait for the run to complete and handle any tool calls
183 -const finalRun = await openaiProvider.waitAndHandleAssistantToolCalls(
184 - 'default', // userId
185 - openai,
186 - run,
187 - thread,
188 - { connectedAccountId: 'connected_account_123' } // Optional
189 -);
190 -
191 -// Get the assistant's response
192 -const messages = await openai.beta.threads.messages.list(thread.id);
193 -console.log(messages.data[0].content);
194 -```
195 -
196 -## Handling Streaming Responses with Tool Calls
197 -
198 -The OpenAI Provider can also handle streaming responses with tool calls:
199 -
200 -```typescript
201 -import { Composio } from '@composio/core';
202 -import { OpenAIProvider } from '@composio/openai';
140 +import { OpenAIResponsesProvider } from '@composio/openai';
141 import OpenAI from 'openai';
142
143 const composio = new Composio({
144 apiKey: 'your-composio-api-key',
145 + provider: new OpenAIResponsesProvider(),
146 });
147
148 const openai = new OpenAI({
149 apiKey: 'your-openai-api-key',
150 });
151
213 -// Get the OpenAI Provider
214 -const openaiProvider = composio.provider as OpenAIProvider;
215 -
152 // Get GitHub tools
153 const tools = await composio.tools.get('default', {
154 toolkits: ['github'],
155 });
156
221 -// Create an assistant with Composio tools
222 -const assistant = await openai.beta.assistants.create({
223 - name: 'GitHub Assistant',
224 - instructions: 'You are a helpful assistant with GitHub tools.',
225 - model: 'gpt-4',
157 +let response = await openai.responses.create({
158 + model: 'gpt-5.2',
159 tools,
160 + input: 'Find information about the Composio SDK repository',
161 });
162
229 -// Create a thread
230 -const thread = await openai.beta.threads.create();
231 -
232 -// Add a message to the thread
233 -await openai.beta.threads.messages.create(thread.id, {
234 - role: 'user',
235 - content: 'Find information about the Composio SDK repository',
236 -});
237 -
238 -// Run the assistant with streaming
239 -const runStream = await openai.beta.threads.runs.createAndStream(thread.id, {
240 - assistant_id: assistant.id,
241 -});
163 +while (response.output.some(item => item.type === 'function_call')) {
164 + const toolOutputs = await composio.provider.handleToolCalls('default', response.output);
165 + response = await openai.responses.create({
166 + model: 'gpt-5.2',
167 + tools,
168 + previous_response_id: response.id,
169 + input: toolOutputs,
170 + });
171 +}
172
243 -// Process the stream and handle tool calls
244 -for await (const event of openaiProvider.waitAndHandleAssistantStreamToolCalls(
245 - 'default', // userId
246 - openai,
247 - runStream,
248 - thread,
249 - { connectedAccountId: 'connected_account_123' } // Optional
250 -)) {
251 - // Process different event types
252 - if (event.event === 'thread.message.created') {
253 - console.log('New message created');
254 - } else if (event.event === 'thread.message.delta') {
255 - console.log('Message update:', event.data.delta.content);
256 - } else if (event.event === 'thread.run.requires_action') {
257 - console.log('Run requires action (tools being executed)');
258 - } else if (event.event === 'thread.run.completed') {
259 - console.log('Run completed');
173 +for (const item of response.output) {
174 + if (item.type === 'message' && item.content[0].type === 'output_text') {
175 + console.log(item.content[0].text);
176 }
177 }
178 ```
@@ -344,30 +260,5 @@ class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection, OpenAi
260 options?: ExecuteToolFnOptions,
261 modifiers?: ExecuteToolModifiers
262 ): Promise<OpenAI.ChatCompletionToolMessageParam[]>;
347 -
348 - handleAssistantMessage(
349 - userId: string,
350 - run: OpenAI.Beta.Threads.Run,
351 - options?: ExecuteToolFnOptions,
352 - modifiers?: ExecuteToolModifiers
353 - ): Promise<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput[]>;
354 -
355 - waitAndHandleAssistantStreamToolCalls(
356 - userId: string,
357 - client: OpenAI,
358 - runStream: Stream<OpenAI.Beta.Assistants.AssistantStreamEvent>,
359 - thread: OpenAI.Beta.Threads.Thread,
360 - options?: ExecuteToolFnOptions,
361 - modifiers?: ExecuteToolModifiers
362 - ): AsyncGenerator<OpenAI.Beta.Assistants.AssistantStreamEvent, void, unknown>;
363 -
364 - waitAndHandleAssistantToolCalls(
365 - userId: string,
366 - client: OpenAI,
367 - run: OpenAI.Beta.Threads.Run,
368 - thread: OpenAI.Beta.Threads.Thread,
369 - options?: ExecuteToolFnOptions,
370 - modifiers?: ExecuteToolModifiers
371 - ): Promise<OpenAI.Beta.Threads.Run>;
263 }
264 ```