Learn how to build AI agents that interact with UniSat services.
The simplest agent type with instructions and tools:
import { Agent } from "@unisat-ai/sdk";
const agent = new Agent({
name: "my-agent",
instruction: "You are a helpful assistant for Bitcoin blockchain queries.",
tools: [
{
name: "get_balance",
description: "Get Bitcoin address balance",
execute: async (args) => {
// Implementation
}
}
]
});Execute sub-agents in a fixed sequence:
import { SequentialAgent } from "@unisat-ai/sdk";
const agent = new SequentialAgent({
name: "trading-flow",
instruction: "Execute trading steps in sequence",
subAgents: [marketAnalyzer, riskChecker, orderExecutor]
});Execute sub-agents concurrently:
import { ParallelAgent } from "@unisat-ai/sdk";
const agent = new ParallelAgent({
name: "multi-token-tracker",
instruction: "Track multiple tokens simultaneously",
subAgents: [btcTracker, ethTracker, solTracker]
});my-agent/
├── agent.ts # Entry point
├── project.yaml # Metadata
├── prompts/ # System prompts
├── tools/ # Custom tools
├── sub_agents/ # Sub-agents
└── utils/ # Helpers
- Validate Input: Always validate user input (addresses, txids, etc.)
- Error Handling: Provide helpful error messages
- Rate Limiting: Respect API rate limits
- Logging: Use structured logging for debugging
See the examples directory for complete working examples.