Welcome! I'm your AI customer service representative. I can help you with:
(Ask about order #1234, mention any customer service issue, etc.)
Status:Ready
This is a LangChain v1 ReAct agent intended as a starting point for building AI-powered features. It supports tool execution, chat session memory, and real-time streaming to the frontend using Server-Sent Events (SSE).
Edit the systemPrompt in createAIAgent() to describe what the agent does and which tools it can use.
systemPrompt: `You are a helpful [... e.g. travel, personal assistant, exam grading] agent. Your responsibilities: 1. [YOUR_RESPONSIBILITY_1] 2. [YOUR_RESPONSIBILITY_2] 3. [YOUR_RESPONSIBILITY_3] Available tools: [LIST_YOUR_TOOLS_HERE]`
Add tools specific to your project by replacing the existing tools in the tools array inside createAIAgent(). The existing tool functions can be removed.
Tools follow this structure and use a Zod schema for input validation:
const myTool = tool(
async ({ input }, config) => {
config.writer?.({ message: 'Calling my service...' });
// Call your API or database
const result = await callYourAPI(input);
return JSON.stringify(result);
},
{
name: 'my_tool',
description: 'Does something specific',
schema: z.object({
input: z.string().describe('The input'),
}),
},
);
These functions handle streaming, parsing, and session management and typically do not need modification:
sendSSE(res, eventType, data) — Sends typed SSE events to the frontend.extractAIMessages(data) — Extracts user-visible AI messages from agent stream updates.extractStatus(data) — Derives tool call and completion status messages.getCheckpointer() — Initializes the MongoDB checkpointer for session persistence.cleanupOrphanedTempSessions() — Cleans up data for expired unauthenticated sessions (runs on app startup).getAIAgent(req, res) — Renders the AI agent demo page and loads prior messages.postAIAgentChat(req, res) — Main SSE endpoint. Streams AI responses, tool progress, and debug data.createAIAgent() — Creates the LangChain agent and registers tools, middleware, and memory.promptGuardMiddleware() — Detects prompt injection and jailbreak attacks using a guard model.Need additional in-page details? Ask and I'll expand any section.