Add Tools to a Workflow#
The Customizing a Workflow tutorial demonstrates how to customize a workflow by overriding parameters. This tutorial will demonstrate how to add new tools to a workflow. Adding a new tool to a workflow requires copying and modifying the workflow configuration file, which, in effect, creates a new customized workflow.
AIQ toolkit includes several built-in tools (functions) that can be used in any workflow. To query for a list of installed tools, run the following command:
aiq info components -t function
The current workflow defines a tool to query the LangSmith User Guide. This is defined in the tools
section of the configuration file:
functions:
webpage_query:
_type: webpage_query
webpage_url: https://docs.smith.langchain.com
description: "Search for information about LangSmith. For any questions about LangSmith, you must use this tool!"
embedder_name: nv-embedqa-e5-v5
chunk_size: 512
However, the workflow is unaware of some related technologies, such as LangGraph, if you run:
aiq run --config_file examples/simple/configs/config.yml --input "How does LangSmith interact with tools like LangGraph?"
The output will be similar to the following:
Workflow Result:
["Unfortunately, I couldn't find any information about LangSmith's interaction with LangGraph. The user guide does not mention LangGraph, and I couldn't find any relevant information through the webpage queries."]
You can solve this by updating the workflow to also query the LangGraph Quickstart guide.
To do this, create a copy of the original workflow configuration file. To add the LangGraph query tool to the workflow, update the YAML file updating the functions
section from:
functions:
webpage_query:
_type: webpage_query
webpage_url: https://docs.smith.langchain.com
description: "Search for information about LangSmith. For any questions about LangSmith, you must use this tool!"
embedder_name: nv-embedqa-e5-v5
chunk_size: 512
to:
functions:
langsmith_query:
_type: webpage_query
webpage_url: https://docs.smith.langchain.com
description: "Search for information about LangSmith. For any questions about LangSmith, you must use this tool!"
embedder_name: nv-embedqa-e5-v5
chunk_size: 512
langgraph_query:
_type: webpage_query
webpage_url: https://langchain-ai.github.io/langgraph/tutorials/introduction
description: "Search for information about LangGraph. For any questions about LangGraph, you must use this tool!"
embedder_name: nv-embedqa-e5-v5
chunk_size: 512
Since you now have two instances of the webpage_query
tool, you need to update the name of the first tool to langsmith_query
.
Finally, update the workflow.tool_names
section to include the new tool from:
workflow:
_type: react_agent
tool_names: [webpage_query, current_datetime]
to:
workflow:
_type: react_agent
tool_names: [langsmith_query, langgraph_query, current_datetime]
Note
The resulting YAML is located at examples/documentation_guides/workflows/custom_workflow/custom_config.yml
in the AIQ toolkit repository.
When you rerun the workflow with the updated configuration file:
aiq run --config_file examples/documentation_guides/workflows/custom_workflow/custom_config.yml \
--input "How does LangSmith interact with tools like LangGraph?"
We should receive output similar to:
Workflow Result:
['LangSmith interacts with LangGraph as part of an out-of-the-box solution for building complex, production-ready features with LLMs. LangGraph works in conjunction with LangSmith to provide this solution, and they are both part of the LangChain ecosystem.']
Alternate Method Using a Web Search Tool#
Adding individual web pages to a workflow can be cumbersome, especially when dealing with multiple web pages. An alternative method is to use a web search tool. One of the tools available in AIQ toolkit is the tavily_internet_search
tool, which utilizes the Tavily Search API.
The tavily_internet_search
tool is part of the aiqtoolkit[langchain]
package, to install the package run:
# local package install from source
uv pip install -e '.[langchain]'
Prior to using the tavily_internet_search
tool, create an account at tavily.com
and obtain an API key. Once obtained, set the TAVILY_API_KEY
environment variable to the API key:
export TAVILY_API_KEY=<YOUR_TAVILY_API_KEY>
We will now update the functions
section of the configuration file replacing the two webpage_query
tools with a single tavily_internet_search
tool entry:
functions:
internet_search:
_type: tavily_internet_search
current_datetime:
_type: current_datetime
Next, update the workflow.tool_names
section to include the new tool:
workflow:
_type: react_agent
tool_names: [internet_search, current_datetime]
The resulting configuration file is located at examples/documentation_guides/workflows/custom_workflow/search_config.yml
in the AIQ toolkit repository.
When you re-run the workflow with the updated configuration file:
aiq run --config_file examples/documentation_guides/workflows/custom_workflow/search_config.yml \
--input "How does LangSmith interact with tools like LangGraph?"
Which will then yield a slightly different result to the same question:
Workflow Result:
['LangSmith interacts with LangGraph through the LangChain ecosystem, which provides the foundation for building LLM applications. LangGraph provides real-time monitoring, tracing, and debugging capabilities, and it can be used in conjunction with LangSmith to build robust agentic applications.']