Skip to content

Conversation

@jumski
Copy link
Contributor

@jumski jumski commented Jan 19, 2026

Add Chatbot with pgflow Tutorial and Update Navigation

This PR adds a comprehensive tutorial on building an advanced chatbot using pgflow for context gathering and AI SDK for streaming responses. The tutorial demonstrates a sophisticated two-phase architecture:

  1. A multi-step pgflow workflow that gathers context from conversation history, knowledge base, web search, and memory in parallel
  2. An Edge function that loads the prepared context and streams AI responses

The tutorial includes:

  • Complete database schema with vector search capabilities
  • Implementation of 8 task functions for different stages of context gathering
  • A pgflow workflow definition that orchestrates parallel processing
  • Edge function for streaming responses
  • React component using pgflow client and AI SDK's useChat hook

Additionally, this PR updates the website navigation to include the new chatbot tutorial and makes minor formatting improvements to the pgflow 0.8.0 release notes.

The tutorial provides a production-ready implementation that showcases pgflow's capabilities for complex AI workflows with real-time progress tracking.

Add a new tutorial showing how to build a production-ready chatbot that:
- Uses pgflow to orchestrate multi-step context gathering
- Performs parallel retrieval from 3 sources (semantic search, web search, memory)
- Implements merge and reranking of results
- Streams responses using AI SDK's useChat hook
- Shows real-time progress updates via pgflow client

The tutorial demonstrates:
- Multi-step flow with parallel execution
- Browser client integration with real-time progress
- Edge function for SSE chat streaming
- Separation of context gathering from response streaming
- Complete database schema, task implementations, and flow definition

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Jan 19, 2026

⚠️ No Changeset found

Latest commit: 02b2f5e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor Author

jumski commented Jan 19, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@nx-cloud
Copy link

nx-cloud bot commented Jan 19, 2026

View your CI Pipeline Execution ↗ for commit 02b2f5e

Command Status Duration Result
nx test:types:health dsl ✅ Succeeded 12s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-19 10:12:37 UTC

Comment on lines +1037 to +1040
export async function POST(req: Request) {
const { messages, data } = await req.json();
const { runId, conversationId } = data;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical data extraction bug. The useChat hook does not automatically extract the data property from individual messages and send it at the top level of the request body. When append() is called with data on line 930-933, that data remains within the message object, not at the request body's top level.

This will cause data to be undefined on line 1038, leading to destructuring errors when trying to extract runId and conversationId.

Fix: Use the body option in useChat to send additional data:

const { messages, input, setInput, append, isLoading } = useChat({
  api: '/api/chatbot-stream',
  body: {
    conversationId,
  },
  onError: (error) => {
    console.error('Chat error:', error);
  },
});

Then pass runId through the message's data field and extract it in the API route:

export async function POST(req: Request) {
  const { messages, conversationId } = await req.json();
  const lastMessage = messages[messages.length - 1];
  const runId = lastMessage.data?.runId;
  // ...
}
Suggested change
export async function POST(req: Request) {
const { messages, data } = await req.json();
const { runId, conversationId } = data;
export async function POST(req: Request) {
const { messages, conversationId } = await req.json();
const lastMessage = messages[messages.length - 1];
const runId = lastMessage.data?.runId;

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants