Compare Ollama as a brilliant scholar locked in a windowless library with books only up to 2023. If you ask about today's news, they can't answer. Tool Calling is like slipping a smartphone under the door. The scholar uses it to search the web, reads the results, and then writes you a perfect summary. simple ASP.NET Core Minimal API that uses Ollama Tool Calling to perform a web search.
Note: We mock the actual search API call to keep the code short, but I've marked exactly where you plug in Bing, DuckDuckGo, or Tavily.
using System.Text.Json;
using System.Text.Json.Nodes;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/search", async (string query) =>
{
var client = new HttpClient();
var ollamaUrl = "http://localhost:11434/api/chat";
// 1. Define the "Smartphone" (The Web Search Tool)
var tools = new object[] {
new {
type = "function",
function = new {
name = "web_search",
description = "Search the web for current information, news, or facts.",
parameters = new {
type = "object",
properties = new {
query = new { type = "string", description = "The search query to look up" }
},
required = new[] { "query" }
}
}
}
};
// 2. Ask Ollama the question and give it the tool
var initialPayload = new {
model = "llama3.1", // Must be a model that supports tools!
messages = new[] { new { role = "user", content = query } },
tools = tools,
stream = false
};
var response = await client.PostAsJsonAsync(ollamaUrl, initialPayload);
var result = await response.Content.ReadFromJsonAsync();
var message = result["message"];
// 3. Check if Ollama wants to use the smartphone (Tool Call)
if (message["tool_calls"] is JsonArray toolCalls)
{
// Extract the search query Ollama wants to make
var searchQuery = toolCalls[0]["function"]["arguments"]["query"].GetValue();
// --- ?? REAL WEB SEARCH HAPPENS HERE ---
// In production, call your Bing/DuckDuckGo/Tavily API here.
var mockSearchResults = $"[Web Result] Breaking news about: {searchQuery}. The weather is 25°C.";
// 4. Feed the search results back to Ollama for a final summary
var finalPayload = new {
model = "llama3.1",
messages = new object[] {
new { role = "user", content = query },
message, // The tool call message from Ollama
new { role = "tool", content = mockSearchResults }
},
stream = false
};
var finalResponse = await client.PostAsJsonAsync(ollamaUrl, finalPayload);
var finalResult = await finalResponse.Content.ReadFromJsonAsync();
return finalResult["message"]["content"].GetValue();
}
return "Ollama answered directly without needing a web search.";
});
app.Run();
How it Works (Step-by-Step for your slides)
The Setup: We define a web_search tool so Ollama knows it has the ability to search.
The First Ask: We send the user's question to Ollama. Instead of answering, Ollama replies with a tool_call (e.g., "I need to search for 'Latest AI news'").
The Execution: Our C# code catches that request, executes the actual web search (via an API), and grabs the results.
The Final Answer: We send the web results back to Ollama. Ollama reads the raw web data and generates a clean, human-readable summary for the user.
"Internal Company Knowledge Bot" Imagine a company uses SharePoint for documents, but it's hard to search. You can build an ASP.NET API where the "Tool" isn't the web, but an Internal SQL Database or SharePoint API. When an employee asks, "What is the policy on work-from-home?", Ollama triggers the tool, fetches the exact PDF text from the database, and summarizes it instantly! Not all models support tools! For this to work in Ollama, they must pull a tool-calling capable model like llama3.1, mistral, or qwen2.5. Standard llama3 (8B) will just ignore the tool definition.
Tuhin PaulPosted Jun 10, 2026, 6:57 AM
Compare Ollama as a brilliant scholar locked in a windowless library with books only up to 2023. If you ask about today's news, they can't answer. Tool Calling is like slipping a smartphone under the door. The scholar uses it to search the web, reads the results, and then writes you a perfect summary. simple ASP.NET Core Minimal API that uses Ollama Tool Calling to perform a web search.
Note: We mock the actual search API call to keep the code short, but I've marked exactly where you plug in Bing, DuckDuckGo, or Tavily.
How it Works (Step-by-Step for your slides)
The Setup: We define a
web_searchtool so Ollama knows it has the ability to search.The First Ask: We send the user's question to Ollama. Instead of answering, Ollama replies with a
tool_call(e.g., "I need to search for 'Latest AI news'").The Execution: Our C# code catches that request, executes the actual web search (via an API), and grabs the results.
The Final Answer: We send the web results back to Ollama. Ollama reads the raw web data and generates a clean, human-readable summary for the user.
"Internal Company Knowledge Bot"
Imagine a company uses SharePoint for documents, but it's hard to search. You can build an ASP.NET API where the "Tool" isn't the web, but an Internal SQL Database or SharePoint API. When an employee asks, "What is the policy on work-from-home?", Ollama triggers the tool, fetches the exact PDF text from the database, and summarizes it instantly! Not all models support tools! For this to work in Ollama, they must pull a tool-calling capable model like
llama3.1,mistral, orqwen2.5. Standardllama3(8B) will just ignore the tool definition.