Skip to content

Commit 3b799b7

Browse files
committed
global connection and docs
1 parent 7f39402 commit 3b799b7

4 files changed

Lines changed: 52 additions & 16 deletions

File tree

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22
import psycopg2
33
from typing import Dict, Any
44

5+
connection = None
6+
57
def _get_connection():
68
"""Get PostgreSQL database connection"""
7-
return psycopg2.connect(
8-
dbname=os.getenv('POSTGRES_DB'),
9-
user=os.getenv('POSTGRES_USER'),
10-
password=os.getenv('POSTGRES_PASSWORD'),
11-
host=os.getenv('POSTGRES_HOST', 'localhost'),
12-
port=os.getenv('POSTGRES_PORT', '5432')
13-
)
9+
10+
global connection
11+
if connection is None:
12+
connection = psycopg2.connect(
13+
dbname=os.getenv('POSTGRES_DB'),
14+
user=os.getenv('POSTGRES_USER'),
15+
password=os.getenv('POSTGRES_PASSWORD'),
16+
host=os.getenv('POSTGRES_HOST', 'localhost'),
17+
port=os.getenv('POSTGRES_PORT', '5432')
18+
)
19+
20+
return connection
1421

1522
def get_schema() -> Dict[str, Any]:
1623
"""
@@ -47,7 +54,7 @@ def get_schema() -> Dict[str, Any]:
4754
schema[table_name] = columns
4855

4956
cursor.close()
50-
conn.close()
57+
# conn.close()
5158
return schema
5259

5360
except Exception as e:
@@ -71,7 +78,7 @@ def execute_query(query: str) -> list:
7178
results = cursor.fetchall()
7279

7380
cursor.close()
74-
conn.close()
81+
# conn.close()
7582
return results
7683

7784
except Exception as e:
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"name": "py_sql",
2+
"name": "sql",
33
"url": "https://pypi.org/project/psycopg2/",
44
"category": "database",
55
"env": {
6-
"POSTGRES_DB": "...",
7-
"POSTGRES_USER": "...",
8-
"POSTGRES_PASSWORD": "...",
9-
"POSTGRES_HOST": "...",
10-
"POSTGRES_PORT": "..."
6+
"POSTGRES_DB": null,
7+
"POSTGRES_USER": null,
8+
"POSTGRES_PASSWORD": null,
9+
"POSTGRES_HOST": null,
10+
"POSTGRES_PORT": null
1111
},
1212
"dependencies": [
1313
"psycopg2-binary>=2.9.9"

docs/tools/core.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ description: 'AgentStack tools that are not third-party integrations'
1313

1414
- [Code Interpreter](/tools/tool/code-interpreter)
1515

16-
## Data Input
16+
## Input
1717
- [Vision](/tools/tool/vision)
1818

19+
## Data
20+
- [SQL](/tools/tool/sql)
21+
1922
<CardGroup cols={1}>
2023
<Card
2124
title="Community Tools"

docs/tools/tool/sql.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: 'Perplexity'
3+
description: 'Agentic Search'
4+
---
5+
6+
## Description
7+
Enable your agent to perform queries directly on a database
8+
9+
<Note>
10+
There is no built-in sandboxing using this tool. Agents may perform destructive queries that may be irreversible.
11+
</Note>
12+
13+
## Installation
14+
15+
```bash
16+
agentstack tools add sql
17+
```
18+
19+
Set the API keys
20+
```env
21+
POSTGRES_DB=...
22+
POSTGRES_USER=...
23+
POSTGRES_PASSWORD=...
24+
POSTGRES_HOST=...
25+
POSTGRES_PORT=...
26+
```

0 commit comments

Comments
 (0)