Simon Willison’s Weblog: Xata Agent

Source URL: https://simonwillison.net/2025/Mar/13/xata-agent/
Source: Simon Willison’s Weblog
Title: Xata Agent

Feedly Summary: Xata Agent
Xata are a hosted PostgreSQL company who also develop the open source pgroll and pgstream schema migration tools.
Their new “Agent" tool is a system that helps monitor and optimize a PostgreSQL server using prompts to LLMs.
Any time I see a new tool like this I go hunting for the prompts. It looks like the main system prompts for orchestrating the tool live here – here’s a sample:

Provide clear, concise, and accurate responses to questions.
Use the provided tools to get context from the PostgreSQL database to answer questions.
When asked why a query is slow, call the explainQuery tool and also take into account the table sizes.
During the initial assessment use the getTablesAndInstanceInfo, getPerfromanceAndVacuumSettings,
and getPostgresExtensions tools.
When asked to run a playbook, use the getPlaybook tool to get the playbook contents. Then use the contents of the playbook
as an action plan. Execute the plan step by step.

The really interesting thing is those playbooks, each of which is implemented as a prompt in the lib/tools/playbooks.ts file. There are six of these so far:

SLOW_QUERIES_PLAYBOOK
GENERAL_MONITORING_PLAYBOOK
TUNING_PLAYBOOK
INVESTIGATE_HIGH_CPU_USAGE_PLAYBOOK
INVESTIGATE_HIGH_CONNECTION_COUNT_PLAYBOOK
INVESTIGATE_LOW_MEMORY_PLAYBOOK

Here’s the full text of INVESTIGATE_LOW_MEMORY_PLAYBOOK:

Objective:
To investigate and resolve low freeable memory in the PostgreSQL database.

Step 1:
Get the freeable memory metric using the tool getInstanceMetric.

Step 3:
Get the instance details and compare the freeable memory with the amount of memory available.

Step 4:
Check the logs for any indications of memory pressure or out of memory errors. If there are, make sure to report that to the user. Also this would mean that the situation is critical.

Step 4:
Check active queries. Use the tool getConnectionsGroups to get the currently active queries. If a user or application stands out for doing a lot of work, record that to indicate to the user.

Step 5:
Check the work_mem setting and shared_buffers setting. Think if it would make sense to reduce these in order to free up memory.

Step 6:
If there is no clear root cause for using memory, suggest to the user to scale up the Postgres instance. Recommend a particular instance class.

This is the first time I’ve seen prompts arranged in a "playbooks" pattern like this. What a weird and interesting way to write software!
Via Hacker News
Tags: prompt-engineering, generative-ai, ai-agents, postgresql, ai, llms

AI Summary and Description: Yes

Summary: The text discusses Xata’s new “Agent” tool designed to optimize PostgreSQL servers using prompts directed at large language models (LLMs). By introducing playbooks, which are structured prompts with specific objectives, Xata enhances the monitoring and troubleshooting capabilities of database management. This novel approach emphasizes the integration of AI with database systems, highlighting potential advancements in information security and optimization efficiencies.

Detailed Description:
The text describes the launch of Xata’s “Agent” tool, which leverages LLMs for monitoring and optimizing PostgreSQL databases. This integration of AI with database management presents several significant insights and implications for professionals in information security and infrastructure.

– **Overview of Xata Agent**:
– A tool developed by Xata to enhance PostgreSQL server management.
– Utilizes prompts directed at LLMs to generate responses and actions based on the server’s state.

– **Prompt Framework**:
– Prompts are utilized to interact with the PostgreSQL database for monitoring and optimization.
– Examples of main system prompts include fetching context, evaluating query performance, and executing specific playbook actions.

– **Playbooks**:
– The tool includes structured playbooks, which are essentially pre-defined sets of actions based on database conditions.
– Sample playbooks include:
– SLOW_QUERIES_PLAYBOOK
– GENERAL_MONITORING_PLAYBOOK
– TUNING_PLAYBOOK
– INVESTIGATE_HIGH_CPU_USAGE_PLAYBOOK
– INVESTIGATE_HIGH_CONNECTION_COUNT_PLAYBOOK
– INVESTIGATE_LOW_MEMORY_PLAYBOOK
– Each playbook follows specific investigative steps to diagnose and resolve issues, such as low memory or slow queries.

– **INVESTIGATE_LOW_MEMORY_PLAYBOOK**:
– Provides a structured approach to analyzing low freeable memory within a PostgreSQL instance.
– Steps include:
– Fetching memory metrics and instance details.
– Analyzing logs for memory-related errors.
– Checking current active queries for any apparent heavy loads.

– **Novelty and Implications**:
– This structured playbook approach is a unique method of writing software that aligns with modern AI capabilities.
– The integration of prompts and decision trees could lead to more efficient database management and faster troubleshooting.
– Professionals in AI and infrastructure security should note this as a potential leverage point for automating database operations and improving security posture against performance-related issues.

The text presents a fresh perspective on using generative AI in systems operations, particularly in database management, which could have significant utility in enhancing security, compliance, and operational efficiency strategies within organizations.