@devries-cameron20 / composio-1 / commits / e035c8bf7
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.

Responses API provider support added

Sushmithamallesh committed Sep 27, 2025 at 01:09 UTC e035c8bf75b5cdaab635effc3faebfb908ef7429
3 files changed +100 -3
python/composio/core/provider/_openai_responses.py new
+96
@@ -0,0 +1,96 @@
1 +"""
2 +OpenAI Responses API provider implementation.
3 +
4 +This provider wraps tools for the new OpenAI Responses API which uses
5 +a flattened tool structure compared to the Chat Completions API.
6 +"""
7 +
8 +from __future__ import annotations
9 +
10 +import json
11 +import typing as t
12 +
13 +from openai.types.responses.response import Response
14 +from openai.types.responses.response_output_item import ResponseFunctionToolCall
15 +from openai.types.chat.chat_completion_message_tool_call import (
16 + ChatCompletionMessageToolCall,
17 +)
18 +
19 +from composio.core.provider import NonAgenticProvider
20 +from composio.types import Modifiers, Tool, ToolExecutionResponse
21 +
22 +# Responses API uses a flattened tool structure
23 +ResponsesTool = t.Dict[str, t.Any]
24 +ResponsesToolCollection = t.List[ResponsesTool]
25 +
26 +
27 +class OpenAIResponsesProvider(
28 + NonAgenticProvider[ResponsesTool, ResponsesToolCollection], name="openai_responses"
29 +):
30 + """OpenAI Responses API Provider class definition.
31 + """
32 +
33 + def wrap_tool(self, tool: Tool) -> ResponsesTool:
34 + """Wrap a tool for the Responses API format.
35 + """
36 + return {
37 + "type": "function",
38 + "name": tool.slug,
39 + "description": tool.description,
40 + "parameters": tool.input_parameters,
41 + }
42 +
43 + def wrap_tools(self, tools: t.Sequence[Tool]) -> ResponsesToolCollection:
44 + """Wrap multiple tools for the Responses API format."""
45 + return [self.wrap_tool(tool) for tool in tools]
46 +
47 + def execute_tool_call(
48 + self,
49 + user_id: str,
50 + tool_call: t.Union[ChatCompletionMessageToolCall, ResponseFunctionToolCall],
51 + modifiers: t.Optional[Modifiers] = None,
52 + ) -> ToolExecutionResponse:
53 + """Execute a tool call from the Responses API.
54 +
55 + :param tool_call: Tool call metadata from Responses API.
56 + :param user_id: User ID to use for executing the function call.
57 + :param modifiers: Optional modifiers for tool execution.
58 + :return: Object containing output data from the tool call.
59 + """
60 + slug = tool_call.name
61 + arguments = json.loads(tool_call.arguments)
62 +
63 + return self.execute_tool(
64 + slug=slug,
65 + arguments=arguments,
66 + modifiers=modifiers,
67 + user_id=user_id,
68 + )
69 +
70 + def handle_tool_calls(
71 + self,
72 + user_id: str,
73 + response: Response,
74 + modifiers: t.Optional[Modifiers] = None,
75 + ) -> t.List[ToolExecutionResponse]:
76 + """
77 + Handle tool calls from OpenAI Responses API.
78 +
79 + :param response: Response object from openai.OpenAI.beta.responses.create
80 + :param user_id: User ID to use for executing the function call.
81 + :param modifiers: Optional modifiers for tool execution
82 + :return: List[ToolExecutionResponse] with tool execution results
83 + """
84 + outputs = []
85 +
86 + if response.output:
87 + for item in response.output:
88 + if isinstance(item, ResponseFunctionToolCall):
89 + result = self.execute_tool_call(
90 + user_id=user_id,
91 + tool_call=item,
92 + modifiers=modifiers,
93 + )
94 + outputs.append(result)
95 +
96 + return outputs
\ No newline at end of file
python/providers/openai/composio_openai/__init__.py
+2 -2
@@ -1,3 +1,3 @@
1 -from composio_openai.provider import OpenAIProvider
1 +from composio_openai.provider import OpenAIProvider, OpenAIResponsesProvider
2
3 -__all__ = ("OpenAIProvider",)
3 +__all__ = ("OpenAIProvider", "OpenAIResponsesProvider")
python/providers/openai/composio_openai/provider.py
+2 -1
@@ -3,5 +3,6 @@ OpenAI Provider for composio SDK.
3 """
4
5 from composio.core.provider._openai import OpenAIProvider
6 +from composio.core.provider._openai_responses import OpenAIResponsesProvider
7
7 -__all__ = ["OpenAIProvider"]
8 +__all__ = ["OpenAIProvider", "OpenAIResponsesProvider"]