Add Tools to a Workflow with NeMo Agent Toolkit#

The Customizing a Workflow tutorial demonstrates how to customize a workflow by overriding parameters. This tutorial will show 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.

NeMo Agent 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:

nat info components -t function

The examples/getting_started/simple_web_query/configs/config.yml workflow defines a tool to query the LangSmith User Guide. This is defined in the functions 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 LangChain/LangGraph, if you run:

nat run --config_file examples/getting_started/simple_web_query/configs/config.yml --input "How do I trace only specific parts of my LangChain application?"

The output may be similar to the following:

Workflow Result:
["Unfortunately, the provided webpages do not provide specific instructions on how to trace only specific parts of a LangChain application using LangSmith. However, they do provide information on how to set up LangSmith tracing with LangChain and how to use LangSmith's observability features to analyze traces and configure metrics, dashboards, and alerts. It is recommended to refer to the how-to guide for setting up LangSmith with LangChain or LangGraph for more information."]

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
  langchain_query:
    _type: webpage_query
    webpage_url: https://docs.smith.langchain.com/observability/how_to_guides/trace_with_langchain
    description: "Search for information about LangChain. For any questions about LangChain, 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, langchain_query, current_datetime]

Note

The resulting YAML is located at examples/documentation_guides/workflows/custom_workflow/custom_config.yml in the NeMo Agent Toolkit repository.

When you rerun the workflow with the updated configuration file:

nat run --config_file examples/documentation_guides/workflows/custom_workflow/custom_config.yml \
  --input "How do I trace only specific parts of my LangChain application?"

We should receive output similar to:

Workflow Result:
['To trace only specific parts of a LangChain application, you can either manually pass in a LangChainTracer instance as a callback or use the tracing_v2_enabled context manager. Additionally, you can configure a LangChainTracer instance to trace a specific invocation.']

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. NeMo Agent Toolkit provides two web search tools: tavily_internet_search which utilizes the Tavily Search API, and exa_internet_search which utilizes the Exa Search API.