Skip to main content

Overview

This demo shows you how to build an AI agent that connects RisingWave with Anthropic’s LLM. The agent processes natural language queries and returns clean, readable results to users. The agent includes several key components:
  • Table extraction from SQL-like queries
  • Dynamic table schema fetching
  • MCP tool invocation
  • Result parsing and formatting
  • Chat loop management between RisingWave and Anthropic
In this tutorial, you’ll learn how to:
  • Implement a custom Anthropic agent
  • Integrate it with RisingWave MCP
  • Perform simple stream processing with RisingWave
For a complete project reference, clone the awesome-stream-processing repository.

Prerequisites

Before you begin, you need:

Step 1: Set up your environment

Create a .env file with your RisingWave connection configuration:

Step 2: Create the agent

Import the required dependencies

Import these modules for your agent:

Build the main agent class

The RisingWaveMCPAgent class manages connections and caches. Adjust the environment variables if you’re connecting to a remote RisingWave instance.

Add core functionality

Add these functions to handle tool usage and provide table context:
Add these final methods to handle query processing and manage the chat loop:

Add the main function

Add the entry point to start the program:

Step 3: Create test data

Create test data using the load generator tutorial or run this script:

Step 4: Run and test the agent

Start the agent

Run this command to start the agent:

Test the agent

Try these example commands: Get database information:
  • Give me the database version
Explore table schemas:
  • Show me the users table structure
Create and query materialized views:
  • Track the highest risk scores
  • Sort that mv by highest spending and display
Experiment with your own prompts and data! You can also use any of the demos to test the agent.

Clean up

When you finish testing:
  1. Stop the agent: Type quit in the agent interface.
  2. Clean up test data (optional): Ask the agent to “Drop the users table”.
  3. Stop RisingWave: Stop the RisingWave service if you started it for this demo.