Built-in tools
LogicGrid.Tools ships five tools — calculator, datetime, HTTP GET,
JSON extract, and web search — covering most real-world agent needs.
dotnet add package LogicGrid.Tools
All five derive from ToolBase<TArgs>, so the LLM sees a typed
JSON schema for each. Attach them via the tools: parameter on
Agent<T>, or via the Tools override on AgentBase<T>.
using LogicGrid.Core.Tools;
using LogicGrid.Tools.Tools;
IAgent assistant = new Agent<string>(
name: "Assistant",
description: "General-purpose assistant.",
systemPrompt:
"You are a helpful assistant. Use tools whenever real data " +
"would beat your training-cutoff guesses.",
llm: llm,
tools: new ToolBase[]
{
new CalculatorTool(),
new DateTimeTool(),
new HttpGetTool(),
new JsonExtractTool(),
});
CalculatorTool
public sealed class CalculatorTool : ToolBase<CalculatorArgs>
{
public CalculatorTool();
}
public sealed class CalculatorArgs
{
public string Expression { get; set; } = "";
}
Evaluates arithmetic expressions safely (no eval, no string
interpolation injection). Supports + - * / %, ^ (power), unary
minus, parentheses, and the standard math constants. The agent
reaches for it whenever the user asks for an exact number.
var calc = new CalculatorTool();
var result = await calc.ExecuteAsync(new CalculatorArgs
{
Expression = "2^10 + 1",
});
// "2^10 + 1 = 1025"
DateTimeTool
public sealed class DateTimeArgs
{
public string Timezone { get; set; } = "UTC";
public string Format { get; set; } = "yyyy-MM-ddTHH:mm:ssZ";
}
public sealed class DateTimeTool : ToolBase<DateTimeArgs>
{
public DateTimeTool(Func<DateTimeOffset>? nowProvider = null);
}
Returns the current date/time in the requested timezone and format.
The optional nowProvider is for tests — pass a fixed clock when you
want deterministic output.
var dt = new DateTimeTool();
var now = await dt.ExecuteAsync(new DateTimeArgs
{
Timezone = "America/New_York",
Format = "yyyy-MM-dd HH:mm",
});
// "2026-04-25 11:42"
HttpGetTool
public sealed class HttpGetArgs
{
public string Url { get; set; } = "";
public int MaxChars { get; set; } = 2000;
}
public sealed class HttpGetTool : ToolBase<HttpGetArgs>
{
public HttpGetTool(); // production
internal HttpGetTool(HttpClient); // for tests
}
Fetches a URL via HTTP GET. The body is returned to the LLM with
HTML markup stripped, capped at MaxChars (default 2000) so it
doesn't blow the context window.
var http = new HttpGetTool();
var body = await http.ExecuteAsync(new HttpGetArgs
{
Url = "https://en.wikipedia.org/wiki/Reciprocal_rank_fusion",
MaxChars = 1500,
});
HttpGetTool is intentionally read-only and unauthenticated. For
authenticated APIs, write a custom tool (typed) —
only takes a few lines.
JsonExtractTool
public sealed class JsonExtractArgs
{
public string Json { get; set; } = "";
public string Path { get; set; } = "";
}
public sealed class JsonExtractTool : ToolBase<JsonExtractArgs>
{
public JsonExtractTool();
}
Extracts a value from a JSON document by dot-notation path. Pair it
with HttpGetTool for "fetch JSON → pick a field" pipelines.
var extract = new JsonExtractTool();
var result = await extract.ExecuteAsync(new JsonExtractArgs
{
Json = """{ "user": { "name": "Alice", "age": 30 } }""",
Path = "user.name",
});
// "Alice"
WebSearchTool
public enum WebSearchProvider { Brave, Tavily, SerpApi }
public sealed class WebSearchOptions
{
public string ApiKey { get; set; } = "";
public WebSearchProvider Provider { get; set; } = WebSearchProvider.Brave;
}
public sealed class WebSearchArgs
{
public string Query { get; set; } = "";
public int MaxResults { get; set; } = 5;
}
public sealed class WebSearchTool : ToolBase<WebSearchArgs>
{
public WebSearchTool(WebSearchOptions options);
}
Searches the live web. Bring your own API key from one of the supported providers:
| Provider | Get a key |
|---|---|
Brave (default) | brave.com/search/api |
Tavily | tavily.com (optimised for LLM agents) |
SerpApi | serpapi.com |
var search = new WebSearchTool(new WebSearchOptions
{
Provider = WebSearchProvider.Tavily,
ApiKey = Environment.GetEnvironmentVariable("TAVILY_KEY")!,
});
The tool returns a list of { title, url, snippet } results that the
LLM can cite verbatim.
Combining tools on one agent
Most agents need a small handful — calculator + datetime + web search covers a lot of "general assistant" use cases:
var search = new WebSearchTool(new WebSearchOptions
{
Provider = WebSearchProvider.Brave,
ApiKey = Environment.GetEnvironmentVariable("BRAVE_KEY")!,
});
IAgent assistant = new Agent<string>(
"Assistant",
"A general-purpose assistant.",
"You are a helpful assistant. Use tools whenever real data would " +
"beat your training-cutoff guesses.",
llm,
tools: new ToolBase[]
{
new CalculatorTool(),
new DateTimeTool(),
search,
});
Where next
- Custom tools (typed) — build your own with
ToolBase<TArgs>and auto-generated schemas. - Custom tools (untyped) — when you need to hand-author the JSON schema or accept arbitrary JSON.
- MCP overview — pull in tools from any MCP server.