@devries-cameron20 / composio Mirror · read-only / commits / 1d0d54140
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

Refactor the OpenAI assistant demo to use the OpenAIResponsesProvider and streamline task execution with the Responses API.

Srija Vuppala committed Aug 18, 2026 at 10:59 UTC 1d0d54140ee170682076eb0114ef7903a07c787d
1 file changed +40 -53
python/providers/openai/openai_assistant_demo.py
+40 -53
@@ -1,64 +1,51 @@
1 -from datetime import datetime
1 +"""
2 +OpenAI Responses API demo.
3 +"""
4
3 -from composio_openai import OpenAIProvider
5 +import json
6 +
7 +from composio_openai import OpenAIResponsesProvider
8 from openai import OpenAI
9
10 from composio import Composio
11
12 # Initialize tools.
13 openai_client = OpenAI()
10 -composio = Composio(provider=OpenAIProvider())
11 -
12 -# Retrieve actions
13 -actions = composio.tools.get(
14 - user_id="default",
15 - tools=["NOTION_ADD_PAGE_CONTENT"],
16 -)
17 -
18 -# Setup openai assistant
19 -assistant_instruction = (
20 - "You are a super intelligent personal assistant."
21 - + "You have been given a set of tools that you are supposed to choose from."
22 - + "You decide the right tool and execute it."
23 -)
24 -# Prepare assistant
25 -assistant = openai_client.beta.assistants.create(
26 - name="Personal Assistant",
27 - instructions=assistant_instruction,
28 - model="gpt-5",
29 - tools=actions, # type: ignore
30 -)
14 +composio = Composio(provider=OpenAIResponsesProvider())
15
32 -# Give a task to execute via Openai Assistants
33 -my_task = (
34 - f"Can you copy all the events in coming week from google calendar to notion? "
35 - f"Today's date is {datetime.now()} and day is {datetime.now().strftime('%A')}"
36 -)
37 -
38 -# create a thread
39 -thread = openai_client.beta.threads.create()
40 -print("Thread ID: ", thread.id)
41 -print("Assistant ID: ", assistant.id)
42 -
43 -# start the asssitant with my task
44 -message = openai_client.beta.threads.messages.create(
45 - thread_id=thread.id,
46 - role="user",
47 - content=my_task,
48 -)
16 +# Define task.
17 +task = "Tell me about the user `pg` on Hacker News."
18
50 -# Execute Agent with integrations
51 -run = openai_client.beta.threads.runs.create(
52 - thread_id=thread.id,
53 - assistant_id=assistant.id,
54 -)
19 +# Get tools that are pre-configured for the Responses API.
20 +tools = composio.tools.get(user_id="default", tools=["HACKERNEWS_GET_USER"])
21
56 -# Execute function calls
57 -run_after_tool_calls = composio.provider.wait_and_handle_assistant_tool_calls(
58 - user_id="default",
59 - client=openai_client,
60 - run=run,
61 - thread=thread,
22 +# Get the first response from the LLM.
23 +response = openai_client.responses.create(
24 + model="gpt-5.2",
25 + tools=tools,
26 + input=task,
27 )
63 -
64 -print(run_after_tool_calls)
28 +print(response)
29 +
30 +# Execute tool calls until the model returns a final answer.
31 +while True:
32 + tool_calls = [item for item in response.output if item.type == "function_call"]
33 + if not tool_calls:
34 + break
35 +
36 + results = composio.provider.handle_tool_calls(response=response, user_id="default")
37 + response = openai_client.responses.create(
38 + model="gpt-5.2",
39 + tools=tools,
40 + previous_response_id=response.id,
41 + input=[
42 + {
43 + "type": "function_call_output",
44 + "call_id": tool_calls[index].call_id,
45 + "output": json.dumps(result),
46 + }
47 + for index, result in enumerate(results)
48 + ],
49 + )
50 +
51 +print(response.output_text)