AI Coding Agent - LangChain with SQLite Checkpoint
A LangChain-based AI coding assistant with SQLite persistent conversation history. This example demonstrates how to use LangChain agents with AG-Kit tools and SQLite checkpoint for conversation persistence.
Features
- 🤖 LangChain Integration - Built on LangChain with AG-Kit tool conversion
- 💾 SQLite Persistence - Conversation history stored in SQLite database
- 🔧 AG-Kit Tools - Full access to AG-Kit's React coding tools
- 📝 Interactive CLI - Simple command-line interface for testing
- 🔄 Memory Management - Persistent conversation state across sessions
Prerequisites
- Node.js 18+
- OpenAI API key
Quick Start
Environment Variables
Create a .env file with:
OPENAI_API_KEY=your_openai_api_key
OPENAI_MODEL=gpt-4o-mini
OPENAI_BASE_URL=https://api.openai.com/v1
Usage
Interactive Mode
Start the interactive CLI:
npm run interactive
Example conversation:
💬 You: Create a React component for a todo list
🤖 Assistant:
I'll help you create a React todo list component. Let me create a new component file...
💬 You: Add TypeScript support to this component
🤖 Assistant:
I'll convert the component to TypeScript with proper type definitions...
Programmatic Usage
import { createAgent } from '@cloudbase/agent-examples-langchain-ai-coding';
const agent = createAgent({
baseProjectPath: '/path/to/projects',
projectName: 'my-react-app',
autoInstallDependencies: true,
});
const response = await agent.invoke({
messages: [{ role: 'user', content: 'Create a React component' }]
});
console.log(response.content);
Architecture
This example demonstrates:
- LangChain Agent Creation - Using the existing
agent.ts implementation
- AG-Kit Tool Integration - Converting AG-Kit tools to LangChain format
- SQLite Checkpoint - Persistent conversation storage using LangChain's SQLite checkpoint
- Interactive CLI - Simple readline-based interface for testing
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ User Input │───▶│ LangChain Agent │───▶│ AG-Kit Tools │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │
▼ ▼
┌──────────────────┐ ┌─────────────────┐
│ SQLite Checkpoint│ │ React Coding │
└──────────────────┘ └─────────────────┘
Project Structure
src/
├── agent.ts # LangChain agent implementation
└── index.ts # Main exports
examples/
└── full-workflow.ts # Interactive CLI example
Available Commands
npm run build - Build the project
npm run interactive - Start interactive CLI
Troubleshooting
OpenAI API Issues
- Verify your API key is correct
- Check you have sufficient credits
- Ensure the model name is supported
SQLite Database
The SQLite database (checkpoints.db) will be created automatically in the project directory when you first run the agent.
Contributing
This example is part of the AG-Kit project. Please refer to the main project's contributing guidelines.
License
MIT License - see the main AG-Kit project for details.