Overview
TheAsyncComposo class provides an asynchronous client for evaluating chat messages with support for concurrent processing. Ideal for large batch evaluation scenarios and high-throughput applications.
Constructor
Parameters
Your Composo API key for authentication. If not provided, will be loaded from the
COMPOSO_API_KEY environment variable.API base URL. Change only if using a custom Composo deployment.
Number of retries on request failure. Each retry uses exponential backoff with jitter. Minimum value is 1 (retries cannot be disabled).
Optional model core identifier for specifying the evaluation model.
Maximum number of concurrent API requests. Controls throughput and prevents rate limit issues.Recommendations:
5-10: Most use cases20+: High-performance scenarios with adequate rate limits
Request timeout in seconds. Total time to wait for a single request (including retries).
Example
evaluate()
Asynchronously evaluate messages against one or more evaluation criteria.Parameters
List of chat messages to evaluate. Each message should be a dictionary with
role and content keys.Supported roles: system, user, assistant, toolEvaluation criterion or list of criteria. Multiple criteria are evaluated concurrently for better performance.
Optional system message to set AI behavior and context.
Optional list of tool definitions for evaluating tool calls.
Optional LLM result to append to the conversation.
If
False, returns a dictionary with task_id instead of blocking for results.Optional key-value pairs to tag and categorize the request. Tags are useful for organizing, filtering, and analyzing evaluations in Metabase or other analytics tools.Constraints:
- Keys must be strings, maximum 64 characters
- Values must be strings, numbers, or bools, maximum 64 characters
- No nested structures (dictionaries, lists, tuples, or sets)
Returns
- Returns single
EvaluationResponseif one criterion provided - Returns
list[EvaluationResponse]if multiple criteria provided (evaluated concurrently) - Returns
dictwithtask_idifblock=False
Response Schema
EvaluationResponseEvaluation score between 0.0 and 1.0. Returns
null if criterion not applicable.Detailed explanation of the evaluation score.
Examples
Basic Async Evaluation
Batch Evaluation with Concurrency
Multiple Criteria (Evaluated Concurrently)
High-Performance Batch Processing
evaluate_trace()
Asynchronously evaluate multi-agent traces.Parameters
Multi-agent trace object containing agent interactions.
Evaluation criterion or list of criteria. Multiple criteria are evaluated concurrently.
Optional model core identifier.
If
False, returns task_id instead of blocking.Optional key-value pairs to tag and categorize the request. Tags are useful for organizing, filtering, and analyzing trace evaluations in Metabase or other analytics tools.Constraints:
- Keys must be strings, maximum 64 characters
- Values must be strings, numbers, or bools (converted to strings), maximum 64 characters
- No nested structures (dictionaries, lists, tuples, or sets)
Returns
- Single or list of trace evaluation responses
- Multiple criteria evaluated concurrently
Example
Context Manager Usage
TheAsyncComposo client supports async context managers for automatic resource cleanup:
Concurrency Control
TheAsyncComposo client uses a semaphore to limit concurrent requests, preventing rate limit issues and excessive resource usage.
Best Practices
- Start Conservative: Begin with
max_concurrent_requests=5and increase if needed - Monitor Rate Limits: Watch for
RateLimitErrorexceptions and adjust accordingly - Use Batching: For very large datasets, process in batches to manage memory
- Handle Errors: Use
asyncio.gather(..., return_exceptions=True)for error resilience
Performance Optimization
Example: Optimal Batch Processing
Comparison with Sync Client
| Feature | Composo | AsyncComposo |
|---|---|---|
| Use Case | Single evaluations | Batch processing |
| Concurrency | Sequential | Concurrent |
| Performance | Slower for batches | Optimized for batches |
| API | Synchronous | Asynchronous |
| Complexity | Simpler | Requires async/await |
| Concurrency Control | N/A | max_concurrent_requests |
AsyncComposo:
- Evaluating 10+ conversations
- Multiple criteria per evaluation
- High-throughput applications
- Integration with async frameworks (FastAPI, aiohttp)
Composo:
- Single evaluations
- Simple scripts
- Synchronous applications
- Learning/prototyping