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).
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 key-value pairs to tag and categorize the request. Tags are useful for organizing, filtering, and analyzing evaluations in 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)
Whether to evaluate only the latest assistant response (
True) or all assistant responses (False).
If not provided, defaults to True for chat evaluations.Note: Lightning model cores (align-lightning-*) only support True.Requires composo 0.4.0 or later.How long Composo may keep the content of this request.
"standard" stores it as normal.
"none" evaluates and returns the score without storing anything but the usage record:
no trace, no evaluation record, and a redacted request payload.Note: requests sent with "none" do not appear in Insights — there is no stored
evaluation for them to aggregate.Resolved against your account-level retention setting by most-restrictive-wins, so this
can only ever tighten retention for a request, never loosen it.Requires composo 0.5.0 or later.Which grounding sources this evaluation may draw on. Every source is enabled by
default; set one to The four keys are
false to exclude it from this request only:memory, annotation, document and uploaded_evaluation.
The sources actually used come back in the response’s sources field.Note: only align-20260109 retrieves sources. Disabling one on any other model
core returns a 400 rather than silently doing nothing.When set to
"end_user", the response will include a cleaned_explanation field that rewrites the explanation to only reference content visible in user and assistant messages.Returns
- Returns single
EvaluationResponseif one criterion provided - Returns
list[EvaluationResponse]if multiple criteria provided (evaluated concurrently) - Returns
dictwithtask_idifblock=False
Response Schema
EvaluationResponseA rewrite of
explanation that only references content visible in user and assistant messages. Only present when explanation_cleaning="end_user" is set in the request.The retrieved context the evaluation was grounded in. Each
Source carries an
id and a type, one of document, memory, annotation or
uploaded_evaluation. Documents are deduplicated, so one retrieved several
times appears once. The list is empty when nothing was retrieved.Examples
Basic Async Evaluation
Batch Evaluation with Concurrency
Multiple Criteria (Evaluated Concurrently)
High-Performance Batch Processing
evaluate_trace()
Asynchronously evaluate multi-agent traces.Parameters
Evaluation criterion or list of criteria. Multiple criteria are evaluated concurrently.
Optional key-value pairs to tag and categorize the request. Tags are useful for organizing, filtering, and analyzing trace evaluations in 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)
Whether to evaluate only the latest response (
True) or all responses (False).
If not provided, defaults to False for trace evaluations.Note: Must be False for trace evaluations.Requires composo 0.4.0 or later.How long Composo may keep the content of this trace.
"standard" stores it as normal.
"none" evaluates and returns the score without storing the trace, the evaluation record,
or an unredacted request payload — such requests do not appear in Insights.Resolved against your account-level retention setting by most-restrictive-wins.Requires composo 0.5.0 or later.Which grounding sources this evaluation may draw on —
memory, annotation,
document and uploaded_evaluation. Every source is enabled by default; set one to
false to exclude it from this request only.Note: only align-20260109 retrieves sources. Disabling one on any other model
core returns a 400.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
When to use
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