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

next
mdx 134 lines 3.9 KB
Raw
1 ---
2 title: "Type-Safe get_tools() for Python SDK"
3 description: "The Python SDK now provides automatic type inference for tools.get() based on the provider"
4 date: "2026-02-01"
5 ---
6
7 The Python SDK's `Composio` class is now generic over the provider type. When you pass a provider to `Composio()`, the return type of `tools.get()` is automatically inferred based on that provider.
8
9 ### SDK Versions
10
11 | SDK | Version |
12 |-----|---------|
13 | Python | v0.11.1+ |
14
15 ### What Changed
16
17 **Before:** The return type of `tools.get()` was always untyped or required manual type annotations.
18
19 **After:** Type checkers (mypy, Pyright) automatically infer the correct tool type from the provider you pass.
20
21 **Before (untyped):**
22 ```python
23 from composio import Composio
24 from composio_anthropic import AnthropicProvider
25
26 composio = Composio(provider=AnthropicProvider())
27 tools = composio.tools.get(user_id="user_123", toolkits=["github"])
28 # tools: Unknown type - no inference
29 ```
30
31 **After (type-safe):**
32 ```python
33 from composio import Composio
34 from composio_anthropic import AnthropicProvider
35
36 composio = Composio(provider=AnthropicProvider())
37 tools = composio.tools.get(user_id="user_123", toolkits=["github"])
38 # tools: list[ToolParam] - automatically inferred!
39 ```
40
41 ### Automatic Type Inference
42
43 The `Composio` class now uses Python generics to provide type-safe return values:
44
45 ```python
46 from composio import Composio
47 from composio_openai import OpenAIProvider
48 from composio_anthropic import AnthropicProvider
49
50 # OpenAI provider -> list[ChatCompletionToolParam]
51 composio_openai = Composio(provider=OpenAIProvider())
52 openai_tools = composio_openai.tools.get(user_id="user", toolkits=["github"])
53
54 # Anthropic provider -> list[ToolParam]
55 composio_anthropic = Composio(provider=AnthropicProvider())
56 anthropic_tools = composio_anthropic.tools.get(user_id="user", toolkits=["github"])
57
58 # Default (no provider) -> list[ChatCompletionToolParam] (OpenAI)
59 composio_default = Composio()
60 default_tools = composio_default.tools.get(user_id="user", toolkits=["github"])
61 ```
62
63 ### Custom Provider Support
64
65 Custom providers automatically get proper type inference without requiring any changes to the Composio SDK:
66
67 ```python
68 import typing as t
69 from typing import Sequence
70
71 from composio import Composio
72 from composio.client.types import Tool
73 from composio.core.provider import NonAgenticProvider
74
75
76 class MyCustomTool(t.TypedDict):
77 """Your custom tool format."""
78 name: str
79 description: str
80 parameters: dict
81
82
83 MyCustomToolCollection = t.List[MyCustomTool]
84
85
86 class MyCustomProvider(
87 NonAgenticProvider[MyCustomTool, MyCustomToolCollection],
88 name="my-custom"
89 ):
90 def wrap_tool(self, tool: Tool) -> MyCustomTool:
91 return MyCustomTool(
92 name=tool.slug,
93 description=tool.description or "",
94 parameters=tool.input_parameters or {},
95 )
96
97 def wrap_tools(self, tools: Sequence[Tool]) -> MyCustomToolCollection:
98 return [self.wrap_tool(tool) for tool in tools]
99
100
101 # Type inference works automatically!
102 composio = Composio(provider=MyCustomProvider())
103 tools = composio.tools.get(user_id="user", toolkits=["github"])
104 # tools: list[MyCustomTool] - correctly inferred
105 ```
106
107 ### Supported Providers
108
109 Type inference is supported for all built-in providers:
110
111 | Provider | Tool Type |
112 |----------|-----------|
113 | OpenAI | `ChatCompletionToolParam` |
114 | OpenAI Responses | `dict[str, Any]` |
115 | Anthropic | `ToolParam` |
116 | Google (GenAI) | `FunctionDeclaration` |
117 | Gemini | `FunctionDeclaration` |
118 | Google ADK | `Tool` |
119 | LangChain | `StructuredTool` |
120 | LangGraph | `StructuredTool` |
121 | LlamaIndex | `FunctionTool` |
122 | CrewAI | `Tool` |
123 | AutoGen | `FunctionTool` |
124 | OpenAI Agents | `FunctionTool` |
125 | Claude Agent SDK | `Tool` |
126
127 ### Backward Compatibility
128
129 This change is fully backward compatible:
130
131 - Existing code continues to work without modifications
132 - Type inference is opt-in via static type checkers
133 - No runtime behavior changes
134 - No migration required