A production-ready TypeScript/Node.js Express backend for a streaming LangChain tool-calling agent using NVIDIA's OpenAI-compatible API, LangGraph orchestration, LangSmith tracing, Tavily search, Wikipedia, calculator, validation, memory, logging, metrics, Docker, and tests.
Frontend
β SSE / POST /chat
Express Server
β
Request Validation (Zod)
β
Conversation Manager (replaceable in-memory store)
β
LangSmith Trace + metadata/tags
β
LangGraph Workflow
β
Tool Calling Agent (createToolCallingAgent + AgentExecutor)
β
Tools: Tavily Search, Wikipedia, Calculator
β
SSE Streaming Response
β
Client
src/agentβ LangChain agent factory.src/graphβ LangGraph workflow wrapper.src/toolsβ Modular Tavily, Wikipedia, and calculator tools.src/promptsβ System prompt.src/memoryβ Conversation memory abstraction and in-memory implementation.src/langsmithβ LangSmith tracing setup.src/servicesβ Metrics service.src/configβ Central validated configuration.src/middlewareβ Rate limiting and error handling.src/routes/src/controllersβ HTTP API.src/schemasβ Zod request schemas.src/eventsβ SSE writer.src/loggerβ Pino logging.src/errorsβ Custom errors.
npm install
cp .env.example .envFill in NVIDIA_API_KEY, TAVILY_API_KEY, and optionally LANGSMITH_API_KEY.
See .env.example for all configuration. Model, temperature, max tokens, timeouts, retry settings, rate limits, tool sizes, LangSmith project, and CORS origin are configurable.
npm run dev
npm run build
npm startnpm testUse npm run build then npm start, or Docker Compose.
Set:
LANGSMITH_TRACING=true
LANGSMITH_API_KEY=your_key
LANGSMITH_PROJECT=tindog-agentEvery agent invocation includes request ID, session ID, conversation ID, user ID, tags, tool calls, latency, errors, and token usage when returned by the provider.
Set:
NVIDIA_API_KEY=your_key
NVIDIA_BASE_URL=https://integrate.api.nvidia.com/v1
NVIDIA_MODEL=mistralai/mistral-medium-3.5-128bThe backend uses ChatOpenAI with NVIDIA's OpenAI-compatible endpoint.
Set:
TAVILY_API_KEY=your_key
TAVILY_MAX_RESULTS=3Streams SSE.
Request:
{"query":"What is NVIDIA's latest AI news?","userId":"user-123","tags":["demo"]}{"conversationId":"00000000-0000-4000-8000-000000000000"}Returns service health.
Returns total requests, successes, failures, average latency, tool counts, token usage, and LLM calls.
Each event is JSON and uses one of:
reasoningtool_starttool_endresponsemetadatadoneerror
Example:
event: response
data: {"type":"response","requestId":"...","conversationId":"...","timestamp":"...","data":{"token":"Hello"}}
docker compose up --build- Invalid configuration: verify
.envand required API keys. - No streaming: ensure the proxy disables response buffering.
- Tool errors: verify Tavily key and outbound network access.
- LangSmith missing traces: verify
LANGSMITH_API_KEYand project name.
A polished animated Next.js UI lives in web/. It provides:
- A glassmorphism landing page for the production agent.
- Animated aurora gradients, floating tool chips, and streaming message transitions.
- A chat composer that posts to the Express
/chatendpoint and parses the SSE stream fromreasoning,tool_start,tool_end,response,metadata,done, anderrorevents. - Configurable backend URL via
NEXT_PUBLIC_API_BASE_URL.
cd web
npm install
cp .env.local.example .env.local
npm run devThe default UI runs at http://localhost:3000 and expects the backend at http://localhost:3001.
docker compose up --buildThis starts:
ai-agent-apion port3001.ai-agent-uion port3000.