Skip to main content

What You’ll Build

An interactive chatbot that uses Tavily tools to answer questions with real-time web data. It dynamically chooses between lightweight search (for simple factual questions) and deep research (for complex, multi-source analysis) — then synthesizes answers with numbered citations.

View Source on GitHub

Architecture

Key behavior:
  • The agent can call search_and_format multiple times until it has enough information
  • The agent can only call stream_research once per query (comprehensive but expensive)
  • All responses include numbered citations linking to sources

Tools Used

Quick Start

Source File

How It Works

The chatbot exposes two tools to the LLM. The agent decides which to call based on the query:
  • search_and_format — wraps tavily_agent_toolkit.search_and_format to run parallel web searches across one or more queries. Accepts an optional time_range filter.
  • stream_research — calls Tavily’s research API in streaming mode via tavily_agent_toolkit.handle_research_stream, returning a comprehensive report.
The system prompt instructs the agent to pick the right tool:
This keeps costs low for quick lookups while enabling deep research when needed.
The chatbot runs a standard agent loop:
  1. Send the user message + tool definitions to the LLM
  2. If the LLM returns a tool call, execute it and feed the result back
  3. Repeat until the LLM returns a final text response
  4. Print the response with citations and continue the conversation
The system prompt enforces citation discipline:

Example Interaction

Key Parameters to Tune

Next Steps

Tools Reference

Full parameter docs for search_and_format and all other tools.

Company Intelligence

Add website crawling and extraction to your agent’s capabilities.