Using AI Agents with your databases
An AI agent that connects to a database, interprets plain language questions, and generates SQL queries to retrieve answers. Securely run in a sandboxed container environment with Dagger.

Dagger is an amazing tool that helps convert complex YAML configurations and brittle shell scripts into robust, maintainable, runnable code. Using containers and sandboxed environments, Dagger allows developers to add business logic to workflows, import additional libraries, and safely ship code.
Recently, Dagger introduced native integration with Large Language Models (LLMs), enhancing its capabilities to automate workflows. This allows developers to build intelligent, AI-driven workflows directly within their pipelines using the same tooling.
Key Benefits of AI Agents with Dagger
Some of the key points of why you should consider using Dagger for AI Agent development are:
- Seamless LLM Integration
With Dagger's LLM primitive you can write an AI Agent once and switch out the LLM provider (e.g. OpenAI, Anthropic, Gemini, etc) through environment variables - removing the need to learn new APIs or rewrite code allowing developers to switch out models on demand. - Built-in Observability
With integrated support for OpenTelemetry, Dagger provides comprehensive observability into your workflows. Tools like Dagger Cloud and the Terminal User Interface (TUI) offer real-time insights into each step of your pipeline, facilitating easier debugging and performance optimization. - Secure, Sandboxed Environments
Dagger runs within containers, ensuring that LLMs and other tools have access only to the resources you as the developer explicitly provide. This sandboxed approach enhances security and predictability in your workflows. - Modular and Reusable Workflows
Dagger promotes the creation of modular, reusable components, allowing developers to build complex workflows from simpler building blocks. This modularity facilitates collaboration and scalability across teams and projects.
Getting Started with AI Agents in Dagger
To begin building AI agents with Dagger:
- Install Dagger CLI: Ensure you have the Dagger CLI installed on your system
- Initialize a Dagger Module: Use the
dagger init
command with your preferred SDK (Go, Python, TypeScript, PHP, etc.) to create a new Dagger Module - Configure LLM Endpoint: Set up your desired LLM provider by configuring the appropriate environment variables (e.g.,
OPENAI_API_KEY
) - Develop Your Agent: Write functions that define the behavior of your AI agent, utilizing Dagger’s LLM and Env primitives to interact with the LLM and manage inputs/outputs
- Run and Iterate: Execute your agent, observe its behavior through Dagger’s observability tools, and refine its logic as needed
You can learn more about building Agents with Dagger by following the Quickstart and looking at the examples here.
Demo: Querying Databases with Natural Language
Explore how to build an AI agent that connects to a database and answers natural language questions:
By integrating AI capabilities directly into your workflows, Dagger enables intelligent, secure, and observable pipelines. Whether automating code generation, testing, or deployment, Dagger’s combination of containerization and LLM integration offers a robust foundation for modern DevOps practices.