This guide assumes that you have completed the Quickstart.
- Retrieving information from a database
- Performing a calculation
- Performing an API call
- … and much more!
1
Define a tool for the agent to use
To get started, we need to define the tool and how the agent should use it. For our company research assistant, a web search tool is crucial for gathering current information. This guide adds a web search tool powered by Tavily to search the web.
You may need to install additional dependencies such as
zod
, zod-to-json-schema
, and @tavily/core
. You can install them using npm:2
Instruct the agent to use the tool
Now that the agent has a tool, we need to teach it when and how to use it. A system prompt is the perfect way to provide these instructions. We can tell the agent to use the Here’s a sample system prompt:
web_search
tool whenever it needs current information to answer a question about a company.If you are unfamiliar with system prompts, you can learn more about them in the Using System Prompts guide.
app/api/chat/systemPrompt.ts
3
Pass the tool to the agent
Now you just need to pass the tool call function to the agent so it can start using the tool. If you’ve followed the Quickstart guide, you can
pass the tool call function to the agent by making a couple of small changes:To view the full
- Import the
tools
andsystemPrompt
to yourroute.ts
file. - Replace the
create
call in yourroute.ts
file with a convenientrunTools
call that takes the list of tools available to the agent.
route.ts
code, you can expand the following codeblock:4
Test it out!
Your company research assistant is now equipped with a powerful web search tool. Try asking it for recent news about a company to see it in action.
