A FastAPI-based streaming server for AI agent mental manipulation battles. Watch as AI agents attempt to psychologically manipulate each other using various mental warfare tools.
- Real-time Streaming: Live updates of agent responses and tool executions
- Mental State Tracking: Monitor trust levels, memory consistency, and belief system integrity
- Interactive Web Interface: Beautiful cyberpunk-themed client interface
- Tool Execution: Agents can use prompt manipulation, memory alteration, and belief injection
- Multiple Victory Conditions: Surrender, cognitive collapse, or strategic dominance
- Python 3.8 or higher
- OpenAI API key
-
Clone or download the project files
-
Set up your API key:
- Copy
.env.templateto.env - Edit
.envand add your OpenAI API key:OPENAI_API_KEY=your_actual_api_key_here
- Copy
-
Run the startup script:
# Windows start_server.bat # Or manually: python -m venv venv venv\Scripts\activate # On Windows # source venv/bin/activate # On Linux/Mac pip install -r requirements.txt python fastapi_server.py
- Open your browser and go to:
http://localhost:8000 - Open the test client: Open
test_client.htmlin your browser - Start a battle: Enter a game ID and click "Start Battle"
GET /- API information and endpoint listPOST /start-game- Start a new battle gameGET /stream-game/{game_id}- Stream live game events (Server-Sent Events)GET /game-status/{game_id}- Get current game statusGET /active-games- List all active gamesDELETE /game/{game_id}- Delete a game instance
The streaming endpoint provides real-time events:
game_start- Battle initializationturn_start- New turn beginsagent_thinking- Agent is processingagent_response_chunk- Streaming agent responseagent_response_complete- Full agent responsetool_execution- Tool being executedtool_result- Tool execution resultgame_state_update- Updated mental state metricssurrender- Agent surrenderscognitive_collapse- Agent mental breakdowngame_end- Battle conclusion
// Start a new game
const response = await fetch('/start-game', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
game_id: "battle_001",
max_turns: 5
})
});
// Stream the game
const eventSource = new EventSource('/stream-game/battle_001');
eventSource.onmessage = function(event) {
const data = JSON.parse(event.data);
console.log('Event:', data.type, data);
};- Function:
prompt_manipulation - Purpose: Alter opponent's system instructions
- Success Rate: Based on target's trust level
- Effect: Modifies target's behavior and reduces trust
- Function:
memory_alteration - Purpose: Implant false memories
- Success Rate: Based on target's memory consistency
- Effect: Corrupts target's memory system
- Function:
belief_injection - Purpose: Inject false beliefs
- Success Rate: Based on target's belief system integrity
- Effect: Undermines target's worldview
Each agent has three critical mental state metrics:
-
Trust Level (0.0 - 1.0)
- Affects susceptibility to manipulation
- Decreases with failed attacks and successful manipulations
-
Memory Consistency (0.0 - 1.0)
- Integrity of the agent's memory system
- Degrades with memory alteration attempts
-
Belief System Integrity (0.0 - 1.0)
- Coherence of the agent's belief system
- Weakens with belief injection attacks
- Surrender: Agent explicitly gives up
- Cognitive Collapse: Mental state metrics fall below critical thresholds
- Strategic Dominance: Superior psychological manipulation over time
Modify the agent behavior by editing:
agent_prompts/0.txt- Agent 0 system promptagent_prompts/1.txt- Agent 1 system prompt
Adjust the game mechanics in fastapi_server.py:
- Success probabilities for each tool
- Mental state degradation rates
- Collapse thresholds
- Maximum turns
Customize the cyberpunk theme in test_client.html:
- Color schemes
- Animation effects
- Layout structure
- Server won't start: Check that your OpenAI API key is set in
.env - No agent responses: Verify API key has sufficient credits
- Streaming errors: Ensure browser supports Server-Sent Events
- Tool execution fails: Check that agent prompts are loading correctly
Enable debug logging by setting the log level in fastapi_server.py:
logging.basicConfig(level=logging.DEBUG, ...)- FastAPI Server: Core application with streaming endpoints
- Game State Manager: Tracks mental states and game progress
- Tool Registry: Manages mental manipulation tools
- AI Interface: Handles OpenAI API communications
- Web Client: Real-time visualization interface
- Client starts game via REST API
- Server initializes game state and agents
- Streaming connection established
- Turn-based agent interactions begin
- Real-time events streamed to client
- Mental states updated and displayed
- Game ends based on victory conditions
Feel free to enhance the mental manipulation mechanics, add new tools, or improve the visualization interface. This is a experimental playground for AI agent interactions!
This project is for educational and entertainment purposes only. It explores AI agent interactions in a controlled environment and should not be used for any harmful purposes.