Analyze Pi Agent's structured logs (.log/*.jsonl), providing multi-dimensional statistics and issue diagnosis.
Log Format
Logs are in JSONL format, one JSON object per line:
{
"schema": "2.0.0",
"timestamp": "2026-05-07T00:46:30.942Z",
"level": "info|warn|error",
"tag": "auto-extract|checkpoint|vector|...",
"message": "日志消息",
"context": {
"role": "default|bw|psm|jly|zero",
"sessionId": "uuid",
"cwd": "/path",
"pid": 12345
},
"meta": {
"model": "provider/model-name",
"duration_ms": 1234,
...
},
"traceId": "tr-xxx"
}
Quick Analysis
Basic Statistics
Run the built-in analysis script:
python3 ~/.pi/agent/skills/pi-log-analyzer/scripts/analyze.py [目录路径] [天数]
Parameters:
目录路径: log directory, default.log/天数: analyze the last N days, default 3
Example:
# 分析最近 3 天
python3 ~/.pi/agent/skills/pi-log-analyzer/scripts/analyze.py
# 分析最近 7 天
python3 ~/.pi/agent/skills/pi-log-analyzer/scripts/analyze.py .log/ 7
# 分析指定目录
python3 ~/.pi/agent/skills/pi-log-analyzer/scripts/analyze.py /path/to/logs 5
Output Content
The script generates the following analyses:
- Overview Statistics: number of log entries, number of sessions, time span
- Level Distribution: count and proportion of info/warn/error
- Module Activity: frequency of occurrence of each tag
- Role Activity: log volume of each role
- Model Usage: models called and their counts
- Time Distribution: hourly activity heatmap
- Warning Details: specific content and patterns of warn/error
Manual Analysis
For more detailed analysis, you can use Python to read the logs:
import json
from collections import Counter
with open('.log/2026-05-09.jsonl') as f:
for line in f:
d = json.loads(line)
# 访问字段:d['level'], d['tag'], d['meta']['model'], etc.
Common Tag Meanings
| Tag | Meaning |
|---|---|
auto-extract |
Automatic memory extraction |
checkpoint |
Scheduled save point |
daily-memory |
Daily memory write |
vector |
Vector index operation |
pending |
Pending item |
repair |
Memory repair |
embedding |
Embedding generation |
knowledge |
Knowledge base operation |
Common Issue Diagnosis
auto-extract parse failed
Cause: The memory extraction result returned by the LLM does not match the expected format
Typical Patterns:
- Returning reasoning process instead of JSON
- JSON is truncated
- Contains
<think>tags
Recommendations:
- Check whether the model supports structured output
- Prefer DeepSeek V4 Flash (lowest failure rate)
Model Call Failure
Check the meta.model field to confirm the model used, and compare with the models.json configuration.
Use Cases
- Daily Inspection: quickly check whether recent activity is normal
- Troubleshooting: locate the root cause of warnings/errors
- Performance Analysis: identify high-load periods and modules
- Model Evaluation: count usage and success rate of each model
- Capacity Planning: estimate resources based on session count and log volume