Bismuth
08/10/2025, 3:20 PMpy
from composio import Composio
from openai import OpenAI
from app.config.settings import settings
from composio_langchain import LangchainProvider
import logging
logger = logging.getLogger(__name__)
class ComposioService:
def __init__(self):
self.composio = Composio(provider=LangchainProvider(),api_key="")
# self.openai = OpenAI(api_key=settings.OPENAI_API_KEY)
def get_notion_tools(self,user_id: str):
"""
Returns Composio-managed Notion tools for a specific user.
"""
return self.composio.tools.get(user_id=user_id, toolkits=["NOTION"])
composio_service = ComposioService()
py
],
"creative": [
image_tool.generate_image,
],
"weather": [
weather_tool.get_weather,
],
"notion": [
*composio_service.get_notion_tools(user_id="688bc1c38769a8edbc71954a")
],
}
# Map categories to their required integrations
CATEGORY_INTEGRATION_REQUIREMENTS = {
"mail": "gmail",
"calendar": "google_calendar",
"google_docs": "google_docs",
# "productivity", "goal_tracking", "documents", "search", "memory", "development", "creative", "weather" don't require integrations
}
# Define tools that should always be accessible to the agent directly
ALWAYS_AVAILABLE_TOOLS = [
search_tool.web_search_tool,
search_tool.deep_research_tool,
webpage_tool.fetch_webpages,
file_tools.query_file,
]
rn im hardcoding the user_id in the tool registry and user_id i get from the requestComposio Support Agent
08/10/2025, 3:40 PMcomposio.connected_accounts.list() and use the user_id from the payload. You can pass filter as parameters to the function like toolkit_slugs, limit, etc.
Let me know if this resolves the query.Bismuth
08/10/2025, 3:56 PMBismuth
08/10/2025, 3:57 PM"notion": [
*composio_service.get_notion_tools(user_id="688bc1c38769a8edbc71954a")
],Bismuth
08/10/2025, 3:57 PMBismuth
08/10/2025, 3:57 PMComposio Support Agent
08/10/2025, 7:09 PMuser_id dynamically?Bismuth
08/11/2025, 3:29 AMComposio Support Agent
08/11/2025, 6:52 AM.list() or .get() connected account to dynamically fetch the use_id . Let me know if it works for you.Bismuth
08/14/2025, 12:44 PMBismuth
08/14/2025, 2:06 PMBismuth
08/14/2025, 2:06 PMComposio Support Agent
08/14/2025, 2:12 PMuser_id is defined to associate a connected account to your API calls, when you are trying to use APIs(get tools, etc) you'll need to specify the connected account which is done using user_id and it is mandatory. I've attached an image for your reference.
https://cdn.discordapp.com/attachments/1404122105343246347/1405554703990784001/Screenshot_2025-08-14_at_19.41.24.png?ex=689f4053&is=689deed3&hm=0e07336a9db815bd4b0b881b9622c1d1bb03fb894870e5b817c66229d96b1d0b&Bismuth
08/14/2025, 2:45 PMBismuth
08/14/2025, 2:47 PMComposio Support Agent
08/14/2025, 2:52 PMBismuth
08/14/2025, 3:06 PMabhishekpatil4
08/14/2025, 3:34 PMbefore_execute, checkout the guide [here](https://docs.composio.dev/docs/modifiers/before-execution#before-execution-modifiers)
here's a snip for ref, you can set the userId like this:
@before_execute(tools=["GMAIL_SEND_EMAIL"])
def before_execute_modifier(
tool: str,
toolkit: str,
params: ToolExecuteParams,
) -> ToolExecuteParams:
params["user_id"] = "<user_id>"
return params
Lmk if this helps.Bismuth
08/14/2025, 3:47 PMBismuth
08/14/2025, 3:47 PMabhishekpatil4
08/14/2025, 3:51 PMBismuth
08/14/2025, 4:12 PMabhishekpatil4
08/14/2025, 4:45 PMbefore_execute should help with your use case.Bismuth
08/14/2025, 5:03 PMpy
TOOLS_BY_CATEGORY = {
"mail": [
*mail_tool.tools,
],
"productivity": [
*todo_tool.tools,
*reminder_tool.tools,
],
"calendar": [
*calendar_tool.tools,
],
"goal_tracking": [
*goal_tool.tools,
],
"google_docs": [
*google_docs_tool.tools,
],
"documents": [
document_tool.generate_document,
file_tools.query_file,
],
"search": [
search_tool.web_search_tool,
search_tool.deep_research_tool,
webpage_tool.fetch_webpages,
],
"memory": [
*memory_tools.tools,
],
"development": [
code_exec_tool.execute_code,
flowchart_tool.create_flowchart,
],
"creative": [
image_tool.generate_image,
],
"weather": [
weather_tool.get_weather,
],
"notion": [
*composio_service.get_notion_tools(user_id="688bc1c38769a8edbc71954a")
],
"google_sheet": [
*composio_service.get_google_sheet_tools(user_id="688bc1c38769a8edbc71954a")
],
"twitter": [
*composio_service.get_x_tools(user_id="688bc1c38769a8edbc71954a")
],
}
# Map categories to their required integrations
CATEGORY_INTEGRATION_REQUIREMENTS = {
"mail": "gmail",
"calendar": "google_calendar",
"google_docs": "google_docs",
}
# Define tools that should always be accessible to the agent directly
ALWAYS_AVAILABLE_TOOLS = [
search_tool.web_search_tool,
search_tool.deep_research_tool,
webpage_tool.fetch_webpages,
file_tools.query_file,
]
tools = [
tool
for category_tools in TOOLS_BY_CATEGORY.values()
for tool in category_tools
if tool not in ALWAYS_AVAILABLE_TOOLS
]
tool_names = [tool.name for tool in tools]
here i have registered the tools that were made my me but now i wanna use composio but these tools i have registered from the composio need user_id which i can't get when first application is build using langgraphBismuth
08/14/2025, 5:04 PMBismuth
08/14/2025, 5:35 PMcreate_twitter_post toolBismuth
08/14/2025, 8:48 PMpy
@schema_modifier(toolkits=["NOTION"])
def inject_user_id(schema, context):
"""
Dynamically inject user_id from RunnableConfig into Composio tools at runtime.
"""
runnable_config = context.get("config")
print("this is schema modifier runnable config",runnable_config)
print("this is schema modifier context",context)
if runnable_config:
metadata = runnable_config.get("metadata", {})
user_id = metadata.get("user_id")
if user_id:
schema["args"]["user_id"] = user_id
schema["description"] = f"if user_id is not provided use this {user_id}"
return schema
is this correct way of passing?Bismuth
08/14/2025, 10:02 PMpy
def get_notion_tools(self, user_id: str):
# self.composio.tools._get()
# self.composio.tools.get_raw_composio_tools()
return self.composio.tools.get(user_id=user_id, toolkits=["NOTION"],modifiers=[inject_user_id])
but it seems like schema modifer isn't being called or connected when tools are calledabhishekpatil4
08/15/2025, 6:38 AMabhishekpatil4
08/15/2025, 6:45 AMBismuth
08/15/2025, 6:53 AMstructuredtool but isn't there any way i can use the runnable config in modifier or before_executeBismuth
08/15/2025, 6:55 AMBismuth
08/15/2025, 6:56 AMabhishekpatil4
08/15/2025, 7:16 AMBismuth
08/15/2025, 7:19 AMabhishekpatil4
08/15/2025, 7:20 AMBismuth
08/15/2025, 7:33 AMabhishekpatil4
08/15/2025, 7:50 AMBismuth
08/15/2025, 5:14 PMdhruvmaradiya
08/15/2025, 5:53 PM_wrap_action method
python
# Add RunnableConfig param with a collision-safe name
parameters.append(
Parameter(
"__runnable_config__",
kind=Parameter.KEYWORD_ONLY,
default=None,
annotation=RunnableConfig,
)
)
and one sneaky workaround, below is required bcz langchain identifies parameter of RunnableConfig type using annotations.
python
# Create __annotations__ only for __runnable_config__
action_func.__annotations__ = {"__runnable_config__": RunnableConfig}
after doing this, we can get RunnableConfig in before_execute modifier like this
python
@before_execute()
def before_execute_notion(
tool,
toolkit,
params: ToolExecuteParams
):
arguments = params.get("arguments", {})
config = arguments.pop("__runnable_config__")abhishekpatil4
08/16/2025, 5:28 AMBismuth
08/16/2025, 6:42 AMpy
from composio_client import Composio
client = Composio(
api_key="My API Key",
)
tools = client.tools.list()
print(tools.current_page)Bismuth
08/16/2025, 6:42 AMBismuth
08/16/2025, 7:07 AMBismuth
08/16/2025, 7:07 AMBismuth
08/16/2025, 7:07 AMpy
def get_tools(self, tool_kit: str):
tools = self.composio.tools.get(
user_id="",
toolkits=[tool_kit],
)
tools_name = [tool.name for tool in tools]
@before_execute(tools=tools_name)
def before_execute_tools(
_,
__,
params: ToolExecuteParams,
):
arguments = params.get("arguments", {})
if not arguments:
return params
config = arguments.pop("__runnable_config__", None)
if config is None:
return params
metadata = config.get("metadata", {}) if isinstance(config, dict) else {}
if not metadata:
return params
user_id = metadata.get("user_id")
if user_id is None:
return params
params["user_id"] = user_id
return params
return self.composio.tools.get(
user_id="",
toolkits=["NOTION"],
modifiers=[before_execute_tools],
)Bismuth
08/16/2025, 8:29 AMBismuth
08/16/2025, 8:37 AMrefresh_token and access_token for the mailComposio Support Agent
08/16/2025, 9:57 AMBismuth
08/16/2025, 10:52 AMBismuth
08/16/2025, 10:54 AMBismuth
08/17/2025, 5:23 AMComposio Support Agent
08/17/2025, 7:15 AMBismuth
08/17/2025, 8:08 AMabhishekpatil4
08/17/2025, 2:02 PMBismuth
08/17/2025, 2:03 PMabhishekpatil4
08/18/2025, 6:59 AMafter_execute runs synchronously after a tool execution completes, so not sure about that.
If you want a function to run after every tool execution configure it this way @after_execute(tools=[], toolkits=[])Bismuth
08/21/2025, 2:50 PMcomposio.get method email has tons of tools which i directly get from the toolkit but i wanna exlcude few tools, it would be helpful if we have a exclude_tools parameter as well, if team is busy on something i would love to give a PRabhishekpatil4
08/22/2025, 7:26 AM