LangchainTools
IntroductionCopied!
LangchainTools is an integration class within the Mainframe-Orchestra framework that bridges the gap between Orchestra and Langchain's extensive toolkit ecosystem. This integration allows developers to incorporate Langchain's diverse set of tools into Orchestra agents, significantly expanding the capabilities of agents and workflows in Orchestra.
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 Orchestra 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 Orchestra library to wrap and use Langchain tools in Orchestra 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 WorksCopied!
LangchainTools acts as a wrapper and adapter for Langchain tools, making them compatible with Orchestra's agent and task system. It dynamically imports Langchain tools, wraps them in a Orchestra-friendly interface, and provides methods to list, retrieve, and use these tools within Orchestra agents.
The class handles the complexities of tool instantiation, input formatting, and output processing, presenting a unified and simplified API for Orchestra users. This abstraction allows developers to focus on designing their AI workflows rather than worrying about the intricacies of tool integration.
Why Use LangchainToolsCopied!
- Expanded Capabilities: Access a vast library of pre-built tools to enhance your AI agents' abilities.
- Simplified Integration: Easily incorporate complex functionalities into your Orchestra workflows without extensive coding.
- Flexibility: Mix and match tools from different sources, combining Orchestra'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 Orchestra 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.
FeaturesCopied!
- List all available Langchain tools
- Retrieve information about specific tools
- Wrap and use Langchain tools in Orchestra agents
UsageCopied!
Listing Available ToolsCopied!
To get a list of all available Langchain tools, use the list_available_tools()
method:
from mainframe_orchestra 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 InformationCopied!
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 ToolsCopied!
To assign a specific langchain tool to your Orchestra agent, use the get_tool()
method:
from mainframe_orchestra import LangchainTools
# Retrieve the DuckDuckGoSearchRun tool
duckduckgosearch = LangchainTools.get_tool("DuckDuckGoSearchRun")
ExampleCopied!
Here's a complete example demonstrating how to use the LangchainTools class:
import os
from mainframe_orchestra 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 ReferenceCopied!
LangchainTools.list_available_tools() -> List[str]
Copied!
Returns a list of names of all available Langchain tools.
LangchainTools.get_tool_info(tool_name: str) -> Dict[str, str]
Copied!
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
Copied!
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.
NotesCopied!
- The LangchainTools class dynamically imports and wraps Langchain tools, making them compatible with the Orchestra 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 Orchestra[langchain_tools]
.