From Postgres To Agentic AI, Building An Agent On Real Time Data

In this video we demonstrate how to build an AI agent which makes use of real time data. The scenario is a market making desk, where a trading application is writing orders and trades for 140 energy contracts into Postgres at around 3,000 operations per second. Rather than having the agent work from a stale overnight extract, we want it to reason over data that was written seconds earlier, because that is the situation most businesses are actually in when they ask what is happening right now. As I explained in Why ClickHouse Is The Best Data Platform For Agentic AI, the combination of freshness, low latency and high concurrency is what makes ClickHouse the natural foundation for this type of workload.
To bring the transactional and analytical worlds together, we integrated WalShadow into the demo. WalShadow is a recent open source project from ClickHouse which replicates Postgres into ClickHouse by reading the physical write ahead log rather than relying on logical replication, bringing commit to visible latency down to a fraction of a second. Postgres carries on doing what it is good at, serving the order book and the transactional workload of the application, while ClickHouse takes on the heavy analytical queries over the full history of events. This split means that analytics never slow down the trading application, and the agent gets a database that is designed to stand up to the many concurrent and sometimes unoptimised queries it will generate. I have written previously about replicating Postgres into ClickHouse with PeerDB and ClickPipes, and WalShadow is a significant step forward in both latency and simplicity.
Giving an agent a database connection is the easy part. The hard part is making sure it understands what the data means, so in the video we show how we deploy a semantic layer on top of ClickHouse which describes datasets such as trader activity in terms of dimensions, metrics and time grains. The agent builds its queries through this layer rather than guessing at raw tables and columns, which, as I discussed in What Do We Mean By Agentic Analytics, is where most of the accuracy and trust comes from. We then ask questions in natural language, such as summarising the activity of the top three traders over the last fifteen minutes, and the agent plans, runs a sequence of queries, inspects the results and explains its answer. The model behind it is an open weight DeepSeek model served by Fireworks AI rather than a frontier model, following the approach in Using Open Source and Open Weight LLMs With ClickHouse. For many business use cases these models are more than capable, at a fraction of the cost and with much stronger privacy guarantees.
Finally, we make use of Langfuse to trace everything the agent does. Langfuse is the ClickHouse native platform for LLM observability, capturing every prompt, tool call, query and response alongside its latency, token usage and cost. This is the piece that turns a prototype into something you can put in front of the business. When an answer looks wrong you can see exactly which queries the agent ran and where it went astray, you can evaluate the quality of responses over time, and you can govern what the system is spending. It is also where we see the most demand from clients, who are comfortable building agents but need the controls to run them in production.
This demo is representative of the agentic AI solutions we build for clients, taking them from prototype through to trustworthy, governed production systems built on real time data foundations. You can read more about how we approach this on our Agentic AI page, or get in touch if you would like to talk through a use case.

Written by
Benjamin Wootton
Founder & CTO, New Cadence
We are an independent ClickHouse consultancy. We help businesses deploy ClickHouse open source and ClickHouse Cloud, build solutions on top of ClickHouse for real-time analytics, observability and AI, and resolve performance and reliability issues with their existing deployments.
Connect on LinkedIn

