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

agent AgentName {
    capability_verb action_phrase
    capability_verb action_phrase when condition
    capability_verb action_phrase if condition
}
✨ Edit in Studio

Or with role inheritance:

agent AgentName: RoleName {
    capability_verb action_phrase
}
✨ Edit in Studio

Capability Verbs

Agents use modal verbs to express different levels of capability:

VerbMeaningUsage
canAgent is able to performStandard capability
mustAgent is required to performMandatory action
shouldAgent ought to performRecommended action
mayAgent is permitted to performOptional permission
willAgent intends to performFuture commitment
shallAgent formally will performFormal requirement
cannotAgent is not able to performExplicit prohibition

See Capability Verbs for detailed documentation.

Conditional Clauses

ClauseMeaningExample
when <condition>Temporal/state conditionwhen order_exists
if <condition>Logical conditionif payment_valid
unless <condition>Negative conditionunless cancelled

Examples

Basic Agent

agent OrderProcessor {
    can fetch order
    can validate items
    can process payment
    can send confirmation
}
✨ Edit in Studio

Agent with Conditions

agent PaymentProcessor {
    can fetch payment_info when user_authenticated
    can validate card if card_provided
    can charge amount if amount_valid
    can send receipt
    cannot refund when order_shipped
}
✨ Edit in Studio

Agent with Role Inheritance

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

agent OrderManager: AdminRole {
    can list all orders
    can update order status
    can cancel order if not_shipped
    must notify customer when status_changed
}
✨ Edit in Studio

Multi-Agent System

agent InventoryManager {
    can check stock levels
    can update inventory when sale_made
    must alert when low_stock
    can reorder items if below_threshold
}

agent NotificationAgent {
    can send email
    can send sms if urgent
    can log notification
    must retry when failed
}

agent OrderCoordinator {
    can receive order
    must validate order
    can assign to InventoryManager
    can assign to NotificationAgent
    must track completion
}
✨ Edit in Studio

Agent Properties

capabilities Property

Optional property to list agent capabilities explicitly.

agent DataAnalyst {
    capabilities: [
        "data_processing",
        "statistical_analysis",
        "visualization",
        "reporting"
    ]
    
    can fetch data when requested
    can analyze patterns
    can generate reports
}
✨ Edit in Studio

skills Property

Optional property to define agent skills.

agent DeveloperAgent {
    skills: [
        "python",
        "typescript",
        "sql",
        "git"
    ]
    
    can write code
    can review code
    can debug issues
}
✨ Edit in Studio

model Property

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

agent CodeReviewer {
    model: "claude-3-sonnet"
    
    can analyze code quality
    can suggest improvements
    can check best practices
}

agent DocumentWriter {
    model: "gpt-4"
    
    can write documentation
    can generate examples
    can format markdown
}
✨ Edit in Studio

Advanced Patterns

Conditional Workflows

agent SmartOrderProcessor {
    can receive order
    
    # Validation phase
    must validate order
    cannot proceed if invalid
    
    # Payment phase
    can process payment when validated
    must retry payment if declined
    should notify customer when payment_failed
    
    # Fulfillment phase
    can prepare shipment when payment_complete
    must update inventory
    can ship order when ready
    
    # Notification phase
    must send confirmation
    should send tracking when shipped
    may send promotional_email
}
✨ Edit in Studio

Agent Hierarchies

agent SupervisorAgent {
    can assign tasks to workers
    can monitor progress
    must aggregate results
    can intervene when issues_detected
}

agent WorkerAgent {
    can receive task
    must execute task
    can report progress
    should request help when stuck
}

agent QualityAgent {
    can review work
    must validate output
    can approve or reject
    should provide feedback
}
✨ Edit in Studio

State-Aware Agents

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

agent OrderStateMachine {
    # Pending state actions
    can accept order when pending
    must validate order when pending
    
    # Processing state actions
    can process payment when processing
    must update inventory when processing
    
    # Completion actions
    must send confirmation when completed
    can archive order when completed
    
    # Error handling
    should retry when failed
    can notify support if max_retries_exceeded
}
✨ 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: can validate payment card
    • Avoid: can validate
  2. Use appropriate verbs for the action type

    • must for critical operations
    • can for standard capabilities
    • should for best practices
    • cannot for explicit restrictions
  3. Add conditions for clarity

    • when <state> for state-dependent actions
    • if <condition> for logical conditions

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
    can receive order
    must validate order items
    cannot proceed if items_unavailable
    
    # Payment processing
    can process payment when validated
    must retry payment if declined
    should notify customer when payment_failed
    
    # Inventory management
    must reserve inventory when payment_complete
    can update stock levels
    
    # Fulfillment
    can prepare shipment when ready
    must update status to shipped
    can track delivery
    
    # Notifications
    must send order confirmation
    should send shipping notification
    may send delivery notification
}
✨ Edit in Studio

Content Management

agent ContentModerator {
    model: "claude-3-sonnet"
    capabilities: [
        "text_analysis",
        "sentiment_detection",
        "policy_compliance"
    ]
    
    can receive content when submitted
    must analyze content
    can approve content if compliant
    must reject content if violates_policy
    should flag content if uncertain
    can escalate to human when complex
}
✨ Edit in Studio

Data Pipeline

agent DataIngestion {
    can fetch data from sources
    must validate schema
    can transform format
    must handle errors
    should retry when connection_failed
}

agent DataProcessor {
    can clean data
    can enrich data
    must validate quality
    can aggregate results
}

agent DataPublisher {
    can write to database when processed
    must create backup
    can notify subscribers
    should log completion
}
✨ Edit in Studio

Related Keywords


Next Steps