π 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
WebSearchToolwith aMultiTurnConversationin 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
MultiTurnConversationwithWebSearchToolandDateTimeToolregistered. - 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:
/resetclears history,/regenerateretries,/continueextends 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:
- Select a model by typing 0-5, or paste a custom model URI.
- Start chatting. The assistant will automatically search the web when needed.
- Use
/resetto clear history,/regenerateto retry, or/continueto 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.CalcArithmeticor custom tools to expand capabilities. - RAG integration: combine web search with local document retrieval for hybrid grounding.
- Agent framework: migrate from
MultiTurnConversationto theAgentbuilder withPlanningStrategy.ReActfor multi-step research tasks. - Persistent sessions: save and restore conversation history across application restarts.