How to Give an Agent a Query Language Instead of a Code Interpreter
A four-step pattern for letting a document agent write validated aggregation pipelines instead of arbitrary code, so results come back shaped and tenancy stays enforced.
A document agent that calls fixed tools makes many round trips and floods its context with raw records. The alternative is to let the agent write an aggregation pipeline: a bounded query language the server can validate before it runs. The handler checks the pipeline, prepends a tenancy filter, executes it server-side, and returns only the reshaped result, so the agent gets comparisons and joins without holding whole collections. The trade-off is a narrower vocabulary: only a small set of stages is permitted, regex is not semantic search, and an unbounded limit can silently truncate answers. Use this pattern when the agent's job is to reshape and compare data under a strict security boundary, not when it needs general computation.
FAQ
Why give an agent a pipeline language instead of letting it write code?
A code interpreter is a general execution surface, so every capability you grant is also an attack surface. A bounded pipeline language keeps the same expressive power for reshaping data while letting a handler validate the query before it runs. The trade-off is a smaller vocabulary: only a fixed stage set is permitted, so some operations need a second pass.
What has to happen between the agent's query and the database?
A handler validates the pipeline, prepends a tenancy filter, and only then executes it server-side. That filter is what keeps one tenant's documents out of another tenant's answer, and it is applied by the platform rather than trusted to the agent. The agent receives the reshaped result, not the raw collection.
What are the practical gotchas of a bounded pipeline?
Regex is not semantic search, so a fuzzy natural-language match will not behave the way an embedding search would. An unbounded or careless limit stage can silently truncate results, making an incomplete answer look complete. Agents also often need two passes, computing booleans or concatenating fields so comparisons happen in the database rather than in context.
A five-step how-to for scaling AI adoption across engineering teams: federate ownership, ship one shared paved path, let builders own their tools, measure throughput, and feed bottlenecks back into the path.
Clang's constant interpreter evaluates constant expressions at compile time, so the bill lands on your build, not your binary. This five-checkpoint guide shows where that memory goes and how to keep it small.
Clairic is a System One extraction model that turns unstructured input into typed values in a single forward pass. This five-step flow shows how to declare fields, call it, and use the results.
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.