Understanding Routines

Learn how routines provide structured task execution and reusable workflows in Ax.


What is a Routine?

In Ax, based on OpenAI's Swarm framework, a Routine is a predefined sequence of steps that agents can follow to accomplish specific tasks. Routines provide structured task execution, reusable workflows, and consistent behavior patterns.

Structure

  • Clear I/O

    Well-defined inputs and outputs

  • Execution Steps

    Defined sequence of operations

  • Success Criteria

    Clear completion conditions

Execution Flow

  • Input Validation

    Verify and validate inputs

  • Step Execution

    Process each defined step

  • Result Formatting

    Format and return results

Types of Routines

1. Task Routines

async def get_city_weather(city: str):
    """Get current weather for a city using Weather API"""
    # 1. Validate city input
    # 2. Make API request to weather service
    # 3. Parse weather data response
    # 4. Return formatted weather data
    return {
        "city": city,
        "temp": temp_celsius,
        "conditions": conditions,
        "humidity": humidity
    }
  • • Specific task execution
  • • Clear start and end
  • • Defined outcomes

2. Decision Routines

  • • Evaluation logic
  • • Routing decisions
  • • Conditional flows

3. Integration Routines

  • • External system interaction
  • • Data transformation
  • • API handling

Best Practices

Modularity

  • • Keep routines focused
  • • Enable reusability
  • • Maintain independence

Error Handling

  • • Define failure modes
  • • Implement recovery steps
  • • Log important events

Documentation

  • • Clear purpose
  • • Input/output specifications
  • • Usage examples