This feature enables debugging of GenAI API calls by logging all parameters and responses to JSON files. When debug mode is enabled, each API call creates a separate JSON log file in the state directory with detailed information about the request and response. Debug mode also enables developer-facing “🐛 DEBUG” messages in the conversation flow.
Debug mode can be enabled in two ways:
export PROMPTPIPE_DEBUG=trueAccepted values for PROMPTPIPE_DEBUG:
true,1,yes,on(case insensitive) - Enable debug modefalse,0,no,off(case insensitive) - Disable debug mode- Any other value defaults to
falsewith a warning
./promptpipe --debugThe command line flag takes precedence over the environment variable.
When debug mode is enabled, API call logs are stored in:
{STATE_DIR}/debug/
Each log file is named using the format:
YYYY-MM-DD.HH-MM-SS.{16-character-random-hex}.json
Example filename: 2025-07-22.14-30-45.a1b2c3d4e5f6789a.json
Each debug log file contains a JSON object with the following fields:
{
"timestamp": "2025-07-22T14:30:45Z",
"method": "GeneratePromptWithContext",
"model": "gpt-4o-mini",
"params": {
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant"
},
{
"role": "user",
"content": "Hello, how are you?"
}
],
"temperature": 0.7,
"max_completion_tokens": 1000
},
"response": {
"choices": [
{
"message": {
"content": "I'm doing well, thank you for asking!"
}
}
]
},
"error": null
}- timestamp: UTC timestamp when the API call was made (RFC3339 format)
- method: The GenAI client method that was called
GeneratePromptWithContext- Simple system/user prompt generationGenerateWithMessages- Multi-message conversation generationGenerateWithTools- Generation with tool/function calling capabilityGenerateThinkingWithMessages- Structured JSON output separating internal thinking and user-facing contentGenerateThinkingWithTools- Structured thinking + content while enabling tool/function calls
- model: The OpenAI model used for the generation
- params: Complete parameters sent to the OpenAI API
- response: Complete response received from the OpenAI API
- error: Error message if the API call failed, otherwise
null
When debug mode is active, the system surfaces the model's internal reasoning (“thinking”) for the Intake and Feedback modules (and the Coordinator module if manually wired). This is accomplished via GenAI methods that instruct the model to emit JSON of the form:
{"thinking": "brief reasoning", "content": "final user reply"}Key properties:
- Thinking is always requested for those tool-driven modules (no separate toggle), to keep prompt schemas consistent.
- Prompt generation uses structured thinking internally but does not emit separate debug messages on its own.
- The thinking field is only delivered to developers via separate debug messages (prefixed with 🐛) and never sent to end users directly.
- Tool-enabled generations embed the same JSON content while still returning native tool call objects.
- If JSON parsing fails, the raw content is treated as the user reply and thinking is left empty (non-fatal fallback).
Displayed debug example (WhatsApp/SMS):
🐛 DEBUG: Coordinator thinking (round 2): Deciding to call save_user_profile because motivation missing; will gather motivation next.
Debug mode is useful for:
- Troubleshooting: Inspect exact parameters sent to OpenAI API
- Cost Analysis: Track token usage and API calls
- Performance Analysis: Understand response times and patterns
- Development: Debug prompt engineering and model behavior
- Auditing: Keep records of all AI interactions
- Complete conversation history
- System prompts (which may contain sensitive instructions)
- User inputs (which may contain personal information)
- AI responses
Recommendations:
- Only enable debug mode in development/testing environments
- Regularly clean up debug log files
- Ensure proper file permissions on the state directory
- Consider data retention policies for debug logs
# Method 1: Environment variable
export PROMPTPIPE_DEBUG=true
./promptpipe
# Method 2: Command line flag
./promptpipe --debug
# Method 3: Both (flag takes precedence)
export PROMPTPIPE_DEBUG=false
./promptpipe --debug # Debug mode will be enabledcurl -X POST http://localhost:8080/send \
-H "Content-Type: application/json" \
-d '{
"to": "+1234567890",
"type": "genai",
"system_prompt": "You are a helpful assistant",
"user_prompt": "Hello, how are you?"
}'After the request, check for debug files (only written when GenAI is enabled):
ls -la /var/lib/promptpipe/debug/cat /var/lib/promptpipe/debug/2025-07-22.14-30-45.a1b2c3d4e5f6789a.json | jq .To disable debug mode:
# Method 1: Unset environment variable
unset PROMPTPIPE_DEBUG
# Method 2: Set to false
export PROMPTPIPE_DEBUG=false
# Method 3: Remove --debug flag
./promptpipe # without --debug flag- Debug logging only occurs when both debug mode is enabled AND a state directory is configured
- Random hex strings prevent filename collisions when multiple API calls happen simultaneously
- Debug directory is created automatically with permissions 0755
- Failed debug logging operations are logged as warnings but don't affect API functionality
- Debug logging has minimal performance impact on API calls
- Structured thinking is appended as an extra system instruction; maintaining it permanently avoids prompt divergence, so there is intentionally no runtime toggle to disable it.