Skip to main content
This guide provides best practices and requirements for implementing an AdCP:Buy orchestrator that properly handles asynchronous operations, pending states, and human-in-the-loop workflows.

Core Design Principles

1. Asynchronous First

The AdCP:Buy protocol is inherently asynchronous. Operations may take seconds, hours, or even days to complete. DO:
  • Design all operations as async/await
  • Store operation state persistently
  • Handle orchestrator restarts gracefully
  • Implement proper timeout handling
DON’T:
  • Assume immediate completion
  • Use synchronous blocking calls
  • Store state only in memory
  • Retry indefinitely without backoff

2. Task Status Management

Operations progress through standardized status values:

3. State Machine Design

Implement proper state machines aligned with AdCP task statuses:

Implementation Requirements

1. Operation Tracking

Store all operation requests with comprehensive tracking:

2. Async Operation Handler

Implement comprehensive async operation handling:

3. Task Monitoring

Implement efficient task monitoring with exponential backoff:

4. Webhook Support with Reliability Patterns

Implement robust webhook endpoints following AdCP reliability patterns (see Core Concepts: Webhook Reliability):

Webhook Best Practices for Orchestrators

  1. Always implement polling backup - Never rely solely on webhooks
  2. Use exponential backoff - For backup polling when webhooks fail
  3. Monitor webhook health - Track success rates and disable if needed
  4. Handle duplicates gracefully - Use event IDs for idempotent processing
  5. Implement proper timeouts - Don’t wait forever for webhook delivery
  6. Verify webhook authenticity - Always validate signatures
  7. Log webhook events - Maintain audit trail for debugging

5. User Communication

Keep users informed about pending operations:

Example Orchestrator Flow

except Exception as e: await self.tracker.update_status( operation_id, “failed”, error=str(e) ) raise

3. Timeout Handling

Implement reasonable timeouts:

4. Error Recovery

Implement retry logic with circuit breakers:

5. Monitoring and Alerting

Track key metrics:
  • Pending operation count by type
  • Average approval time
  • Rejection rate
  • Task timeout rate
  • API error rate

Testing Considerations

1. Simulate Pending States

Test handling of all pending states:

2. Test Timeout Scenarios

Ensure proper timeout handling:

Conclusion

Building a robust AdCP:Buy orchestrator requires:
  1. Asynchronous design throughout
  2. Proper state management
  3. Graceful handling of pending states
  4. User communication
  5. Monitoring and observability
Remember: Pending states are not errors - they’re a normal part of the advertising workflow.