https://linen.dev logo
s
Hi, I’m exploring the integration of Composio with LangChain’s create_agent. I noticed that create_agent requires tools to be preconfigured, but Composio loads tools based on a user_id. My concern is about production efficiency: if I need to compile the graph for every request just to provide the user_id, this seems very inefficient. Is there a way to: Customize or inject the user_id through context or a middleware? Access the tool definitions without providing a user_id for every request? Essentially, I’m looking for a pattern to manage tools per user without recompiling the entire graph each time. Any guidance or best practices would be appreciated.
u
Hey @Skkippie, I'd recommend using tool-router sessions for your use case. Tool-router has meta tools like
COMPOSIO_SEARCH_TOOLS
,
COMPOSIO_MULTI_EXECUTE_TOOL
,
COMPOSIO_MANAGE_CONNECTIONS
, etc. Try creating a session.tools() which returns meta tools that are identical for all users. Compile your graph once with these tools. The meta tools handle tool discovery and execution dynamically using the user's credentials so you should be good to run these tools to fetch and use dynamically instead of pre-configuring. —[Meta Tools](https://docs.composio.dev/docs/tools-and-toolkits). You can use out chatbot on Docs or Dashboard to understand more about tool-router and how it works. It should be pretty helpful.