For AI Agents
Quickstart
Get your agent talking to production in 5 minutes.
1. Install
bash
pip install astapa openai2. Start the proxy
bash
# Download and run
curl -fsSL https://astapa.com/install.sh | sh
DATABASE_URL=postgres://user:pass@localhost/mydb astapa-proxy3. Connect your agent
python
from openai import OpenAI
from astapa import Astapa
openai = OpenAI()
astapa = Astapa()
# Define database tools
tools = [
{"type": "function", "function": {
"name": "query",
"description": "Run a SELECT query",
"parameters": {"type": "object", "properties": {
"sql": {"type": "string"}
}, "required": ["sql"]}
}},
{"type": "function", "function": {
"name": "mutate",
"description": "Run INSERT/UPDATE/DELETE (staged for review)",
"parameters": {"type": "object", "properties": {
"sql": {"type": "string"}
}, "required": ["sql"]}
}}
]
with astapa.session(
project_id="my-agent",
database="mydb",
user="postgres",
password="pass",
) as session:
def handle_tool(name: str, args: dict) -> str:
if name == "query":
return str(session.execute(args["sql"]))
elif name == "mutate":
session.execute(args["sql"])
return "Staged for review"
# Agent loop
response = openai.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Refund order #102"}],
tools=tools,
)
for tc in response.choices[0].message.tool_calls or []:
result = handle_tool(tc.function.name, eval(tc.function.arguments))
print(f"[{tc.function.name}] {result}")
# View staged changes
print("Changes:", session.diff())
# Session auto-proposes on exit4. Review and approve
python
# Later, review the proposed changes
session = astapa.get_session(session_id)
print(session.diff())
session.approve() # Apply to production
# or
session.reject() # Discard changes