Closing the loop: Building a coding agent that uses Postgres branches
Explore how to build an AI coding agent that follows a full developer workflow, including creating Postgres branches, using a sandbox, fixing bugs, and raising pull requests with Xata, Vercel, and GitHub.
Author
Divyendu SinghDate published
I recently presented Xata Agent at Berlin PostgreSQL meetup showcasing how we use Xata Agent to manage and tune a fleet of PostgreSQL instances in production. Here is the recap.
In short summary,
Xata Agent is an open source agent that monitors your database, finds root causes of issues and suggests fixes and improvements. It's like having a new SRE hire in your team, one with extensive experience in Postgres.
After the meetup, a question that was raised multiple times was about making the agent also "see" code (in addition to just PostgreSQL logs and stats) and therefore “closing the loop” for agent to autonomously solve problems or go very far in solving problems.
That led us to explore what it looks like to give an AI agent access to code and realistic data using database branching, the ability to run code in a sandbox and the ability to commit changes to a PR. Essentially, this means giving the agent access to the same tools a developer uses when building features or fixing bugs.
In this blog post, we showcase the workflow with a custom agent and tools that allow it to interact with GitHub, Sandbox and Xata branches but it is possible to do the same with existing workflows like claude, gh and xata CLIs. We’ll cover that approach in a future blog post.
Demo aka “show me what you got”
I can hear some of you already say “show me what you got”

Here is a 3 minute demo to showcase what I mean:
In the demo, you can see that the agent is able clone the repository in a sandbox, change the database URL in the environment variables to a Xata branch created for the PR and implement the feature just from the issue description autonomously.
Since we are using PR as the point of interaction, a human developer can checkout the PR and contribute along the AI agent.
The Workflow
If a developer has to build a feature or fix a bug, that usually involves following some fixed sequence of events like:
- Create a git branch
- Get enough data from production database or seed it to be able to reproduce the issue
- Reproduce the issue
- Make a hypothesis on where the issue might be (by reading code)
- Fix the issue and raise a PR
- See tests / CI pass, get reviews
- Merge the PR, profit
With the respective APIs of Vercel Sandbox, Xata Platform and GitHub Apps. It is possible for an agent to have:
- Ability to read code and create pull requests via GitHub API
- Realistic PII safe branches instantly via Xata
- A sandbox to execute code in via Vercel

For the purpose of this demo, we chose a GitHub issue as the initiator of the workflow but it can also be a prompt on an agent UI (like Codex) or a prompt from an agent CLI like claude.
The System Prompt
The heavy lifting of running the workflow is done by the system prompt. This 200+ line system prompt in plain English shows us how far the AI agents (and the LLMs underneath) have come.
Here it the system prompt that makes the demo tick:
You can see that we emphasize having the model stick to the “follow the workflow” plan and approach tasks the same way a developer would.
In practice, this worked well, the agent was able to use the tools that were available to it and make changes to the schema.
Next steps
Another interesting question that came up during the Xata Agent talk at Berlin PostgreSQL meetup was “why do we have a custom agent and not something like agent + MCP servers”.
My answer back then was “when we started working on the agents, MCPs and other tools that make AI agents programmable were very new or didn’t exist”.
Claude Skills (which didn’t exist at the time of the talk) and Ampcode’s toolbox-based approach are clear indicators that we’re heading toward programmable AI agents. As a next step, I plan to recreate this workflow using a CLI-based approach:
- Using
claudeCLI as the agent - Creating the database branch using
xataCLI - Reading code and issues using
ghCLI and so on
Conclusion
Thank you for reading this blog post. I am really excited with where the AI models are headed and would continue exploring ideas in this space.
We look forward to having you try the Xata platform. If you'd like early access, you can get access today.
Related Posts
Recap of Berlin Postgres Meetup on September 23rd 2025
Takeaways from the Sep 23, 2025 Berlin Postgres Meetup: how Xata Agent (open-source Postgres AI agent) helps manage PostgreSQL at scale, Q&A highlights, lessons.
From natural language to SQL queries: How we built Generate SQL with AI
Discover how Xata used Large Language Models (LLMs) to turn natural language into accurate PostgreSQL queries, simplifying BI workflows and boosting productivity.
From DBA to DB Agents
Discover how a PostgreSQL DBA’s decade of expertise evolved into designing Xata’s AI-powered Postgres agent, automating monitoring and observability.