A simple AI coding agent that combines Retrieval-Augmented Generation (RAG) with file writing capabilities. It can search through your documentation and generate code files based on your requests.
This is a basic RAG-powered AI agent that:
- 📖 Reads documents from a
docs/folder - 🔍 Searches through them using vector embeddings
- 💬 Answers questions based on the documentation
- 📝 Writes code files to a
workplace/directory - 🧠 Uses LangChain + ChromaDB for RAG functionality
What it's NOT:
- Not a production-ready tool
- Not optimized for large-scale use
- Just a learning project for RAG + agents
rag-coder/
├── agent.py # Loads documents from docs/ folder
├── config.py # Configuration using pydantic-settings
├── llm.py # LLM provider setup (OpenRouter or Groq)
├── main.py # Main entry point with agent loop
├── tools.py # Agent tools (write files, search docs)
├── vectorstore.py # ChromaDB vector store setup
├── docs/ # Put your .txt or .md files here
├── workplace/ # Generated files go here
└── .chromadb/ # Vector database (auto-created)
- Python 3.9+
- OpenRouter API key OR Groq API key
- Basic understanding of virtual environments
cd rag-coderWindows:
python -m venv .venv
.venv\Scripts\activateLinux/Mac:
python3 -m venv .venv
source .venv/bin/activatepip install langchain langchain-community langchain-openai langchain-groq langchain-huggingface
pip install chromadb
pip install pydantic-settings
pip install langchain-text-splittersCreate a file named .env in the project root:
For OpenRouter: (Get your API key from https://openrouter.ai/keys)
OPEN_ROUTER_API_KEY=your_openrouter_api_key_here
OPENROUTER_URL_BASE=https://openrouter.ai/api/v1
LLM_MODEL_NAME=meta-llama/llama-3.1-8b-instruct:freeFor Groq: (Get your API key from https://console.groq.com/keys)
GROQ_API_KEY=your_groq_api_key_here
LLM_MODEL_NAME=llama3-8b-8192Put your .txt or .md files in the docs/ folder:
# Example: Create a document
echo "Python is a programming language" > docs/python_info.txtThe agent will load these documents on startup and use them to answer questions.
python main.pyAsk questions about your docs:
🧑 You: What is Python?
The agent will search the docs and answer based on the content.
Generate code files:
🧑 You: Write a hello world program in Python
The agent will create the file in the workplace/ directory.
Exit:
🧑 You: exit
Put any .txt or .md file in the docs/ folder:
docs/
├── test.txt
├── my_notes.md
└── project_info.txtThe documents are loaded when you run python main.py. Just restart to load new docs.
The agent will automatically search through all documents when you ask questions.
Example:
# Add this to docs/kavy.txt
Name: Kavy Gajjar
Email: gajjarkav@gmail.com
Website: https://kavy.dev
Then ask:
🧑 You: Who is Kavy Gajjar?
The agent will search the docs and provide the information.
-
Document Loading (
agent.py):- Scans
docs/folder for.txtand.mdfiles - Splits documents into chunks (800 chars, 100 overlap)
- Uses HuggingFace embeddings (all-MiniLM-L6-v2)
- Scans
-
Vector Store (
vectorstore.py):- Creates ChromaDB vector database
- Stores document embeddings
- Provides similarity search retriever
-
Agent (
main.py):- Uses LangChain agents with tool calling
- Has 2 tools:
search_documentationandwrite_files - Decides when to search docs or write files
-
LLM Provider (
llm.py):- Supports OpenRouter or Groq
- Reads API key from
.envfile
- 🐌 Slow document loading on first run
- 📦 Limited to small document sets (not optimized)
- 🔄 Requires restart to load new documents
- 🎯 Basic tool calling (no advanced features)
- 🗂️ No document management UI
- ⚡ Not async (blocking operations)
"No LLM API key found"
- Check your
.envfile exists - Verify the API key variable names match
"VectorStoreRetriever object has no attribute..."
- Update LangChain packages:
pip install --upgrade langchain langchain-community
"Loaded 0 documents"
- Make sure you have
.txtor.mdfiles in thedocs/folder
"Error: write_file() missing argument"
- This should be fixed with StructuredTool. If not, reinstall langchain-core
- LangChain - Agent framework
- ChromaDB - Vector database
- HuggingFace - Embeddings (all-MiniLM-L6-v2)
- OpenRouter/Groq - LLM providers
- Pydantic - Settings management
- Auto-reload documents without restart
- Support for PDF, DOCX files
- Better error handling
- Document metadata tracking
- Multiple workspace folders
- Web interface
- Chat history persistence
Do whatever you want with this code. No warranty, no guarantees.
Made by someone learning RAG and AI agents.
Note: This is a learning project. Don't use it for anything important without proper testing and improvements.
A simple AI coding agent that combines Retrieval-Augmented Generation (RAG) with file writing capabilities. It can search through your documentation and generate code files based on your requests.
This is a basic RAG-powered AI agent that:
- 📖 Reads documents from a
docs/folder - 🔍 Searches through them using vector embeddings
- 💬 Answers questions based on the documentation
- 📝 Writes code files to a
workplace/directory - 🧠 Uses LangChain + ChromaDB for RAG functionality
What it's NOT:
- Not a production-ready tool
- Not optimized for large-scale use
- Just a learning project for RAG + agents
rag-coder/
├── agent.py # Loads documents from docs/ folder
├── config.py # Configuration using pydantic-settings
├── llm.py # LLM provider setup (OpenRouter or Groq)
├── main.py # Main entry point with agent loop
├── tools.py # Agent tools (write files, search docs)
├── vectorstore.py # ChromaDB vector store setup
├── docs/ # Put your .txt or .md files here
├── workplace/ # Generated files go here
└── .chromadb/ # Vector database (auto-created)
- Python 3.9+
- OpenRouter API key OR Groq API key
- Get OpenRouter API key: https://openrouter.ai/keys
- Get Groq API key: https://console.groq.com/keys
- Basic understanding of virtual environments
cd rag-coderWindows:
python -m venv .venv
.venv\Scripts\activateLinux/Mac:
python3 -m venv .venv
source .venv/bin/activatepip install langchain langchain-community langchain-openai langchain-groq langchain-huggingface
pip install chromadb
pip install pydantic-settings
pip install langchain-text-splittersCreate a file named .env in the project root:
For OpenRouter:
OPEN_ROUTER_API_KEY=your_openrouter_api_key_here
OPENROUTER_URL_BASE=https://openrouter.ai/api/v1
LLM_MODEL_NAME=meta-llama/llama-3.1-8b-instruct:freeFor Groq:
GROQ_API_KEY=your_groq_api_key_here
LLM_MODEL_NAME=llama3-8b-8192Put your .txt or .md files in the docs/ folder:
# Example: Create a document
echo "Python is a programming language" > docs/python_info.txtThe agent will load these documents on startup and use them to answer questions.
python main.pyAsk questions about your docs:
🧑 You: What is Python?
The agent will search the docs and answer based on the content.
Generate code files:
🧑 You: Write a hello world program in Python
The agent will create the file in the workplace/ directory.
Exit:
🧑 You: exit
Put any .txt or .md file in the docs/ folder:
docs/
├── test.txt
├── my_notes.md
└── project_info.txtThe documents are loaded when you run python main.py. Just restart to load new docs.
The agent will automatically search through all documents when you ask questions.
Example:
# Add this to docs/kavy.txt
Name: Kavy Gajjar
Email: gajjarkav@gmail.com
Website: https://kavy.dev
Then ask:
🧑 You: Who is Kavy Gajjar?
The agent will search the docs and provide the information.
-
Document Loading (
agent.py):- Scans
docs/folder for.txtand.mdfiles - Splits documents into chunks (800 chars, 100 overlap)
- Uses HuggingFace embeddings (all-MiniLM-L6-v2)
- Scans
-
Vector Store (
vectorstore.py):- Creates ChromaDB vector database
- Stores document embeddings
- Provides similarity search retriever
-
Agent (
main.py):- Uses LangChain agents with tool calling
- Has 2 tools:
search_documentationandwrite_files - Decides when to search docs or write files
-
LLM Provider (
llm.py):- Supports OpenRouter or Groq
- Reads API key from
.envfile
- 🐌 Slow document loading on first run
- 📦 Limited to small document sets (not optimized)
- 🔄 Requires restart to load new documents
- 🎯 Basic tool calling (no advanced features)
- 🗂️ No document management UI
- ⚡ Not async (blocking operations)
"No LLM API key found"
- Check your
.envfile exists - Verify the API key variable names match
"VectorStoreRetriever object has no attribute..."
- Update LangChain packages:
pip install --upgrade langchain langchain-community
"Loaded 0 documents"
- Make sure you have
.txtor.mdfiles in thedocs/folder
"Error: write_file() missing argument"
- This should be fixed with StructuredTool. If not, reinstall langchain-core
- LangChain - Agent framework
- ChromaDB - Vector database
- HuggingFace - Embeddings (all-MiniLM-L6-v2)
- OpenRouter/Groq - LLM providers
- Pydantic - Settings management
Do whatever you want with this code. No warranty, no guarantees.
Made by KavyGajjar
Note: This is a learning project. Don't use it for anything important without proper testing and improvements.