Skip to main content

Quick Reference

Clear instructions = better results. Be specific about sources, data fields, and output format.

✅ Good: Specific & Structured

const result = await session.runTask(`
    Find iPhone 15 Pro prices on:
    - Amazon.com
    - BestBuy.com
    - Apple.com

    For each retailer, provide:
    - Base price (128GB model)
    - Availability (in stock / out of stock)
    - Product URL

    Return as JSON array:
    [{"retailer": "Amazon", "price": 999.99, "available": true, "url": "..."}]
`);

❌ Bad: Vague & Unstructured

const result = await session.runTask('Check iPhone prices');

Always Request JSON

Request structured output for easy parsing.
const result = await session.runTask(`
    Extract product info and return as JSON:
    {"name": "...", "price": 99.99, "in_stock": true, "url": "..."}
    
    Return ONLY valid JSON, no markdown.
`);

Break Down Complex Tasks

Split complex workflows into smaller steps.
const session = await client.createSession('agi-0');
try {
    // Step 1: Get specs
    const specs = await session.runTask('Find iPhone 15 Pro specifications. Return JSON.');
    
    // Step 2: Find prices
    const prices = await session.runTask('Find iPhone 15 Pro prices on Amazon, Best Buy, Apple. Return JSON array.');
} finally {
    await session.delete();
}

Handle Edge Cases

Tell agents how to handle missing data.
const result = await session.runTask(`
    Find product prices on Amazon.
    
    If out of stock: Set "available": false
    If price not found: Set "price": null
    If product doesn't exist: Return {"error": "Product not found"}
    
    Always return valid JSON.
`);

Key Principles

Be Specific

Provide exact sources, formats, and data fields

Request JSON

Always request structured output for easy parsing

Break It Down

Split complex workflows into smaller steps

Handle Edge Cases

Tell agents how to handle missing data

Next Steps