- Added UserSimulator service for automated interactions. - Added Docker simulation script and documentation. - Supported --knowledge-source flag defaulting to ~/.agents/kb.md.
3.3 KiB
Running User Simulation in Docker with External Knowledge Source
This guide explains how to run the User Simulator in a Docker environment while mounting an external knowledge base. This setup allows the simulator to "learn" from its interactions and persist that knowledge back to your host machine.
We have provided an automated script that handles the entire setup, execution, and cleanup process.
Prerequisites
- Docker installed and running.
- Gemini API Key (standard
AIza...key). - Local checkout of the
gemini-clirepository.
Execution via Automation Script (Recommended)
The easiest and most reliable way to run the simulation is using the provided bash script. This script automatically:
- Creates a uniquely timestamped workspace folder on your host.
- Generates a global
settings.jsonfile to natively bypass the CLI's interactive Folder Trust and Authentication dialogs. - Builds the sandbox image from your current branch.
- Mounts the workspace and runs the container with
--initto gracefully handle termination (e.g.,Ctrl+C).
Running the Script
Ensure your API key is exported:
export GEMINI_API_KEY="AIzaSy..."
Run the script from the root of the repository:
# Uses the default prompt ("make a snake game in python")
./scripts/run_simulator_docker.sh
# Or, provide a custom prompt:
./scripts/run_simulator_docker.sh "create a simple react counter component"
Manual Execution Breakdown
If you need to run the simulation manually, here is exactly what the automated script does under the hood:
1. Prepare Workspace & Knowledge Source
WORKSPACE_DIR="/tmp/gemini_docker_workspace"
mkdir -p "$WORKSPACE_DIR"
touch "$WORKSPACE_DIR/knowledge.md"
chmod -R 777 "$WORKSPACE_DIR"
2. Bypass Interactive Startup Dialogs
To prevent the simulator from getting stuck on the initial Auth or Folder Trust
screens, generate a global settings.json file.
mkdir -p "$WORKSPACE_DIR/.gemini"
echo '{
"security": {
"auth": { "selectedType": "gemini-api-key" },
"folderTrust": { "enabled": false }
}
}' > "$WORKSPACE_DIR/.gemini/settings.json"
chmod 777 "$WORKSPACE_DIR/.gemini/settings.json"
3. Build the Image
GEMINI_SANDBOX=docker npm run build:sandbox -- -i gemini-cli-simulator:latest
4. Run the Container
Notice the --init flag (for Ctrl+C support) and the explicit mount mapping
the settings.json file into /home/node/.gemini/ inside the container.
docker run -it --rm --init \
-v "$WORKSPACE_DIR:/workspace" \
-v "$WORKSPACE_DIR/.gemini/settings.json:/home/node/.gemini/settings.json" \
-w /workspace \
-e GEMINI_API_KEY="$GEMINI_API_KEY" \
-e GEMINI_DEBUG_LOG_FILE="/workspace/debug.log" \
gemini-cli-simulator:latest \
gemini --prompt-interactive "make a snake game in python" \
--approval-mode plan \
--simulate-user \
--knowledge-source "/workspace/knowledge.md"
Verification
Once the simulation completes, verify the results in your workspace folder:
- Generated Code: Check for project files (e.g.,
snake.py). - Persistent Knowledge: Check
knowledge.md. You should see new rules dynamically appended by the simulator. - Logs:
debug.log: Detailed internal LLM decision logic.interactions_<timestamp>.txt: Raw screen scrape frames seen by the simulator's "eyes".