Table of Contents

πŸ‘‰ Try the demo: https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/agents/web_search_assistant

Web Search Assistant for C# .NET Applications


🎯 Purpose of the Demo

The Web Search Assistant demo shows how to use LM-Kit.NET to build a general-purpose assistant that autonomously decides when to search the web. Unlike research agents that always search, this assistant behaves like ChatGPT or Copilot: it answers casual questions from its own knowledge and only searches the web when it needs fresh, factual, or real-time information.

This is the reference demo for integrating the built-in WebSearchTool into a conversational assistant.

The sample shows how to:

  • Register the built-in WebSearchTool with a MultiTurnConversation in a single line of code.
  • Let the LLM autonomously decide when web search is needed, based on the system prompt.
  • Provide full call-flow visibility with color-coded streaming output (reasoning, tool calls, responses).
  • Swap between search providers (DuckDuckGo, Brave, Tavily, Serper) with minimal code changes.

πŸ‘₯ Who Should Use This Demo

  • Developers building chatbots: add web-grounded answers to any conversational AI application.
  • Product teams evaluating LM-Kit.NET: see the complete tool-calling flow from registration to autonomous invocation.
  • AI engineers: understand how a local LLM decides when to call external tools vs. answering from its own knowledge.
  • Startups and enterprises: build privacy-first assistants that run locally but can still access live web data.

πŸš€ What Problem It Solves

LLMs have a knowledge cutoff and can hallucinate when asked about recent events or specific facts. By equipping an assistant with web search, it can:

  • Answer questions about current events, news, and real-time data.
  • Provide accurate factual information with source citations.
  • Maintain the conversational fluency of a general-purpose assistant.
  • Avoid unnecessary searches for casual questions, saving latency and resources.

πŸ’» Demo Application Overview

Console application that:

  • Lets you select a language model from a curated list (or paste a custom URI).
  • Creates a MultiTurnConversation with WebSearchTool and DateTimeTool registered.
  • Enters an interactive chat loop with full streaming output.
  • Color-codes every phase of the call flow so you can see exactly what happens.

✨ Key Features

  • One-line tool registration: chat.Tools.Register(BuiltInTools.WebSearch) is all it takes.
  • Autonomous tool calling: the model decides when to search based on the system prompt.
  • DuckDuckGo by default: no API key required, works out of the box.
  • Provider switching: swap to Brave, Tavily, or Serper with one line of code.
  • DateTimeTool: the model knows the current date for time-sensitive queries.
  • Call-flow visibility: reasoning (blue), tool calls (red), responses (white), stats (gray).
  • Special commands: /reset clears history, /regenerate retries, /continue extends the last response.

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   User Input    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Web Search     β”‚
β”‚  Assistant      β”‚
β”‚  (MultiTurn     β”‚
β”‚   Conversation) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”
    β”‚  Tools  β”‚
    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
    β”‚WebSearch│──── DuckDuckGo / Brave / Tavily / Serper
    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
    β”‚DateTime │──── Current date/time awareness
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Tool Registration

using LMKit.Agents.Tools.BuiltIn;

MultiTurnConversation chat = new(model);

// One line to register web search (DuckDuckGo, no API key)
chat.Tools.Register(BuiltInTools.WebSearch);

// One line for date/time awareness
chat.Tools.Register(BuiltInTools.DateTimeNow);

Switching Providers

using LMKit.Agents.Tools.BuiltIn.Net;

// Brave Search (free tier at https://brave.com/search/api/)
var webSearch = BuiltInTools.CreateWebSearch(WebSearchTool.Provider.Brave, "YOUR_API_KEY");

// Tavily (AI-optimized search, https://tavily.com)
var webSearch = BuiltInTools.CreateWebSearch(WebSearchTool.Provider.Tavily, "YOUR_API_KEY");

// Serper (Google results via API, https://serper.dev)
var webSearch = BuiltInTools.CreateWebSearch(WebSearchTool.Provider.Serper, "YOUR_API_KEY");

βš™οΈ Getting Started

Prerequisites

  • .NET 8.0 or later
  • Sufficient VRAM for the selected model (4-18 GB)
  • Internet connectivity for web search

Download

git clone https://github.com/LM-Kit/lm-kit-net-samples
cd lm-kit-net-samples/console_net/agents/web_search_assistant

Run

dotnet build
dotnet run

Then:

  1. Select a model by typing 0-5, or paste a custom model URI.
  2. Start chatting. The assistant will automatically search the web when needed.
  3. Use /reset to clear history, /regenerate to retry, or /continue to extend.

πŸ”§ Troubleshooting

  • No search results: DuckDuckGo may throttle frequent requests. Space out queries or switch to Brave/Tavily.
  • Model does not search: try a larger model (GPT OSS 20B or GLM 4.7 Flash recommended). Smaller models may not reliably trigger tool calls.
  • Slow responses: web search adds network latency. Responses without search are faster.
  • Timeout: the default timeout is 3 minutes. For complex queries requiring multiple searches, this may not be enough.

πŸš€ Extend the Demo

  • Premium search: switch to Brave, Tavily, or Serper for higher quality results.
  • More tools: register additional built-in tools like BuiltInTools.CalcArithmetic or custom tools to expand capabilities.
  • RAG integration: combine web search with local document retrieval for hybrid grounding.
  • Agent framework: migrate from MultiTurnConversation to the Agent builder with PlanningStrategy.ReAct for multi-step research tasks.
  • Persistent sessions: save and restore conversation history across application restarts.

πŸ“š Additional Resources