AI agent generation system using RAG (Retrieval-Augmented Generation).
Description
LLM Agent Factory is an intelligent system that generates structured AI agent descriptions based on user queries. The system uses a RAG approach: finds similar agents in the database and generates a new agent using LLM, adapting it to your query.
Each generated agent contains:
agent_id — unique identifier
display_name — human-readable name
persona — agent's character and expertise
description — what the agent does and how it helps the user
role_id — agent role (researcher, coder, tutor, etc.)
domain — subject area
tools — list of tools (web_search, code_interpreter, etc.)
1# With RAG generation support2pip install -e ".[rag]"
Requirements: Python >= 3.12
Configuration
Environment Variables
For LLM API access, create a .env file in the project root (or set environment variables):
bash
1# Copy the example file2cp env.example .env
34# Edit .env and add your API credentials5LLM_API_KEY=your-api-key-here
6LLM_BASE_URL=https://api.openai.com/v1
7LLM_MODEL=gpt-oss-120b
Note: The .env file is already in .gitignore and will not be committed to the repository.
Alternatively, you can pass API credentials via command-line arguments or in code (see usage examples below).
Quick Start
1. Search Existing Agents
Find a suitable agent in the database (~22,000 agents):
bash
1# Interactive search mode2agent-search
34# Or single query5agent-search -q "Python programming help" -k 5
2. Generate New Agent by Query
Create a unique agent using RAG:
bash
1# Interactive generation mode2agent-generate
34# Or immediate generation5agent-generate "I need an agent for code review in Python"67# Generate multiple variants8agent-generate --agents 3"customer support specialist"
Usage
Agent Search (Retrieval)
The system supports semantic agent search using embedding models and optional reranking.
Interactive Mode Commands
Command
Description
/switch <dataset>
Switch dataset (eng, all)
/topk <n>
Change number of results
/rerank
Enable/disable reranking
/stats
Show statistics
/help
Show help
/quit
Exit
Usage Examples
bash
1# Search with English dataset (default)2agent-search
34# With English dataset (default)5agent-search -d eng
67# Use all datasets together8agent-search -d all
910# With reranking for better accuracy11agent-search --rerank -q "machine learning expert"1213# Choose embedding model14agent-search --model bge-large -q "data analyst"1516# Multilingual search17agent-search --model bge-m3 -d all -q "programming"
Agent Generation (RAG)
RAG system combines search for similar agents with LLM generation to create unique agents.
Interactive Mode Commands
Command
Description
generate <query>
Generate agent by query
search <query>
Only search for similar agents
dataset <name>
Switch dataset (eng, all)
agents <N>
Number of agents to generate (1-10)
examples <N>
Number of examples for context (1-20)
format <type>
Output format (json, pretty)
stats
Show configuration
help
Help
quit
Exit
Usage Examples
bash
1# Interactive mode2agent-generate
34# Single generation5agent-generate "I need an agent that helps with code review"67# Generate multiple variants8agent-generate --agents 3"customer support agent"910# With pretty formatting11agent-generate --format pretty "data analysis helper"1213# English dataset (default)14agent-generate --dataset eng "programming assistant"1516# More examples for context17agent-generate --examples 10"medical diagnosis assistant"1819# Configure LLM temperature20agent-generate --temperature 0.9"creative writing assistant"
A: Start with bge-small. For high quality use bge-large. For multilingual use bge-m3.
Q: What is reranking and do I need it?
A: Reranking is two-stage retrieval. The first stage quickly finds candidates, the second accurately ranks them. Improves quality but slows down search.
Q: What's the difference between agent-search and agent-generate?
A: agent-search (Retrieval) searches for existing agents in the database. agent-generate (RAG) creates new unique agents using LLM based on your query and similar agents.
Q: Which dataset should I use?
A: eng for English queries (default), all for all datasets (same as eng).
Q: How to configure my own LLM?
A: Use parameters --model, --url, --api-key in CLI or create LLMConfig in code.
Q: First initialization takes long?
A: Yes, on first run the embedding index is built (~1-2 minutes). It's cached in retrieval/.cache/ and subsequent runs are fast.
Testing
bash
1# Run all tests2pytest retrieval/tests/ -v
34# Only retrieval tests5pytest retrieval/tests/test_retriever.py -v
67# Only RAG tests8pytest retrieval/tests/test_rag.py -v
910# With coverage11pytest retrieval/tests/ --cov=retrieval --cov-report=term-missing
Support
If you have questions or issues, create an issue in the repository.