postgresql_reader_agent = Agent(
role="AI Database Reliability Engineer with PostgreSQL expertise",
goal="Troubleshoot PostgreSQL database issues and find the answer to the user questions",
backstory=(
"You are a professional who is involved in very complex PostgreSQL "
"..."),
llm=llm,
verbose=True,
allow_delegation=False,
tools=[postgresql_tool],
)
"""
You only have read-only permissions to the database by default. You should not execute destructive commands like
DROP, DELETE, or UPDATE unless explicitly requested and confirmed by the user. Focus primarily on SELECT queries for
diagnostics and analysis.
"""
from pydantic import BaseModel, Field
class PostgreSQLCommandInput(BaseModel):
"""Input for executing PostgreSQL commands securely."""
command: str = Field(..., description="The SQL command to execute (e.g., 'SELECT * FROM users LIMIT 10').")
host: str = Field(..., description="The PostgreSQL server host address.")
port: int = Field(5432, description="The PostgreSQL server port (default: 5432).")
user: str = Field(..., description="The PostgreSQL username.")
password: str = Field(..., description="The PostgreSQL password.")
database: str = Field(..., description="The PostgreSQL database name to use.")
class PostgreSQLTool(BaseTool):
name: str = "PostgreSQL Command Executor"
description: str = "Executes PostgreSQL commands securely and returns the results in a readable format."
args_schema: Type[BaseModel] = PostgreSQLCommandInput
# tool code below
assets = [
{
"type": "postgresql",
"host": "MASKED",
"port": "5432",
"user": "aiuser",
"database": "aitestdb",
"password": "MASKED"
}
]
python 01_crew.py "perform a health assessment of my database"
...
The PostgreSQL database 'aitestdb' on server MASKED:5432 is running PostgreSQL version 16.8. Database statistics show some activity with commits, rollbacks, and data access. There's one active connection from client address 10.15.34.2. The database currently contains only system tables within the pg_catalog and information_schema schemas, indicating a potentially new or system-level database. Background writer statistics show checkpoint and buffer allocation activity.
python 02_crew.py "perform a health assessment of my database"
...
Based on the information I have, here's a health assessment of your database:
**Database Server (do_test_server - MASKED):**
* **General Status:** The server appears to be running and accessible.
* **Resources:** The server is a DigitalOcean droplet ("test-ai-agents") with 1GB of RAM, 1 vCPU, and 25GB of disk space.
* **Monitoring:** A CPU usage alert is configured, triggering if CPU usage exceeds 70% for 5 minutes.
* **Operating System:** Ubuntu 20.04 (LTS) x64.
* **Networking:** Public IPv4 and IPv6 addresses are assigned. Private networking is enabled.
...and more...