Core Steps
- Initialize your LLM: Choose and configure the language model you want your agent to use (e.g.,
ChatOpenAI). - Initialize
ToolManager: This is the central registry for your MCP tools. - Load Applications and Register Tools:
- Load your desired
Applicationinstances (e.g., usingapp_from_slugor direct instantiation). - Register their tools with the
ToolManagerusingtool_manager.register_tools_from_app(your_app_instance). - Add any custom standalone tools using
tool_manager.add_tool(your_function).
- Load your desired
- Convert Tools to Langchain Format:
The
ToolManagercan list tools in a format compatible with Langchain.This uses theconvert_tool_to_langchain_tooladapter internally, which wraps your MCP tool’srunmethod within a LangchainStructuredTool. - Create a Langchain Agent:
Use a Langchain agent constructor, like
create_react_agentfromlanggraph.prebuilt, passing thellmand thelangchain_tools.The ReAct (Reasoning and Acting) agent is a common choice that works well with tools. - Invoke the Agent:
Call the agent with user input.
ToolManager, registering tools (either from applications or custom functions), converting them, and then passing them to a Langchain agent is fundamental. The subsequent example guides will build upon this by using tools from specific MCP applications.