agentskit.js
ToolsIntegrations

postgres

Postgres query tool — BYO runner keeps the adapter client-agnostic (`postgres.js`, `pg`, Drizzle, Prisma, Neon).

import { postgres } from '@agentskit/tools'
import postgresJs from 'postgres'

const sql = postgresJs(process.env.DATABASE_URL!)

const runtime = createRuntime({
  adapter,
  tools: [...postgres({
    run: async (query, params) => sql.unsafe(query, params as unknown[]),
  })],
})

Sub-tools

NamePurpose
postgresQueryExecute parameterized SQL, return rows + row-count

Bundled: postgres(config).

Config

type PostgresConfig = {
  run: (query: string, params: unknown[]) => Promise<PostgresExecuteResult>
  readonly?: boolean    // block non-SELECT statements
  maxRows?: number      // cap on result size
}

Example — data analyst agent

import { postgres } from '@agentskit/tools'
import { sqlAnalystSkill } from '@agentskit/skills'

const runtime = createRuntime({
  adapter,
  skills: [sqlAnalystSkill],
  tools: [...postgres({ run, readonly: true, maxRows: 100 })],
})

await runtime.run('How many users signed up last week vs the week before?')

Safety

  • Default to readonly: true. Let the agent read before it ever writes.
  • For writes, wrap via mandatory sandbox with an allowlist of tables.
  • Never pass string-interpolated queries — always use the params array.
✎ Edit this page on GitHub·Found a problem? Open an issue →·How to contribute →

On this page