autogen_ext.tools.langchain#
- class LangChainToolAdapter(langchain_tool: LangChainTool)[source]#
- Bases: - BaseTool[- BaseModel,- Any]- Allows you to wrap a LangChain tool and make it available to AutoGen. - Note - This class requires the - langchainextra for the- autogen-extpackage.- Parameters:
- langchain_tool (LangChainTool) – A LangChain tool to wrap 
 - Examples: - Use the PythonAstREPLTool from the langchain_experimental package to create a tool that allows you to interact with a Pandas DataFrame. - import asyncio import pandas as pd from langchain_experimental.tools.python.tool import PythonAstREPLTool from autogen_ext.tools.langchain import LangChainToolAdapter from autogen_ext.models.openai import OpenAIChatCompletionClient from autogen_agentchat.messages import TextMessage from autogen_agentchat.agents import AssistantAgent from autogen_agentchat.ui import Console from autogen_core import CancellationToken async def main() -> None: df = pd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv") # type: ignore tool = LangChainToolAdapter(PythonAstREPLTool(locals={"df": df})) model_client = OpenAIChatCompletionClient(model="gpt-4o") agent = AssistantAgent( "assistant", tools=[tool], model_client=model_client, system_message="Use the `df` variable to access the dataset.", ) await Console( agent.on_messages_stream( [TextMessage(content="What's the average age of the passengers?", source="user")], CancellationToken() ) ) asyncio.run(main()) - async run(args: BaseModel, cancellation_token: CancellationToken) Any[source]#