LangchainTools
Introduction
LangchainTools is an integration class within the TaskflowAI framework that bridges the gap between TaskflowAI and Langchain's extensive toolkit ecosystem. This integration allows developers to incorporate Langchain's diverse set of tools into TaskflowAI agents, significantly expanding the capabilities of agents and workflows in TaskflowAI.
By leveraging LangchainTools, developers can access a wide array of pre-built tools from Langchain, ranging from web search engines and language translators to code interpreters and database connectors. This integration not only enhances the functionality of TaskflowAI agents but also reduces development time by eliminating the need to recreate these tools from scratch.
Note: LangchainTools is built on top of the Langchain framework, and it is not a Langchain library. It is a TaskflowAI library to wrap and use Langchain tools in TaskflowAI agents. It is in Beta and under development, so please bear with the rough edges and feel free to submit an issue or PR.
How It Works
LangchainTools acts as a wrapper and adapter for Langchain tools, making them compatible with TaskflowAI's agent and task system. It dynamically imports Langchain tools, wraps them in a TaskflowAI-friendly interface, and provides methods to list, retrieve, and use these tools within TaskflowAI agents.
The class handles the complexities of tool instantiation, input formatting, and output processing, presenting a unified and simplified API for TaskflowAI users. This abstraction allows developers to focus on designing their AI workflows rather than worrying about the intricacies of tool integration.
Why Use LangchainTools
- Expanded Capabilities: Access a vast library of pre-built tools to enhance your AI agents' abilities.
- Simplified Integration: Easily incorporate complex functionalities into your TaskflowAI workflows without extensive coding.
- Flexibility: Mix and match tools from different sources, combining TaskflowAI's native tools with Langchain's offerings.
- Time-Saving: Leverage existing, well-tested tools instead of developing them from scratch.
- Community Support: Benefit from the ongoing development and improvements in both the TaskflowAI and Langchain communities.
By using LangchainTools, developers can create more versatile, powerful, and efficient AI agents capable of handling a wide range of tasks across various domains.
Features
- List all available Langchain tools
- Retrieve information about specific tools
- Wrap and use Langchain tools in TaskflowAI agents
Usage
Listing Available Tools
To get a list of all available Langchain tools, use the list_available_tools()
method:
from taskflowai import LangchainTools
available_tools = LangchainTools.list_available_tools()
print("Available tools:", available_tools)
This will output a list of available tools, which may include:
['AINAppOps',
'AINOwnerOps',
'AINRuleOps',
'AINTransfer',
'AINValueOps',
'AIPluginTool',
'APIOperation',
'ArxivQueryRun',
'AskNewsSearch',
'AzureAiServicesDocumentIntelligenceTool',
'AzureAiServicesImageAnalysisTool',
'AzureAiServicesSpeechToTextTool',
'AzureAiServicesTextToSpeechTool',
'AzureAiServicesTextAnalyticsForHealthTool',
'AzureCogsFormRecognizerTool',
'AzureCogsImageAnalysisTool',
'AzureCogsSpeech2TextTool',
'AzureCogsText2SpeechTool',
'AzureCogsTextAnalyticsHealthTool',
'BalanceSheets',
'BaseGraphQLTool',
'BaseRequestsTool',
'BaseSQLDatabaseTool',
'BaseSparkSQLTool',
'BaseTool',
'BearlyInterpreterTool',
...
Getting Tool Information
To retrieve information about a specific tool, use the get_tool_info()
method:
tool_info = LangchainTools.get_tool_info("DuckDuckGoSearchRun")
print("DuckDuckGoSearchRun info:", tool_info)
This will return a brief description of the tool.
DuckDuckGoSearchRun info: {'name': 'duckduckgo_search', 'description': 'A wrapper around DuckDuckGo Search. Useful for when you need to answer questions about current events. Input should be a search query.', 'module_path': 'langchain_community.tools.ddg_search.tool'}
Retrieving and Using Tools
To assign a specific langchain tool to your TaskflowAI agent, use the get_tool()
method:
from taskflowai import LangchainTools
# Retrieve the DuckDuckGoSearchRun tool
duckduckgosearch = LangchainTools.get_tool("DuckDuckGoSearchRun")
Example
Here's a complete example demonstrating how to use the LangchainTools class:
import os
from taskflowai import Task, Agent, OpenrouterModels, set_verbosity, LangchainTools
set_verbosity(1)
# Get the DuckDuckGoSearchRun tool
duckduckgosearch = LangchainTools.get_tool("DuckDuckGoSearchRun")
# Create an agent with the DuckDuckGoSearchRun tool
web_researcher = Agent(
role="Web Searcher",
goal="Search the web for information",
tools={duckduckgosearch},
llm=OpenrouterModels.llama_3_1_405b_instruct
)
# Create and execute a task
task_result = Task.create(
agent=web_researcher,
instruction="Search the web for information about NVDA and summarize the results."
)
print(task_result)
API Reference
LangchainTools.list_available_tools() -> List[str]
Returns a list of names of all available Langchain tools.
LangchainTools.get_tool_info(tool_name: str) -> Dict[str, str]
Retrieves information about a specific Langchain tool.
tool_name
(str): The name of the tool to retrieve information for.
Returns a dictionary containing the tool's name, description, and module path.
Raises:
ValueError
: If an unknown tool name is provided.
LangchainTools.get_tool(tool_name: str) -> Callable
Retrieves and wraps a specified Langchain tool.
tool_name
(str): Name of the Langchain tool to retrieve.
Returns a wrapped Langchain tool as a callable function.
Raises:
ValueError
: If an unknown tool name is provided.ImportError
: If Langchain dependencies are not installed.
Notes
- The LangchainTools class dynamically imports and wraps Langchain tools, making them compatible with the TaskflowAI framework.
- Ensure that you have the necessary permissions and API keys set up for the specific Langchain tools you intend to use.
- Some tools may require additional configuration or dependencies. Refer to the Langchain documentation for specific tool requirements.
- To use LangchainTools, you need to install the required packages with
pip install taskflowai[langchain_tools]
.