Skip to content

PATTERN Cited by 1 source

Query language as agent tool

Query language as agent tool exposes a declarative query language (typically SQL) as the primary tool surface for data retrieval, instead of wrapping each REST endpoint as a tool. Agents are strong at writing SQL, and SQL gives them fine-grained control over what enters the context windowSELECT only needed fields, LIMIT to a few rows, COUNT / GROUP BY server-side instead of retrieving raw samples (Source: sources/2026-03-04-datadog-mcp-server-agent-tools).

Failure mode this replaces

V1 tool design: one tool per API endpoint (get_logs_matching_filter, etc.). A user asks "which services are logging the most errors in the last hour?". The V1 agent:

  • has no aggregation tool → pulls some logs matching an error filter, guesses a trend from the sample; often wrong.
  • worse, some agents brute-force it — repeatedly retrieving data until the context window fills.

With a SQL tool, the same question becomes one tool call of a query like SELECT service, COUNT(*) AS c ... GROUP BY service ORDER BY c DESC, returning small structured output.

Reported outcomes

Datadog reports on their eval scenarios:

  • ~40% cheaper runs in some scenarios (fewer tokens to reach the answer).
  • Higher correctness on trend / aggregation questions (exact counts, not sample inferences).

Cost of the pattern

  • Significant implementation lift: "at the scale we operate at, traditional relational databases don't work". Requires a distributed query engine over the domain's storage (implicitly systems/husky-class, for Datadog).
  • Surfaces more capability than necessary for the simple cases; pair with patterns/tool-surface-minimization so the surface area stays manageable.
  • Errors must be specific to be useful (patterns/actionable-error-messages); "invalid query" traps agents in retry loops.

Applicability

  • Strong fit: data retrieval where the agent asks aggregation, filtering, or ranking questions; domain with stable schema and affordable query-engine coverage.
  • Weaker fit: action tools (create / modify / delete) — SQL collapses retrieval, but side-effecting operations remain separate named tools.

Seen in

Last updated · 200 distilled / 1,178 read