Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
docs: add python modifier sinppets
angrybayblade6f2084f8ada0
diff --git a/fern/docs/authentication/custom-auth-configs.mdx b/fern/docs/authentication/custom-auth-configs.mdxindex 0f9fee5b2..66b93aa38 100644--- a/fern/docs/authentication/custom-auth-configs.mdx+++ b/fern/docs/authentication/custom-auth-configs.mdx@@ -106,7 +106,7 @@ connReq.idconsole.log(connection);-````+``````python Python maxLines=60# Create a new connected accountconnection_request = composio.connected_accounts.initiate(@@ -118,7 +118,7 @@ print(connection_request)# Wait for the connection to be establishedconnected_account = connection_request.wait_for_connection()print(connected_account)-````+```</CodeGroup>@@ -169,7 +169,7 @@ const redirectUrl = `${composioEndpoint}?${queryParams.toString()}`;res.redirect(302, redirectUrl);}-````+``````python FastAPI (app.py)from fastapi import FastAPI@@ -198,7 +198,7 @@ def authorize_app(toolkit: str):auth_config_id=auth_config_id,)return RedirectResponse(url=connection_request.redirect_url)-````+```</CodeGroup></Step>diff --git a/fern/docs/authentication/custom-auth-params.mdx b/fern/docs/authentication/custom-auth-params.mdxindex 80eeea3b7..b1f2b5d0c 100644--- a/fern/docs/authentication/custom-auth-params.mdx+++ b/fern/docs/authentication/custom-auth-params.mdx@@ -60,7 +60,27 @@ const authModifier = (toolSlug: string, toolkitSlug: string, params: any) => {};``````python Python maxLines=25-+from composio import before_execute+from composio.types import ToolExecuteParams+++@before_execute(toolkits=["NOTION"])+def add_custom_auth(+ tool: str,+ toolkit: str,+ params: ToolExecuteParams,+) -> ToolExecuteParams:+ if params["custom_auth_params"] is None:+ params["custom_auth_params"] = {"parameters": []}++ params["custom_auth_params"]["parameters"].append(+ {+ "name": "x-api-key",+ "value": os.getenv("NOTION_API_KEY"),+ "in": "header",+ }+ )+ return params```</CodeGroup>@@ -91,6 +111,14 @@ const result = await composio.tools.execute(console.log(JSON.stringify(result, null, 2));``````python Python maxLines=20-+result = composio.tools.execute(+ slug="NOTION_GET_DATABASE_ITEMS",+ user_id="default",+ arguments={},+ modifiers=[+ add_custom_auth,+ ],+)+print(result)```</CodeGroup>\ No newline at end of filediff --git a/fern/docs/tool-calling/after-execution-modifiers.mdx b/fern/docs/tool-calling/after-execution-modifiers.mdxindex feaa167a4..56d8e88f5 100644--- a/fern/docs/tool-calling/after-execution-modifiers.mdx+++ b/fern/docs/tool-calling/after-execution-modifiers.mdx@@ -74,7 +74,39 @@ if (tool_calls) {``````python Python maxLines=60 wordWrap+from composio import Composio, after_execute+from composio.types import ToolExecutionResponse++@after_execute(tools=["HACKERNEWS_GET_USER"])+def after_execute_modifier(+ tool: str,+ toolkit: str,+ response: ToolExecutionResponse,+) -> ToolExecutionResponse:+ return {+ **response,+ "data": {+ "karama": response["data"]["karama"],+ },+ }+# Get response from the LLM+response = openai_client.chat.completions.create(+ model="gpt-4o-mini",+ tools=tools,+ messages=messages,+)+print(response)++# Execute the function calls.+result = composio.provider.handle_tool_calls(+ response=response,+ user_id="default",+ modifiers=[+ after_execute_modifier,+ ]+)+print(result)```</CodeGroup>@@ -121,7 +153,33 @@ const agenticTools = await composio.tools.get(``````python Python maxLines=60 wordWrap+from composio import Composio, after_execute+from composio.types import ToolExecutionResponse+from composio_crewai import CrewAIProvider++composio = Composio(provider=CrewAIProvider())++@after_execute(tools=["HACKERNEWS_GET_USER"])+def after_execute_modifier(+ tool: str,+ toolkit: str,+ response: ToolExecutionResponse,+) -> ToolExecutionResponse:+ return {+ **response,+ "data": {+ "karama": response["data"]["karama"],+ },+ }++tools = composio.tools.get(+ user_id="default",+ slug="HACKERNEWS_GET_USER",+ modifiers=[+ after_execute_modifier,+ ]+)```</CodeGroup>diff --git a/fern/docs/tool-calling/before-execution-modifiers.mdx b/fern/docs/tool-calling/before-execution-modifiers.mdxindex bbe75c45d..dce86eeb5 100644--- a/fern/docs/tool-calling/before-execution-modifiers.mdx+++ b/fern/docs/tool-calling/before-execution-modifiers.mdx@@ -70,7 +70,35 @@ if (tool_calls) {``````python Python maxLines=60 wordWrap-+from composio import Composio, before_execute+from composio.types import ToolExecuteParams++@before_execute(tools=["HACKERNEWS_GET_LATEST_POSTS"])+def before_execute_modifier(+ tool: str,+ toolkit: str,+ params: ToolExecuteParams,+) -> ToolExecuteParams:+ params["arguments"]["size"] = 1+ return params++# Get response from the LLM+response = openai_client.chat.completions.create(+ model="gpt-4o-mini",+ tools=tools,+ messages=messages,+)+print(response)++# Execute the function calls.+result = composio.provider.handle_tool_calls(+ response=response,+ user_id="default",+ modifiers=[+ before_execute_modifier,+ ]+)+print(result)```</CodeGroup>@@ -123,7 +151,32 @@ const { text } = await generateText({``````python Python maxLines=60 wordWrap-+from composio import Composio, before_execute+from composio.types import ToolExecuteParams+from composio_crewai import CrewAIProvider++composio = Composio(provider=CrewAIProvider())++@before_execute(tools=["LINEAR_CREATE_LINEAR_ISSUE"])+def modify_linear_project_id(+ tool: str,+ toolkit: str,+ params: ToolExecuteParams,+) -> ToolExecuteParams:+ params["arguments"]["project_id"] = "1234567890"+ return params++tools = composio.tools.get(+ user_id="default",+ tools=[+ "HACKERNEWS_GET_LATEST_POSTS",+ "HACKERNEWS_GET_USER",+ "LINEAR_CREATE_LINEAR_ISSUE",+ ],+ modifiers=[+ after_execute_modifier,+ ]+)```</CodeGroup>diff --git a/fern/docs/tool-calling/schema-modifiers.mdx b/fern/docs/tool-calling/schema-modifiers.mdxindex d0769d2c3..5e31e194b 100644--- a/fern/docs/tool-calling/schema-modifiers.mdx+++ b/fern/docs/tool-calling/schema-modifiers.mdx@@ -52,7 +52,28 @@ console.log(JSON.stringify(tools, null, 2));``````python Python maxLines=60 wordWrap-+from composio import Composio, schema_modifier+from composio.types import Tool++user_id = "[email protected]"++@schema_modifier(tools=["HACKERNEWS_GET_LATEST_POSTS"])+def modify_schema(+ tool: str,+ toolkit: str,+ schema: Tool,+) -> Tool:+ _ = schema.input_parameters["properties"].pop("page", None)+ schema.input_parameters["required"] = ["size"]+ return schema++tools = composio.tools.get(+ user_id=user_id,+ tools=["HACKERNEWS_GET_LATEST_POSTS", "HACKERNEWS_GET_USER"],+ modifiers=[+ modify_schema,+ ]+)```</CodeGroup>@@ -114,6 +135,52 @@ console.log(response.choices[0].message.tool_calls);```python Python maxLines=60 wordWrap+from openai import OpenAI+from composio import Composio, schema_modifier+from composio.types import Tool+from composio_openai import OpenAIProvider+++@schema_modifier(tools=["HACKERNEWS_GET_LATEST_POSTS"])+def modify_schema(+ tool: str,+ toolkit: str,+ schema: Tool,+) -> Tool:+ _ = schema.input_parameters["properties"].pop("page", None)+ schema.input_parameters["required"] = ["size"]+ return schema++# Initialize tools.+openai_client = OpenAI()+composio = Composio(provider=OpenAIProvider())++# Define task.+task = "Star a repo composiohq/composio on GitHub"++# Get GitHub tools that are pre-configured+tools = composio.tools.get(+ user_id="default",+ tools=['HACKERNEWS_GET_LATEST_POSTS', 'HACKERNEWS_GET_USER'],+ modifiers=[+ modify_schema,+ ],+)++# Get response from the LLM+response = openai_client.chat.completions.create(+ model="gpt-4o-mini",+ tools=tools,+ messages=[+ {"role": "system", "content": "You are a helpful assistant."},+ {"role": "user", "content": task},+ ],+)+print(response)++# Execute the function calls.+result = composio.provider.handle_tool_calls(response=response, user_id="default")+print(result)```</CodeGroup>