// Step 1: Create and configure identityawait agent.processNaturalLanguage( "Create a new identity from seed phrase");// Step 2: Check the new balanceconst balance = await agent.processNaturalLanguage( "What's the balance of the identity I just created?");// Step 3: Conditional actionawait agent.processNaturalLanguage( "If the balance is zero, switch back to my main identity");
const devAgent = agent.createAgent('developer');// Step 1: Plan deploymentconst plan = await devAgent.chat( "I want to deploy a hello world canister. What are the steps?");console.log(plan);// Step 2: Create canisterconst canister = await devAgent.chat( "Create a new canister with 5T cycles for development");// Step 3: Deploy codeconst deployment = await devAgent.chat( "Deploy my hello_world.wasm to the canister we just created");// Step 4: Verifyconst status = await devAgent.chat( "Check if the deployment was successful and show the canister status");
const devAgent = agent.createAgent('developer');// Example 1: Debugging deployment issuesawait devAgent.chat("My canister deployment is failing with 'insufficient cycles'");// Response: "The error indicates your canister needs more cycles. Current deployments // typically require at least 1T cycles. Let me check your canister's balance..."// Example 2: Best practices consultationawait devAgent.chat("What's the recommended canister architecture for a DEX?");// Response: "For a DEX, I recommend a multi-canister architecture:// 1. Trading Engine Canister - handles order matching// 2. Token Registry Canister - manages supported tokens// 3. User Account Canister - tracks balances..."// Example 3: Upgrade guidanceawait devAgent.chat("How do I safely upgrade my production canister?");// Response: "For safe production upgrades:// 1. First, take a snapshot of current state// 2. Test the upgrade on a staging canister// 3. Use stable memory for critical data..."
const defiAgent = agent.createAgent('defi');// Example 1: Portfolio managementconst portfolio = await defiAgent.chat( "Show me a summary of all my token holdings");// Example 2: Batch transfersawait defiAgent.chat( "I need to send payments to my team: 10 ICP to Alice, 15 ICP to Bob, 5 ICP to Charlie");// Example 3: Token analysisawait defiAgent.chat( "What's the most efficient way to transfer ICRC-1 tokens with minimal fees?");
// Set up monitoring for multiple canistersconst monitoringScript = `Monitor all my canisters and:1. Alert me if any canister has less than 1T cycles2. Automatically top up canisters that fall below 500B cycles3. Generate a daily report of cycles consumption`;const result = await agent.processNaturalLanguage(monitoringScript);// The agent will:// - List all controlled canisters// - Check cycles balances// - Set up monitoring with the cycles plugin// - Configure auto top-up rules
const defiAgent = agent.createAgent('defi');// Complex distribution logicconst distribution = await defiAgent.chat(`I need to distribute 1000 REWARD tokens to these addresses based on their contribution:- Alice (40%): ${aliceAccount}- Bob (35%): ${bobAccount}- Charlie (25%): ${charlieAccount}Calculate the exact amounts and execute the transfers.`);// The agent will:// - Calculate token amounts (400, 350, 250)// - Validate all recipient addresses// - Execute transfers in sequence// - Provide transaction summaries
const devAgent = agent.createAgent('developer');// Full deployment pipelineconst pipeline = await devAgent.chat(`Execute my deployment pipeline:1. Create a staging canister2. Deploy the latest build3. Run smoke tests (call the 'health' method)4. If tests pass, upgrade the production canister5. Verify the upgrade was successful`);// The agent orchestrates the entire pipeline with error handling
try { await agent.processNaturalLanguage( "Transfer 1000 ICP to an invalid address xyz" );} catch (error) { console.log("Error caught:", error.message); // Ask for clarification const clarification = await agent.processNaturalLanguage( "The transfer failed. Can you help me validate the recipient address?" );}
// The agent validates before executingconst validation = await agent.processNaturalLanguage( "I want to transfer all my ICP to alice. Is this safe?");// Response: "Transferring all your ICP would leave your account empty. // You need to keep some ICP for transaction fees. // Would you like to keep 0.1 ICP for fees?"
// Start a conversationconst agent1 = agent.createAgent('general');// First interactionawait agent1.chat("I'm new to ICP. Where should I start?");// Response: "Welcome to ICP! I recommend starting with:// 1. Understanding identities and principals// 2. Learning about ICP tokens and cycles..."// Follow-up with contextawait agent1.chat("Tell me more about the first point");// Response: "Identities in ICP are like your blockchain account...// [Detailed explanation about identities]"// Another follow-upawait agent1.chat("Can you show me how to create one?");// Response: "Of course! Let me create an example identity for you...// [Creates identity and shows the process]"
const teacher = agent.createAgent('general');// Interactive learningawait teacher.chat("Teach me about cycles by doing");// Response: "Let's learn about cycles hands-on! First, let me check // a canister's cycles balance to show you..."// [Agent executes get_cycles_balance tool]// "This canister has 5.2T cycles. Cycles are like fuel for computation.// Now, let's see how much 1 ICP converts to..."// [Agent executes pricing check]// "Currently, 1 ICP = 1.3T cycles. Would you like to try topping up// a canister to see how it works?"
// Complex conditional operationsconst smartTransfer = await agent.processNaturalLanguage(`Check my ICP balance and:- If it's over 100 ICP, transfer 20 ICP to my savings- If it's between 50-100 ICP, transfer 10 ICP- If it's under 50 ICP, just tell me the balance`);
// Batch with safety checksconst batchOps = await agent.processNaturalLanguage(`I need to:1. Create 3 new canisters for my microservices2. Allocate 10T cycles to each3. Add alice as controller to all of themPlease confirm the total cycles cost before proceeding.`);// Response: "This will create 3 canisters with 30T cycles total // (approximately 23 ICP). Proceed? (yes/no)"
// Set up intelligent monitoringconst monitoring = await agent.processNaturalLanguage(`Set up monitoring for my main canister:- Check cycles every hour- Alert me on Slack if below 2T cycles- Auto top-up if below 1T cycles- Generate weekly usage reports`);
// Cross-plugin workflowconst workflow = await agent.processNaturalLanguage(`For my new project:1. Create a dedicated identity2. Transfer 50 ICP to it3. Create a canister with 20T cycles4. Deploy my app.wasm5. Set up cycles monitoring`);// The agent coordinates across:// - Identity plugin (create identity)// - Token plugin (transfer ICP)// - Canister plugin (create and deploy)// - Cycles plugin (monitoring)
const setupScript = `Set up my new DeFi application:1. Create identity 'defi-admin'2. Create 3 canisters: 'token', 'exchange', 'governance'3. Allocate 10T cycles to each4. Deploy the respective WASM modules5. Create initial token supply of 1M tokens6. Set up monitoring for all canisters`;const setup = await agent.processNaturalLanguage(setupScript);
// Always validate before major operationsconst secureTransfer = await agent.processNaturalLanguage( "Before I transfer 100 ICP to this address, can you verify it's valid?");// Use memos for trackingconst trackedTransfer = await agent.processNaturalLanguage( "Transfer 5 ICP to alice with memo: 'Invoice #12345'");// Regular security checksconst audit = await agent.processNaturalLanguage( "List all identities and their permissions");
// Batch operations for efficiencyconst efficientDeploy = await agent.processNaturalLanguage( "Deploy these 5 WASM modules to their respective canisters in parallel");// Optimize cycles usageconst optimization = await agent.processNaturalLanguage( "Analyze my canisters' cycles consumption and suggest optimizations");
A complete AI-powered trading bot that demonstrates:
Real-time market data integration
AI analysis using specialized DeFi agents
On-chain trade recording and verification
Natural language trading commands
// Example usage from the trading botconst defiAgent = agent.createAgent('defi');// AI-powered market analysisconst analysis = await defiAgent.chat( "Analyze BTC/USDT for trading opportunities with current market conditions");// Natural language tradingconst trade = await agent.processNaturalLanguage( "Execute BTC trade based on AI analysis with 2% risk limit");// On-chain verificationconst verification = await agent.processNaturalLanguage( "Store trading analysis data on persistent storage canister");
// Example from the DAO voting systemconst governanceAgent = agent.createAgent('governance');// AI proposal analysisconst recommendation = await governanceAgent.chat( "Analyze governance proposal PROP-2024-007 for community fund allocation");// Automated voting with AI reasoningconst vote = await agent.processNaturalLanguage( "Cast YES vote on proposal PROP-2024-007 based on AI analysis");// Governance metricsconst metrics = await agent.processNaturalLanguage( "Show current DAO voting statistics and participation rates");
Try the Sample Applications: Visit /sample-applications/ in the repository to run these examples locally and see the natural language interface in action with real blockchain operations.