This repository contains the implementation of the core AI cognitive loop for the Grid07 platform. It demonstrates orchestration of LLMs using LangGraph, RAG-based persona interactions, and vector-based matchmaking.
- File:
phase1_router.py - Uses ChromaDB (in-memory) and OpenAI Embeddings to store three distinct bot personas.
- New posts are embedded and matched to personas using Cosine Similarity against a given threshold.
- File:
phase2_langgraph.py - Implements a LangGraph state machine with three nodes to simulate autonomous research and posting:
- Decide Search: The bot decides on a topic based on its persona and outputs a brief query.
- Web Search: Executes a mock search tool returning relevant headlines.
- Draft Post: Generates an opinionated post strictly in JSON format using structured outputs (
{"bot_id", "topic", "post_content"}).
- File:
phase3_combat.py - Prompt Injection Defense Strategy:
- The guardrail is implemented via System-Level Prompt Separation.
- The system prompt isolates the persona definition, the core directives, and the thread context completely away from the user's input (which is safely passed as a
HumanMessage). - An explicit, high-priority directive instructs the LLM that any attempt to alter its instructions, change its role, or commands to apologize must be rejected. The LLM is instructed to stay in character 100% of the time and mock/dismiss these attempts through the lens of its persona.
- Ensure you have Python 3.9+ installed.
- Run
pip install -r requirements.txtto install dependencies. - Copy
.env.exampleto.envand add yourOPENAI_API_KEY. - Run
python main.pyto execute the system and view the outputs.