Debugging Agents
When things go wrong, here’s how to diagnose and fix them.Local Testing
Always test locally before deploying:Debug Mode
Add debug output to stderr (doesn’t affect response):Common Errors
”Agent not found”
Cause: Wrong slug or agent doesn’t exist. Fix:“Agent not active”
Cause: Agent isn’t deployed or was stopped. Fix:“castari.json not found”
Cause: Missing configuration file. Fix: Createcastari.json in your agent root:
“npm install failed”
Cause: Dependency issues. Fix:- Run
npm installlocally first - Check
package.jsonfor errors - Ensure all packages are published to npm
”Timeout exceeded”
Cause: Agent took too long (>120s default). Fix:- Optimize slow operations
- Break complex tasks into smaller steps
- Check for infinite loops
”Tool execution failed”
Cause: Error in tool handler. Fix:“ANTHROPIC_API_KEY not set”
Cause: Missing API key. Fix: Castari injects this automatically. If you see this locally:Debugging Tool Calls
Log Tool Inputs/Outputs
Validate Tool Schemas
Ensure your tool schemas match what Claude sends:Debugging Claude Interactions
Log Messages
Check Stop Reasons
| Stop Reason | Meaning |
|---|---|
end_turn | Claude finished responding |
tool_use | Claude wants to use a tool |
max_tokens | Hit token limit |
stop_sequence | Hit a stop sequence |
Environment Issues
Check Secrets
Check Agent Status
error, redeploy:
Getting Help
If you’re stuck:- Test locally:
echo "prompt" | npm run dev - Check status:
cast agents get my-agent - Redeploy:
cast deploy