Skip to content

Commit 7d2aa5b

Browse files
authored
Postgres Docs (#345)
* Postgres Docs * Examples!
1 parent 7de72d8 commit 7d2aa5b

11 files changed

Lines changed: 244 additions & 0 deletions

File tree

pages/toolkits/_meta.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export default {
3030
sales: {
3131
title: "Sales",
3232
},
33+
databases: {
34+
title: "Databases",
35+
},
3336
"-- Submit your toolkit": {
3437
type: "separator",
3538
title: "Submit your toolkit",

pages/toolkits/databases/_meta.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
postgres: "Postgres",
3+
};
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Postgres
2+
3+
import ToolInfo from "@/components/ToolInfo";
4+
import Badges from "@/components/Badges";
5+
import TabbedCodeBlock from "@/components/TabbedCodeBlock";
6+
import TableOfContents from "@/components/TableOfContents";
7+
import ToolFooter from "@/components/ToolFooter";
8+
9+
<ToolInfo
10+
description="Enable agents to interact with PostgreSQL databases (read only)."
11+
author="Arcade"
12+
codeLink="https://github.com/ArcadeAI/arcade-ai/tree/main/toolkits/postgres"
13+
authType="database connection string"
14+
versions={["0.1.0"]}
15+
/>
16+
17+
<Badges repo="arcadeai/arcade-postgres" />
18+
19+
The Arcade Postgres toolkit provides a pre-built set of tools for interacting with PostgreSQL databases in a read-only manner.
20+
21+
<Note>
22+
This toolkit is meant to be an example of how to build a toolkit for a database, and is not intended to be used in production. For production use, we recommend forking this repository and building your own toolkit with use-case specific tools.
23+
</Note>
24+
25+
26+
This repository demonstrates a few concepts to aid in LLM-powered database interactions.
27+
* Re-use an existing database pool for all tool calls
28+
* Enforce read-only access to the database
29+
* Hint to the LLM that both table and schema discovery is required before executing a query
30+
* Enforce a limit on the number of rows returned by a query
31+
32+
## Available Tools
33+
34+
<TableOfContents
35+
headers={["Tool Name", "Description"]}
36+
data={
37+
[
38+
['Postgres.DiscoverTables', "Discover all tables in a PostgreSQL database."],
39+
['Postgres.GetTableSchema', "Get the schema of a table in a PostgreSQL database."],
40+
['Postgres.ExecuteQuery', "Execute a query on a PostgreSQL database."],
41+
]
42+
}
43+
/>
44+
45+
Note that all tools require the `DATABASE_CONNECTION_STRING` secret to be set.
46+
47+
## Postgres.DiscoverTables
48+
49+
Discover all tables in a PostgreSQL database.
50+
51+
<TabbedCodeBlock
52+
tabs={[
53+
{
54+
label: "Call the Tool",
55+
content: {
56+
Python: [
57+
"/examples/integrations/toolkits/postgres/discover_tables_example_call_tool.py",
58+
],
59+
JavaScript: ["/examples/integrations/toolkits/postgres/discover_tables_example_call_tool.js"],
60+
},
61+
}
62+
]}
63+
/>
64+
## Postgres.GetTableSchema
65+
66+
Get the schema of a table in a PostgreSQL database.
67+
68+
<TabbedCodeBlock
69+
tabs={[
70+
{
71+
label: "Call the Tool",
72+
content: {
73+
Python: [
74+
"/examples/integrations/toolkits/postgres/get_table_schema_example_call_tool.py",
75+
],
76+
JavaScript: ["/examples/integrations/toolkits/postgres/get_table_schema_example_call_tool.js"],
77+
},
78+
}
79+
]}
80+
/>
81+
## Postgres.ExecuteQuery
82+
83+
<TabbedCodeBlock
84+
tabs={[
85+
{
86+
label: "Call the Tool",
87+
content: {
88+
Python: [
89+
"/examples/integrations/toolkits/postgres/execute_query_example_call_tool.py",
90+
],
91+
JavaScript: ["/examples/integrations/toolkits/postgres/execute_query_example_call_tool.js"],
92+
},
93+
}
94+
]}
95+
/>
96+
97+
Execute a query on a PostgreSQL database. Be sure that your agent runs the `Postgres.DiscoverTables` and `Postgres.GetTableSchema` tools before executing a query.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Arcade } from "@arcadeai/arcadejs";
2+
3+
const client = new Arcade(); // Automatically finds the `ARCADE_API_KEY` env variable
4+
5+
const USER_ID = "{arcade_user_id}";
6+
const TOOL_NAME = "Postgres.DiscoverTables";
7+
8+
const toolInput = {};
9+
10+
const response = await client.tools.execute({
11+
tool_name: TOOL_NAME,
12+
input: toolInput,
13+
user_id: USER_ID,
14+
});
15+
16+
console.log(response.output.value);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from arcadepy import Arcade
2+
3+
client = Arcade() # Automatically finds the `ARCADE_API_KEY` env variable
4+
5+
TOOL_NAME = "Postgres.DiscoverTables"
6+
7+
user_id = "{arcade_user_id}"
8+
9+
tool_input = {}
10+
11+
response = client.tools.execute(
12+
tool_name=TOOL_NAME,
13+
input=tool_input,
14+
user_id=user_id,
15+
)
16+
17+
print(response.output.value)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Arcade } from "@arcadeai/arcadejs";
2+
3+
const client = new Arcade(); // Automatically finds the `ARCADE_API_KEY` env variable
4+
5+
const USER_ID = "{arcade_user_id}";
6+
const TOOL_NAME = "Postgres.ExecuteQuery";
7+
8+
const toolInput = {
9+
query: "SELECT * FROM users",
10+
};
11+
12+
const response = await client.tools.execute({
13+
tool_name: TOOL_NAME,
14+
input: toolInput,
15+
user_id: USER_ID,
16+
});
17+
18+
console.log(response.output.value);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from arcadepy import Arcade
2+
3+
client = Arcade() # Automatically finds the `ARCADE_API_KEY` env variable
4+
5+
TOOL_NAME = "Postgres.ExecuteQuery"
6+
7+
user_id = "{arcade_user_id}"
8+
9+
tool_input = {
10+
"query": "SELECT * FROM users",
11+
}
12+
13+
response = client.tools.execute(
14+
tool_name=TOOL_NAME,
15+
input=tool_input,
16+
user_id=user_id,
17+
)
18+
19+
print(response.output.value)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Arcade } from "@arcadeai/arcadejs";
2+
3+
const client = new Arcade(); // Automatically finds the `ARCADE_API_KEY` env variable
4+
5+
const USER_ID = "{arcade_user_id}";
6+
const TOOL_NAME = "Postgres.GetTableSchema";
7+
8+
const toolInput = {
9+
schema_name: "public",
10+
table_name: "users",
11+
};
12+
13+
const response = await client.tools.execute({
14+
tool_name: TOOL_NAME,
15+
input: toolInput,
16+
user_id: USER_ID,
17+
});
18+
19+
console.log(response.output.value);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from arcadepy import Arcade
2+
3+
client = Arcade() # Automatically finds the `ARCADE_API_KEY` env variable
4+
5+
TOOL_NAME = "Postgres.GetTableSchema"
6+
7+
user_id = "{arcade_user_id}"
8+
9+
tool_input = {
10+
"schema_name": "public",
11+
"table_name": "users",
12+
}
13+
14+
response = client.tools.execute(
15+
tool_name=TOOL_NAME,
16+
input=tool_input,
17+
user_id=user_id,
18+
)
19+
20+
print(response.output.value)

public/images/icons/postgres.svg

Lines changed: 22 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)