- Generates relevant search queries from user messages
- Retrieves and evaluates information from your knowledge base
- Provides streaming responses with real-time status updates
- Handles complex multi-step reasoning automatically
Prerequisites
Before getting started, make sure you have:- A Next.js application set up
- An Agentset API key and namespace configured
- An OpenAI API key for the language model
1
Install Dependencies
Install the required packages for building agentic RAG applications with AI SDK integration.Key packages:
@agentset/ai-sdk
: Provides the AgenticEngine for agentic RAG workflows@ai-sdk/react
: React hooks for chat functionality with streaming supportagentset
: Core SDK for interacting with your knowledge baseai
: AI SDK core with UI message utilities
2
Configure Your Language Model
Set up your language model configuration that will be used by the AgenticEngine for query generation, evaluation, and answer synthesis.Make sure to add your OpenAI API key to your environment variables:
lib/llm.ts
.env.local
3
Create the API Route
Create an API route that handles chat requests using the AgenticEngine with proper message validation and streaming support.Key features:
app/api/chat/route.ts
- Message validation: Ensures UI messages are properly formatted
- Streaming response: Provides real-time updates during the agentic process
- Error handling: Graceful error management with custom error messages
- Three-step process: Query generation → evaluation → answer synthesis
4
Build the Frontend Chat Interface
Create a React component that provides a complete chat interface with support for agentic RAG status updates and query visibility.Enhanced features:
app/page.tsx
- Status updates: Shows real-time progress of the agentic process
- Query visibility: Displays the generated search queries
- Improved UX: Better styling and responsive design
- Type safety: Uses
AgentsetUIMessage
type for better TypeScript support
5
Test Your Agentic RAG Application
Start your Next.js application and test the agentic RAG functionality:Your chat application will now:
- Generate queries from user messages automatically
- Search your knowledge base using the generated queries
- Evaluate results and determine if more information is needed
- Synthesize answers based on retrieved information
- Stream responses with real-time status updates
Advanced Configuration
The AgenticEngine supports several optional parameters for fine-tuning:maxEvals
: Maximum number of evaluation rounds (default: 3)tokenBudget
: Token budget for the entire process (default: 4096)queryOptions
: Search configuration liketopK
,rerankLimit
, andrerank
settings