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

docs: add python modifier sinppets

angrybayblade committed Jun 16, 2025 at 19:29 UTC 6f2084f8ada0c2fa83476836146cba415afca0a1
5 files changed +215 -9
fern/docs/authentication/custom-auth-configs.mdx
+4 -4
@@ -106,7 +106,7 @@ connReq.id
106
107 console.log(connection);
108
109 -````
109 +```
110 ```python Python maxLines=60
111 # Create a new connected account
112 connection_request = composio.connected_accounts.initiate(
@@ -118,7 +118,7 @@ print(connection_request)
118 # Wait for the connection to be established
119 connected_account = connection_request.wait_for_connection()
120 print(connected_account)
121 -````
121 +```
122
123 </CodeGroup>
124
@@ -169,7 +169,7 @@ const redirectUrl = `${composioEndpoint}?${queryParams.toString()}`;
169 res.redirect(302, redirectUrl);
170 }
171
172 -````
172 +```
173
174 ```python FastAPI (app.py)
175 from fastapi import FastAPI
@@ -198,7 +198,7 @@ def authorize_app(toolkit: str):
198 auth_config_id=auth_config_id,
199 )
200 return RedirectResponse(url=connection_request.redirect_url)
201 -````
201 +```
202
203 </CodeGroup>
204 </Step>
fern/docs/authentication/custom-auth-params.mdx
+30 -2
@@ -60,7 +60,27 @@ const authModifier = (toolSlug: string, toolkitSlug: string, params: any) => {
60 };
61 ```
62 ```python Python maxLines=25
63 -
63 +from composio import before_execute
64 +from composio.types import ToolExecuteParams
65 +
66 +
67 +@before_execute(toolkits=["NOTION"])
68 +def add_custom_auth(
69 + tool: str,
70 + toolkit: str,
71 + params: ToolExecuteParams,
72 +) -> ToolExecuteParams:
73 + if params["custom_auth_params"] is None:
74 + params["custom_auth_params"] = {"parameters": []}
75 +
76 + params["custom_auth_params"]["parameters"].append(
77 + {
78 + "name": "x-api-key",
79 + "value": os.getenv("NOTION_API_KEY"),
80 + "in": "header",
81 + }
82 + )
83 + return params
84 ```
85 </CodeGroup>
86
@@ -91,6 +111,14 @@ const result = await composio.tools.execute(
111 console.log(JSON.stringify(result, null, 2));
112 ```
113 ```python Python maxLines=20
94 -
114 +result = composio.tools.execute(
115 + slug="NOTION_GET_DATABASE_ITEMS",
116 + user_id="default",
117 + arguments={},
118 + modifiers=[
119 + add_custom_auth,
120 + ],
121 +)
122 +print(result)
123 ```
124 </CodeGroup>
\ No newline at end of file
fern/docs/tool-calling/after-execution-modifiers.mdx
+58
@@ -74,7 +74,39 @@ if (tool_calls) {
74
75 ```
76 ```python Python maxLines=60 wordWrap
77 +from composio import Composio, after_execute
78 +from composio.types import ToolExecutionResponse
79 +
80 +@after_execute(tools=["HACKERNEWS_GET_USER"])
81 +def after_execute_modifier(
82 + tool: str,
83 + toolkit: str,
84 + response: ToolExecutionResponse,
85 +) -> ToolExecutionResponse:
86 + return {
87 + **response,
88 + "data": {
89 + "karama": response["data"]["karama"],
90 + },
91 + }
92
93 +# Get response from the LLM
94 +response = openai_client.chat.completions.create(
95 + model="gpt-4o-mini",
96 + tools=tools,
97 + messages=messages,
98 +)
99 +print(response)
100 +
101 +# Execute the function calls.
102 +result = composio.provider.handle_tool_calls(
103 + response=response,
104 + user_id="default",
105 + modifiers=[
106 + after_execute_modifier,
107 + ]
108 +)
109 +print(result)
110 ```
111
112 </CodeGroup>
@@ -121,7 +153,33 @@ const agenticTools = await composio.tools.get(
153
154 ```
155 ```python Python maxLines=60 wordWrap
156 +from composio import Composio, after_execute
157 +from composio.types import ToolExecutionResponse
158 +from composio_crewai import CrewAIProvider
159 +
160 +composio = Composio(provider=CrewAIProvider())
161 +
162 +@after_execute(tools=["HACKERNEWS_GET_USER"])
163 +def after_execute_modifier(
164 + tool: str,
165 + toolkit: str,
166 + response: ToolExecutionResponse,
167 +) -> ToolExecutionResponse:
168 + return {
169 + **response,
170 + "data": {
171 + "karama": response["data"]["karama"],
172 + },
173 + }
174 +
175
176 +tools = composio.tools.get(
177 + user_id="default",
178 + slug="HACKERNEWS_GET_USER",
179 + modifiers=[
180 + after_execute_modifier,
181 + ]
182 +)
183 ```
184
185 </CodeGroup>
fern/docs/tool-calling/before-execution-modifiers.mdx
+55 -2
@@ -70,7 +70,35 @@ if (tool_calls) {
70
71 ```
72 ```python Python maxLines=60 wordWrap
73 -
73 +from composio import Composio, before_execute
74 +from composio.types import ToolExecuteParams
75 +
76 +@before_execute(tools=["HACKERNEWS_GET_LATEST_POSTS"])
77 +def before_execute_modifier(
78 + tool: str,
79 + toolkit: str,
80 + params: ToolExecuteParams,
81 +) -> ToolExecuteParams:
82 + params["arguments"]["size"] = 1
83 + return params
84 +
85 +# Get response from the LLM
86 +response = openai_client.chat.completions.create(
87 + model="gpt-4o-mini",
88 + tools=tools,
89 + messages=messages,
90 +)
91 +print(response)
92 +
93 +# Execute the function calls.
94 +result = composio.provider.handle_tool_calls(
95 + response=response,
96 + user_id="default",
97 + modifiers=[
98 + before_execute_modifier,
99 + ]
100 +)
101 +print(result)
102 ```
103
104 </CodeGroup>
@@ -123,7 +151,32 @@ const { text } = await generateText({
151
152 ```
153 ```python Python maxLines=60 wordWrap
126 -
154 +from composio import Composio, before_execute
155 +from composio.types import ToolExecuteParams
156 +from composio_crewai import CrewAIProvider
157 +
158 +composio = Composio(provider=CrewAIProvider())
159 +
160 +@before_execute(tools=["LINEAR_CREATE_LINEAR_ISSUE"])
161 +def modify_linear_project_id(
162 + tool: str,
163 + toolkit: str,
164 + params: ToolExecuteParams,
165 +) -> ToolExecuteParams:
166 + params["arguments"]["project_id"] = "1234567890"
167 + return params
168 +
169 +tools = composio.tools.get(
170 + user_id="default",
171 + tools=[
172 + "HACKERNEWS_GET_LATEST_POSTS",
173 + "HACKERNEWS_GET_USER",
174 + "LINEAR_CREATE_LINEAR_ISSUE",
175 + ],
176 + modifiers=[
177 + after_execute_modifier,
178 + ]
179 +)
180 ```
181
182 </CodeGroup>
fern/docs/tool-calling/schema-modifiers.mdx
+68 -1
@@ -52,7 +52,28 @@ console.log(JSON.stringify(tools, null, 2));
52
53 ```
54 ```python Python maxLines=60 wordWrap
55 -
55 +from composio import Composio, schema_modifier
56 +from composio.types import Tool
57 +
58 +user_id = "your@email.com"
59 +
60 +@schema_modifier(tools=["HACKERNEWS_GET_LATEST_POSTS"])
61 +def modify_schema(
62 + tool: str,
63 + toolkit: str,
64 + schema: Tool,
65 +) -> Tool:
66 + _ = schema.input_parameters["properties"].pop("page", None)
67 + schema.input_parameters["required"] = ["size"]
68 + return schema
69 +
70 +tools = composio.tools.get(
71 + user_id=user_id,
72 + tools=["HACKERNEWS_GET_LATEST_POSTS", "HACKERNEWS_GET_USER"],
73 + modifiers=[
74 + modify_schema,
75 + ]
76 +)
77 ```
78
79 </CodeGroup>
@@ -114,6 +135,52 @@ console.log(response.choices[0].message.tool_calls);
135
136 ```python Python maxLines=60 wordWrap
137
138 +from openai import OpenAI
139 +from composio import Composio, schema_modifier
140 +from composio.types import Tool
141 +from composio_openai import OpenAIProvider
142 +
143 +
144 +@schema_modifier(tools=["HACKERNEWS_GET_LATEST_POSTS"])
145 +def modify_schema(
146 + tool: str,
147 + toolkit: str,
148 + schema: Tool,
149 +) -> Tool:
150 + _ = schema.input_parameters["properties"].pop("page", None)
151 + schema.input_parameters["required"] = ["size"]
152 + return schema
153 +
154 +# Initialize tools.
155 +openai_client = OpenAI()
156 +composio = Composio(provider=OpenAIProvider())
157 +
158 +# Define task.
159 +task = "Star a repo composiohq/composio on GitHub"
160 +
161 +# Get GitHub tools that are pre-configured
162 +tools = composio.tools.get(
163 + user_id="default",
164 + tools=['HACKERNEWS_GET_LATEST_POSTS', 'HACKERNEWS_GET_USER'],
165 + modifiers=[
166 + modify_schema,
167 + ],
168 +)
169 +
170 +# Get response from the LLM
171 +response = openai_client.chat.completions.create(
172 + model="gpt-4o-mini",
173 + tools=tools,
174 + messages=[
175 + {"role": "system", "content": "You are a helpful assistant."},
176 + {"role": "user", "content": task},
177 + ],
178 +)
179 +print(response)
180 +
181 +# Execute the function calls.
182 +result = composio.provider.handle_tool_calls(response=response, user_id="default")
183 +print(result)
184 ```
185
186 </CodeGroup>