Skip to main content

Building Custom Agents

Learn how to build agents from scratch using the Claude Agent SDK.

Prerequisites

  • Node.js 18+
  • Castari CLI installed (npm install -g @castari/cli)
  • Basic TypeScript knowledge

Agent Architecture

A Castari agent is a Node.js program that:
  1. Reads a prompt from stdin
  2. Processes with Claude and executes tools
  3. Writes response to stdout

Creating an Agent from Scratch

1. Initialize the Project

2. Create castari.json

3. Create package.json Scripts

4. Write the Agent

5. Create CLAUDE.md

6. Test Locally

7. Deploy

Adding Custom Tools

Tool Schema

Tools are defined with JSON Schema:

Tool Handler

External API Integration

Don’t forget to set the secret:

Best Practices

Error Handling

Always handle tool errors gracefully:

Timeout Handling

For long-running operations:

Logging

Write debug info to stderr (doesn’t affect response):

See Also

Templates

Start with pre-built agents

MCP Integration

Model Context Protocol tools

Debugging

Troubleshooting tips