Agents

Define autonomous agents with capabilities, roles, and conditional actions.

Keywords

  • agent - Define an autonomous agent
  • capabilities - List agent capabilities (optional property)
  • skills - List agent skills (optional property)
  • model - Specify AI model to use (optional property)

agent Keyword

Define autonomous agents that can perform actions based on capabilities and conditions.

Syntax

Capabilities can be unquoted (single word) or quoted (multi-word):

// Unquoted capabilities (single word)
agent AgentName {
    fetchOrder
    validateItems
    processPayment
}

// Quoted capabilities (multi-word)
agent AgentName {
    "fetch order"
    "validate items"
    "process payment"
}

// Mixed syntax (recommended)
agent AgentName {
    fetchOrder
    "validate order items"    // quotes for multi-word
    processPayment
    "send confirmation email"
}
✨ Edit in Studio

With role inheritance:

agent AgentName: RoleName {
    processOrder
    "handle complex tasks"
}
✨ Edit in Studio

Examples

Basic Agent

agent OrderProcessor {
    fetchOrder
    validateItems
    processPayment
    sendConfirmation
}
✨ Edit in Studio

Agent with Role Inheritance

role AdminRole {
    permission orders {
        create,
        read,
        update,
        delete
    }
}

agent OrderManager: AdminRole {
    listOrders
    updateOrderStatus
    cancelOrder
    notifyCustomer
}
✨ Edit in Studio

Multi-Agent System

agent InventoryManager {
    checkStockLevels
    updateInventory
    alertOnLowStock
    reorderItems
}

agent NotificationAgent {
    sendEmail
    sendSms
    logNotification
    retryOnFailure
}

agent OrderCoordinator {
    receiveOrder
    validateOrder
    "assign to InventoryManager"
    "assign to NotificationAgent"
    trackCompletion
}
✨ Edit in Studio

Agent Properties

capabilities Property

Optional property to list agent capabilities explicitly.

agent DataAnalyst {
    capabilities: [
        "data_processing",
        "statistical_analysis",
        "visualization",
        "reporting"
    ]
    
    fetchData
    analyzePatterns
    generateReports
}
✨ Edit in Studio

skills Property

Optional property to define agent skills.

agent DeveloperAgent {
    skills: [
        "python",
        "typescript",
        "sql",
        "git"
    ]
    
    writeCode
    reviewCode
    debugIssues
}
✨ Edit in Studio

model Property

Optional property to specify which AI model the agent should use.

agent CodeReviewer {
    model: "claude-3-sonnet"
    
    analyzeCodeQuality
    suggestImprovements
    checkBestPractices
}

agent DocumentWriter {
    model: "gpt-4"
    
    writeDocumentation
    generateExamples
    formatMarkdown
}
✨ Edit in Studio

Advanced Patterns

Complex Workflows

agent SmartOrderProcessor {
    receiveOrder
    
    # Validation phase
    validateOrder
    
    # Payment phase
    processPayment
    retryPaymentOnFailure
    "notify customer on payment failure"
    
    # Fulfillment phase
    prepareShipment
    updateInventory
    shipOrder
    
    # Notification phase
    sendConfirmation
    sendTrackingInfo
}
✨ Edit in Studio

Agent Hierarchies

agent SupervisorAgent {
    assignTasksToWorkers
    monitorProgress
    aggregateResults
    interveneOnIssues
}

agent WorkerAgent {
    receiveTask
    executeTask
    reportProgress
    requestHelpWhenStuck
}

agent QualityAgent {
    reviewWork
    validateOutput
    approveOrReject
    provideFeedback
}
✨ Edit in Studio

State-Aware Agents

workflow OrderFlow {
    state pending -> processing
    state processing -> completed, failed
    state failed -> retry, cancelled
}

agent OrderStateMachine {
    # Pending state actions
    acceptOrder
    validateOrder
    
    # Processing state actions
    processPayment
    updateInventory
    
    # Completion actions
    sendConfirmation
    archiveOrder
    
    # Error handling
    retryOnFailure
    notifySupport
}
✨ Edit in Studio

Best Practices

Naming Conventions

  • Use PascalCase for agent names: OrderProcessor, DataAnalyst
  • Use descriptive names that indicate purpose: EmailNotifier, InventoryManager
  • Suffix with role type when helpful: OrderAgent, PaymentAgent

Capability Design

  1. Be specific with action phrases

    • Good: validatePaymentCard or "validate payment card"
    • Avoid: validate
  2. Use camelCase for unquoted or descriptive phrases for quoted

    • Unquoted: processCustomerOrder
    • Quoted: "process customer order"
  3. Group related actions together

Agent Organization

# Group agents by domain

# Payment Domain
agent PaymentValidator { ... }
agent PaymentProcessor { ... }
agent RefundManager { ... }

# Inventory Domain
agent StockChecker { ... }
agent InventoryUpdater { ... }
agent ReorderAgent { ... }

# Notification Domain
agent EmailSender { ... }
agent SMSDispatcher { ... }
agent NotificationLogger { ... }
✨ Edit in Studio

Real-World Examples

E-Commerce System

enum OrderStatus {
    pending
    processing
    shipped
    delivered
}

role CustomerRole {
    permission orders {
        create,
        read
    }
}

agent OrderOrchestrator: CustomerRole {
    # Order reception
    receiveOrder
    validateOrderItems
    
    # Payment processing
    processPayment
    retryPaymentOnDecline
    "notify customer on failure"
    
    # Inventory management
    reserveInventory
    updateStockLevels
    
    # Fulfillment
    prepareShipment
    updateStatusToShipped
    trackDelivery
    
    # Notifications
    sendOrderConfirmation
    sendShippingNotification
    sendDeliveryNotification
}
✨ Edit in Studio

Content Management

agent ContentModerator {
    model: "claude-3-sonnet"
    capabilities: [
        "text_analysis",
        "sentiment_detection",
        "policy_compliance"
    ]
    
    receiveContent
    analyzeContent
    approveCompliantContent
    rejectPolicyViolations
    flagUncertainContent
    escalateToHuman
}
✨ Edit in Studio

Data Pipeline

agent DataIngestion {
    fetchDataFromSources
    validateSchema
    transformFormat
    handleErrors
    retryOnConnectionFailure
}

agent DataProcessor {
    cleanData
    enrichData
    validateQuality
    aggregateResults
}

agent DataPublisher {
    writeToDatabase
    createBackup
    notifySubscribers
    logCompletion
}
✨ Edit in Studio

Related Keywords

  • role - Agents can inherit from roles
  • workflow - Agents can follow workflows
  • visitor - Visitors interact with agents

Next Steps