Using knowledge stores

Give your agent a database it can read from and write to
View as Markdown

A knowledge store is a database your agent uses — Postgres, MySQL, Redis, Qdrant, Neo4j, or Pinecone. You declare it in astropods.yml; the platform creates it and passes the connection details to your agent as environment variables.

This guide builds an agent with a single Postgres store named writer: declare it, run it locally, push a blueprint, and deploy it from the dashboard.

1knowledge:
2 writer:
3 provider: postgres

With one store, the variables are POSTGRES_HOST, POSTGRES_PORT, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB — the entry name (writer) is not part of them. That only changes when you add a second store of the same type (see Adding a second store).


Before you start

You need:

  • An Astro AI account.
  • The ast CLI.
  • A container runtime (such as Docker) for ast project start.

Steps

1

Create the agent

$ast project create writer-agent --model anthropic
$cd writer-agent

This generates the starter source and astropods.yml.

2

Declare the store

Add a knowledge block to astropods.yml:

1spec: blueprint/v1
2name: writer-agent
3
4agent:
5 build:
6 context: .
7 dockerfile: Dockerfile
8
9knowledge:
10 writer:
11 provider: postgres

You only set the provider — no host, port, or password. Supported values: postgres, mysql, redis, qdrant, neo4j, and pinecone.

3

Read the connection in your code

The connection details arrive as environment variables:

1import os
2import psycopg2 # replace with your database driver
3
4conn = psycopg2.connect(
5 host=os.environ["POSTGRES_HOST"],
6 port=os.environ["POSTGRES_PORT"],
7 user=os.environ["POSTGRES_USER"],
8 password=os.environ["POSTGRES_PASSWORD"],
9 dbname=os.environ["POSTGRES_DB"],
10)
1import { Pool } from "pg"; // replace with your database driver
2
3const pool = new Pool({
4 host: process.env.POSTGRES_HOST,
5 port: Number(process.env.POSTGRES_PORT),
6 user: process.env.POSTGRES_USER,
7 password: process.env.POSTGRES_PASSWORD,
8 database: process.env.POSTGRES_DB,
9});
VariableMeaning
POSTGRES_HOSTHost
POSTGRES_PORTPort (default 5432)
POSTGRES_USERUsername
POSTGRES_PASSWORDPassword
POSTGRES_DBDatabase name

Postgres gives you separate fields, not a single URL. Redis, Qdrant, and Neo4j also get a <PREFIX>_URL variable.

4

Run it locally

$ast project start

The CLI starts a Postgres container next to your agent with the same POSTGRES_* variables wired in. Your data persists across restarts. Logs stream in the foreground; Ctrl+C to stop.

5

Push a blueprint

$ast login
$ast blueprint push writer-agent

The blueprint records that the agent needs a writer Postgres store. It does not contain any credentials.

6

Deploy from the dashboard

Go to Blueprints, find writer-agent, and click Deploy. In the form:

  1. Set variables — fill in ANTHROPIC_API_KEY, either as a value or from your vault.
  2. Choose how the store is backed — each store has a Local / Shared toggle:
    • Local (default) — the platform creates a managed Postgres database just for this agent.
    • Shared — point the store at a database you’ve connected to the account. One database can back several agents, so they share the same data. Pick it from the dropdown.
  3. Deploy — submit the form.

To use Shared, connect the database first under Knowledge > Add store (host, port, database, credentials — stored encrypted). Only matching, Ready stores can be selected. See Knowledge stores for connecting a database in a private network.

The agent then appears under Agents with its live status.


Adding a second store

When you have two stores of the same type, the entry name is added to the variables so they don’t clash:

1knowledge:
2 writer:
3 provider: postgres
4 analytics:
5 provider: postgres

One store is the primary and keeps the plain POSTGRES_* names; the others get the name added. The primary is the entry named after the provider, or — if none is — the first one alphabetically. Here analytics comes first:

EntryVariables
analytics (primary)POSTGRES_HOST, POSTGRES_USER, … and POSTGRES_ANALYTICS_HOST, POSTGRES_ANALYTICS_USER, …
writerPOSTGRES_WRITER_HOST, POSTGRES_WRITER_USER, …

Each store is backed on its own, so you can leave one Local and set another to Shared. To make a store the primary, name it after the provider (e.g. postgres:).


Next steps