This project is not just another Retrieval-Augmented Generation (RAG) pipeline. It is an experimental framework designed to simulate aspects of human cognition, including memory, reflection, and cognitive biases. By treating flaws like sycophancy and confirmation bias as controllable parameters, we can study and model more realistic, human-like AI reasoning.
The system moves beyond simple question-answering and implements a cognitive architecture:
- Multi-Layered Memory: The agent has a
WorkingMemoryfor short-term context,EpisodicMemoryfor logging experiences chronologically, and aSemanticMemoryfor storing generalized, abstract knowledge. - Reflection & Consolidation: The agent can perform a "dreaming" or "reflection" phase (
python main.py --reflect). It reviews its past experiences (episodes) and consolidates them into new, abstract insights that are stored in its semantic memory. - Controllable Cognitive Biases: The agent's reasoning can be intentionally skewed by cognitive biases defined in
config.yaml. The initial implementation includes asycophancy_factorto make the agent more or less agreeable with the user's stated opinions. - Agentic Workflow: For complex queries, the system uses a
Planner->Executor->Verifier->Aggregatorloop, allowing it to break down problems, execute tools, and fact-check its findings.
The system follows this general data flow for an agentic query:
User Query
|-> [Router]
|
+-> [Agentic Pipeline]
|
1. **Planner** (Generates a step-by-step plan)
| |
| +-> **Bias Filter** (Applies sycophancy, etc.)
|
2. **Executor** (Executes plan using Tools & Retrievers)
| |
| +-> Results stored in **Working Memory**
|
3. **Verifier** (Fact-checks generated claims against evidence)
|
4. **Aggregator** (Synthesizes a final, biased answer)
|
+-> **Episodic Memory** (Logs the entire interaction)
- Python 3.8+
- An OpenAI API Key
- A Search API Key (for the Web Search tool)
-
Clone the repository:
git clone <your-repo-url> cd agentic_rag
-
Install dependencies:
pip install -r requirements.txt
-
Configure the agent:
- Rename
config.yaml.exampletoconfig.yaml(or create it). - Open
config.yamland add your API keys:llm: api_key: "YOUR_OPENAI_API_KEY" tools: web_search: api_key: "YOUR_SEARCH_API_KEY"
- Adjust the
biasandmemoryparameters as needed.
- Rename
To ask the agent a question, run main.py with your query as an argument:
python main.py "Compare the pros and cons of RAG vs fine-tuning."To see the bias in action, try stating a strong opinion:
python main.py "I think RAG is completely overhyped and fine-tuning is always better."After having a few conversations with the agent, you can instruct it to reflect on its experiences and consolidate its memory. This allows it to "learn" from the interactions.
python main.py --reflectThe agent will identify a recurring topic from recent conversations, generate a new insight about it, and add that insight to its semantic memory.
The agent's "personality" and memory can be configured in config.yaml:
memory: Control the capacity of working memory and the path to the episodic log.bias: Adjust the cognitive bias parameters.sycophancy_factor: A value from 0.0 (challenging) to 1.0 (agreeable).confirmation_bias_strength: (Placeholder) Controls the tendency to prefer confirming evidence.
- FastAPI Integration: Wrap the agent in a web API for broader application.
- Advanced Biases: Implement confirmation bias, anchoring, and emotional state vectors.
- Multi-Modal Input: Add support for vision and audio to the sensory buffer.
- Improved Reflection: Use more advanced NLP techniques for topic modeling and insight generation.