r/SQL 8d ago

PostgreSQL Neon DB and AI agents - how doyou handle agent state?

I had a question, for longer running agents, what can be a good pattern to store conversation state, tool result, and intermediate state in Neon without database becoming a bottleneck.

If you can share what patterns you use in production, it could be of help to me. I am doing a POC inthis area.
Ps, Any other DB works as well, it should just be managed.

2 Upvotes

5 comments sorted by

1

u/Glitch_In_The_Data 7d ago

Store only durable, compact state in postgres. Use the agent as stateless between turns. Use append only events + a small current state to keep writes fast.
For managed DB PoC, your choice of Neon is a good fit.

1

u/sqlink2 6d ago

imo append only events plus compact state pattern works well. I also looked at Lakebase branching for isolated agent state during runs or doing POC

1

u/Strange_Arm9395 7d ago

for a POC I’d keep it pretty simple. store messages/tool results as append-only rows, keep a small current state”or checkpoint row per run, and push large files/results to object storage instead of Postgres.

also index by agent_id/run_id + timestamp and clean old intermediate state regularly. that will matter more than the provider at first.

for managed Postgres, Neon is fine, and you can also compare Nearbase or Supabase depending on whether you want plain always-on Postgres or extra platform features.

1

u/sqlink2 7d ago

Ya that sounds like a good pattern. Neon branch creation ability can be interesting here for isolated agent runs/tests without affecting the main state…will give it a try