This is the Python backend for the SimuVerse agent simulation system that handles agent decision making using OpenAI's GPT models.
-
Install the required dependencies:
pip install -r requirements.txt
-
Create a
.envfile in this directory with your OpenAI API key:OPENAI_API_KEY=your_api_key_here -
Run the server:
python main.py
Agent profiles are stored in agent_profiles.json. Each agent has the following configurable properties:
personality: Defines the agent's personality traits and characteristicstask: The current task or objective for the agentdefault_location: The default starting location (e.g., "park", "library")
Example:
{
"Agent_A": {
"personality": "Curious and analytical. You are a Mars colony scientist specializing in environmental systems.",
"task": "Explore the colony and report any findings about the environment.",
"default_location": "park"
}
}GET /health: Health check endpointPOST /agent/register: Register a new agentDELETE /agent/{agent_id}: Delete an agentPOST /generate: Generate agent decision using LLMPOST /env/update: Update environment stateGET /env/{agent_id}: Get environment state for a specific agent
GET /profiles: List all agent profilesGET /profiles/{agent_id}: Get a specific agent's profilePOST /profiles/{agent_id}: Update an agent's profileDELETE /profiles/{agent_id}: Delete an agent's profile
Example profile update:
curl -X POST http://localhost:3000/profiles/Agent_A \
-H "Content-Type: application/json" \
-d '{"personality": "Curious and analytical", "task": "Explore the park"}'POST /logs/export: Export all logsGET /logs/agent/{agent_id}: Get logs for a specific agentGET /logs/agents: List all agents with logs
The backend includes a vector-based memory system that allows agents to recall past experiences:
POST /memory/{agent_id}: Store a new memory for an agentPOST /memory/{agent_id}/query: Query an agent's memoriesGET /memory/{agent_id}: Get all memories for an agentGET /memory/{agent_id}/{memory_id}: Get a specific memoryDELETE /memory/{agent_id}/{memory_id}: Delete a specific memoryDELETE /memory/{agent_id}: Clear all memories for an agentGET /memory/: List all agents with memories
To enable the memory system:
# Setup the memory system
./setup_memory_system.sh
# Start the system with Docker support for vector database
docker-compose -f docker-compose.memory.yml up -dFor more details, see Memory System README.
The system maintains an environment state that includes:
- Agent positions and statuses
- Nearby agents for each agent
- Nearby objects for each agent
- Location information
This state is updated regularly from the Unity frontend and used to provide context to the LLM for making decisions.
The backend communicates with the Unity frontend through HTTP APIs:
- Unity sends environment updates to the backend
- The backend sends action commands back to Unity
- All communication uses JSON format
Check the agent_logs directory for detailed logs of agent interactions with the LLM system. Each agent has its own log file tracking:
- Prompts sent to the LLM
- Responses received
- Parsed actions
- Timestamps for each interaction
Agents can communicate with each other through the SPEAK action when they are at the same location. Messages are delivered to all agents at the same location.
Agents have a semantic memory system that allows them to:
- Remember past interactions and experiences
- Retrieve relevant memories based on their current context
- Have a continuity of experience as they navigate the simulation
A web-based dashboard is available for monitoring agent status and interactions at http://localhost:5001 when the backend is running.