The ICP Agent Kit’s natural language processing capabilities allow you to interact with the blockchain using plain English commands. This guide covers command patterns, conversation management, and best practices.

How It Works

1

Command Understanding

Your natural language input is processed by OpenAI’s GPT-4 to understand intent and extract parameters.
2

Tool Selection

The system automatically selects the appropriate tool(s) from the 10 available LangChain tools.
3

Execution

The selected tools execute the blockchain operations with proper error handling.
4

Response

Results are formatted in natural language for easy understanding.

Command Patterns

Identity Commands

// Check current identity
'Show me my current identity';
'What is my principal?';
'Display my account information';

// Create identities
'Create a new identity called alice';
'Generate an anonymous identity for testing';
'Create identity from seed phrase: [12/24 words...]';

// Switch identities
'Switch to my trading identity';
'Use the alice identity';
'Change to anonymous';

// List identities
'Show all my identities';
'List available identities';

Token Commands

// Check balances
'What is my ICP balance?';
'Show me how much ICP I have';
'Check balance for account xyz';

// Transfer ICP
'Transfer 5 ICP to alice.icp';
'Send 0.1 ICP to [principal-id]';
'Transfer 10 ICP to [account-id] with memo: payment';

// ICRC-1 tokens
'Transfer 1000 CHAT tokens to bob';
'Send 500 tokens from canister xyz to alice';
'Check my token balance for canister abc';

Canister Commands

// Create canisters
'Create a new canister with 5 trillion cycles';
'Deploy a canister with 2T cycles';
'Make a new canister for my app';

// Deploy code
'Deploy my app.wasm to canister xyz';
'Install WASM module to canister abc';
'Upgrade canister def with new code';

// Check status
'Check status of canister xyz';
'Show me all my canisters';
'Get canister abc information';

// Manage controllers
'Add alice as controller to my canister';
'Remove bob from canister controllers';

Cycles Commands

// Check cycles
'Check cycles for canister xyz';
'How many cycles does my canister have?';
'Show cycles balance for all my canisters';

// Top up cycles
'Top up canister xyz with 2 trillion cycles';
'Add 5T cycles to my canister';
'Refill canister abc with 1T cycles';

// Conversions
'How many cycles can I get with 1 ICP?';
'Convert 5 ICP to cycles';
"What's the current ICP to cycles rate?";

Multi-Step Operations

The NLP processor can handle complex, multi-step operations:
// Example 1: Identity and balance check
const result = await agent.processNaturalLanguage(
  'Create a new identity called trading and check its balance',
);

// Example 2: Canister deployment workflow
const result = await agent.processNaturalLanguage(
  'Create a canister with 5T cycles and deploy my app.wasm to it',
);

// Example 3: Token management
const result = await agent.processNaturalLanguage(
  "Check my ICP balance, and if it's over 10 ICP, transfer 5 to alice",
);

Context-Aware Conversations

The system maintains context within a session:
// First command
await agent.processNaturalLanguage('Create an identity called alice');

// Context-aware follow-up
await agent.processNaturalLanguage("What's the principal?");
// System understands you mean alice's principal

// Another follow-up
await agent.processNaturalLanguage('Switch back to the default identity');
// System knows your previous identity

Using Specialized Agents

Different agents provide focused expertise:

General Agent

const generalAgent = agent.createAgent('general');

// Good for mixed operations
await generalAgent.chat('Check my balance and list my canisters');
await generalAgent.chat('Help me manage my tokens and cycles');

Developer Agent

const devAgent = agent.createAgent('developer');

// Optimized for canister development
await devAgent.chat('I need to deploy a new version of my app');
await devAgent.chat("What's the best practice for canister upgrades?");
await devAgent.chat('Help me debug my canister deployment');

DeFi Agent

const defiAgent = agent.createAgent('defi');

// Specialized for financial operations
await defiAgent.chat('I want to manage my token portfolio');
await defiAgent.chat('What are the fees for transferring ICP?');
await defiAgent.chat('Help me set up recurring transfers');

Advanced Patterns

Conditional Operations

// Using conditions
'If my balance is over 100 ICP, transfer 50 to savings';
'Check if canister xyz has enough cycles, if not top it up';

// Multiple conditions
'If I have more than 10 ICP and canister abc needs cycles, convert 2 ICP to cycles for it';

Batch Operations

// Multiple transfers
'Transfer 5 ICP to alice, 3 ICP to bob, and 2 ICP to charlie';

// Multiple checks
'Check balance for all my identities';
'Show status of all my canisters';

Queries and Filters

// Filtered queries
'Show me canisters with less than 1T cycles';
'List identities that have ICP balance';
'Find canisters I control';

Error Handling

Natural language errors are user-friendly:
// Invalid address
'Transfer 5 ICP to invalid-address';
// Response: "The recipient address 'invalid-address' is not valid..."

// Insufficient balance
'Transfer 1000 ICP to alice';
// Response: "Insufficient balance. You have 10 ICP but tried to transfer 1000 ICP..."

// Missing parameters
'Transfer to alice';
// Response: "Please specify the amount to transfer. For example: 'Transfer 5 ICP to alice'"

Best Practices

Conversation Examples

Example 1: Token Management Flow

User: "What's my ICP balance?"
Agent: "Your ICP balance is 25.5 ICP (Account: 60ab9a...)"

User: "I need to send some to alice for the project"
Agent: "How much ICP would you like to send to alice?"

User: "5 ICP should be enough"
Agent: "Successfully transferred 5 ICP to alice.
        Transaction ID: 12345
        New balance: 20.5 ICP"

Example 2: Canister Development Flow

User: "I need to deploy my new app"
Agent: "I'll help you deploy your app. First, do you have an existing canister or should I create a new one?"

User: "Create a new one"
Agent: "How many cycles should I allocate? (Recommended: 5T for new apps)"

User: "Use 5T"
Agent: "Created canister: rrkah-fqaaa-aaaaa-aaaaq-cai with 5T cycles.
        Ready to deploy your WASM module. What's the path to your WASM file?"

Debugging Natural Language

Enable verbose mode to see tool selection:
const agent = new ICPAgent({
  network: 'mainnet',
  openai: { apiKey: 'your-key' },
  debug: true, // Enable debug logging
});

// You'll see:
// - Which tools are selected
// - Parameters extracted
// - Execution steps

Language Tips

Common Phrases Reference

IntentExample Phrases
Check Balance”What’s my balance?”, “Show ICP”, “How much do I have?”
Transfer”Send X to Y”, “Transfer X ICP to Y”, “Pay Y with X ICP”
Create”Make a new…”, “Create a…”, “Generate a…”
List”Show all…”, “List my…”, “What are my…”
Help”How do I…”, “What’s the best way to…”, “Help me…”

Next Steps

Ready to build something more complex? Check out: