This project is a Proof of Concept (PoC) for building Agentic AI systems capable of Continuous Learning.
Unlike traditional LLM chains that reset their state after every interaction, this agent possesses a persistent Long-Term Memory. It uses the Reflexion technique to analyze its own mistakes, extract general rules/lessons, and store them on the disk. When faced with new tasks, it recalls these lessons to avoid repeating past errors.
Built using LangGraph, it demonstrates a cyclic graph architecture rather than a linear chain.
- π Reflexion Loop: The agent acts, receives feedback from the environment, and reflects on why it failed before trying again.
- πΎ Long-Term Memory: Lessons are stored in a JSON file (
agent_memory.json), allowing knowledge to persist across different execution sessions. - π§ Knowledge Transfer: The agent applies constraints learned in "Task A" to "Task B" automatically.
- π‘οΈ Robust Parsing: Includes a smart validation node that handles various code formats outputted by LLMs.
The system is modeled as a State Graph with three main nodes:
- Generator (Agent): Generates Python code. It reads the Long-Term Memory before generating to ensure it respects previously learned rules.
- Validator (Environment): Executes the code and checks against specific rules (e.g., "Sum must be 100", "Number 50 is forbidden"). It acts as a simulator.
- Reflector (Critic): Triggered only upon failure. It translates raw error messages into high-level "Lessons" and saves them to the memory file.
graph TD
Start([Start]) --> Generator
Generator --> Validator
Validator -- "Valid Output" --> Success([End / Success])
Validator -- "Error / Invalid" --> Reflector
Reflector -- "Save Lesson to JSON" --> Generator