Debugging
Troubleshooting guide for common Agent.md errors and issues.
Common Errors
1. Validation Errors
Error:
ValidationError: 1 validation error for AgentConfig
model.provider
Input should be 'google', 'openai', 'anthropic', 'ollama', or 'local'
Cause: Invalid provider name in frontmatter.
Fix:
Error:
ValidationError: 1 validation error for AgentConfig
triggers.0.cron
Invalid cron expression: '* * * *'
Cause: Malformed cron expression (missing field).
Fix:
# Wrong - only 4 fields
triggers:
- type: schedule
cron: "* * * *" # ❌
# Correct - 5 fields (minute hour day month weekday)
triggers:
- type: schedule
cron: "0 9 * * *" # ✓ Every day at 9 AM
Cron format reminder:
┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of month (1 - 31)
│ │ │ ┌───────────── month (1 - 12)
│ │ │ │ ┌───────────── day of week (0 - 6, Sunday = 0)
│ │ │ │ │
* * * * *
Error:
ValidationError: 1 validation error for AgentConfig
paths
Path '/workspace/../etc/passwd' is outside allowed workspace
Cause: Path traversal attempt or absolute path outside workspace.
Fix:
# Wrong
paths:
- /etc/passwd # ❌ Outside workspace
# Correct
paths:
- /workspace/data/ # ✓ Inside workspace
2. Provider Not Installed
Error:
ImportError: Provider 'openai' requires langchain-openai package.
Install with: pip install langchain-openai
Cause: Provider package not installed.
Fix:
# Install specific provider
pip install langchain-openai
# Or install with extras
uv pip install -e ".[openai]"
# Install all providers
uv pip install -e ".[all]"
Check installed providers:
# List installed packages
pip list | grep langchain
# Should see:
# langchain-openai 0.x.x
# langchain-anthropic 0.x.x
# langchain-google-genai 0.x.x
Error:
Cause: Missing or invalid API key in environment.
Fix:
# Check if API key is set
echo $OPENAI_API_KEY
# If empty, add to .env
echo "OPENAI_API_KEY=sk-proj-your-key-here" >> .env
# Reload environment
source .env # bash
# or
set -a; source .env; set +a # More reliable
Verify API key format:
- OpenAI: sk-proj-... (newer) or sk-... (legacy)
- Anthropic: sk-ant-...
- Google: AI... (39 characters)
3. Tool Not Found
Error:
Cause: Built-in tool name typo or custom tool not loaded.
Fix:
# Wrong
tools:
- name: read_file # ❌ Wrong name
# Correct (built-in tools)
tools:
- name: file_read # ✓
- name: file_write # ✓
- name: http_request # ✓
Available built-in tools:
- file_read - Read files from allowed paths
- file_write - Write files to allowed paths
- file_edit - Edit files with targeted text replacement
- file_glob - Find files matching a glob pattern
- http_request - Make HTTP requests
Error:
Cause: Custom tool file not in tools/ directory or not registered.
Fix:
# Check tools directory
ls -la /Users/zfab/repos/agentmd/tools/
# Custom tool must be:
# 1. In tools/ directory
# 2. Named <tool_name>.py
# 3. Define a function decorated with @tool
Example custom tool (tools/my_custom_tool.py):
from langchain_core.tools import tool
@tool
def my_custom_tool(input: str) -> str:
"""Description of what the tool does."""
return f"Processed: {input}"
4. MCP Connection Failed
Error:
MCPConnectionError: Failed to start MCP server 'filesystem'
Command: npx -y @modelcontextprotocol/server-filesystem
Error: ENOENT: no such file or directory
Cause: npx not installed or MCP server package not found.
Fix:
# Check if npx is installed
which npx
# If not found, install Node.js
brew install node # macOS
# or
apt install nodejs npm # Linux
# Verify
npx --version
Test MCP server manually:
# Try running MCP server directly
npx -y @modelcontextprotocol/server-filesystem /workspace
# Should output JSON on stdout
# Press Ctrl+C to stop
Error:
Cause: MCP server crashed or invalid arguments.
Fix:
# Check server arguments
mcp:
servers:
filesystem:
command: "npx"
args:
- "-y"
- "@modelcontextprotocol/server-filesystem"
- "/workspace/data" # Must be valid directory
Debug MCP server:
# Run server manually with verbose output
MCP_DEBUG=1 npx -y @modelcontextprotocol/server-filesystem /workspace/data
5. Path Permissions
Error:
Cause: File not in allowed paths.
Fix:
Or check file actually exists:
Error:
Cause: Agent trying to write to directory not in paths.
Fix:
# Wrong
paths:
- /output/ # Can only access /output/
# Agent tries to write to /workspace/ → Error
# Correct
paths:
- /output/
- /workspace/results/ # Add if needed
Best practice: Only include the paths the agent actually needs.
6. Timeouts
Error:
Cause: Agent taking too long, default timeout reached.
Fix:
Or investigate why agent is slow:
# Check logs for what it was doing
agentmd logs my-agent --verbose
# Look for:
# - Infinite loops (max_iterations reached)
# - Slow tool calls (http_request to slow API)
# - Large file operations
Error:
Cause: HTTP request tool timeout.
Fix:
7. Model Errors
Error:
Cause: Prompt too long for model's context window.
Fix:
# Use model with larger context
model:
provider: openai
name: gpt-4-turbo # 128K context vs gpt-3.5-turbo 4K
Or reduce prompt length: - Shorten system prompt - Reduce conversation history - Use smaller tool descriptions
Error:
Cause: Too many requests to LLM provider.
Fix:
# Check schedule frequency
# If cron: "* * * * *" (every minute) → reduce
# Or add delay between runs
How to Read Logs
Basic Logs
# List all executions for an agent
agentmd logs my-agent
# Output:
# Execution ID: abc123 | Started: 2026-03-11 09:00:00 | Status: success
# Execution ID: def456 | Started: 2026-03-11 09:15:00 | Status: failed
Verbose Logs
# Show full details
agentmd logs my-agent --verbose
# Output:
# Execution: abc123
# Agent: my-agent
# Started: 2026-03-11 09:00:00
# Completed: 2026-03-11 09:01:23
# Status: success
# Input tokens: 1,234
# Output tokens: 567
# Total tokens: 1,801
#
# Messages:
# [AI] Analyzing input file...
# [TOOL] file_read: /workspace/data/input.txt
# [AI] Processing complete. Writing output...
# [TOOL] file_write: /output/result.txt
# [AI] Task completed successfully.
Filter by Status
# Only show failed executions
agentmd logs my-agent --status failed
# Only show successful executions
agentmd logs my-agent --status success
Filter by Date
# Show logs from last 24 hours
agentmd logs my-agent --since "24 hours ago"
# Show logs from specific date
agentmd logs my-agent --since "2026-03-10"
Export Logs
# Export to JSON
agentmd logs my-agent --format json > logs.json
# Export to CSV
agentmd logs my-agent --format csv > logs.csv
Verbosity Levels
Level 0: Silent
Use for: Cron jobs, background tasks
Level 1: Normal (Default)
Output:
Level 2: Verbose
Output:
Starting agent: my-agent
[AI] Analyzing data...
[TOOL CALL] file_read
Path: /workspace/data/input.txt
Result: 1,234 bytes read
[AI] Writing report...
[TOOL CALL] file_write
Path: /output/report.txt
Result: 567 bytes written
Execution complete.
Token usage: 1,801 tokens ($0.05)
Level 3: Debug
Output:
[DEBUG] Loading agent from: /workspace/my-agent.md
[DEBUG] Parsed config: AgentConfig(name='my-agent', ...)
[DEBUG] Creating chat model: provider=openai, name=gpt-4
[DEBUG] Building ReAct graph...
[DEBUG] Starting execution...
Starting agent: my-agent
[DEBUG] State: messages=[SystemMessage(...)]
[AI] Analyzing data...
[DEBUG] Tool call: file_read(path="/workspace/data/input.txt")
[TOOL CALL] file_read
Path: /workspace/data/input.txt
Result: 1,234 bytes read
[DEBUG] State: messages=[SystemMessage(...), HumanMessage(...), AIMessage(...)]
...
Use for: Debugging validation errors, provider issues, graph execution
Debugging Workflow
-
Validate syntax:
-
Check provider installed:
-
Test with dry run:
-
Run with verbose output:
-
Check logs if failed:
-
Enable debug mode:
Common Issues & Quick Fixes
| Issue | Quick Fix |
|---|---|
| Validation error | agentmd validate <file> |
| Provider not found | pip install langchain-<provider> |
| API key error | Check .env file, echo $OPENAI_API_KEY |
| Tool not found | Check tool name in tools: list |
| MCP error | Test server manually: npx -y <mcp-package> <args> |
| Path permission | Add path to paths |
| Timeout | Increase settings.timeout |
| Rate limit | Reduce schedule frequency |
| Context too long | Use model with larger context or shorten prompt |
| Import error | uv sync to reinstall dependencies |
Getting Help
-
Check documentation:
-
Validate config:
-
Enable verbose logging:
-
Check database:
-
Test components individually: