Skip to main content

Overview

The AsyncComposo 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

api_key
string
Your Composo API key for authentication. If not provided, will be loaded from the COMPOSO_API_KEY environment variable.
base_url
string
default:"https://platform.composo.ai"
API base URL. Change only if using a custom Composo deployment.
num_retries
integer
default:"1"
Number of retries on request failure. Each retry uses exponential backoff with jitter. Minimum value is 1 (retries cannot be disabled).
model_core
string
Optional model core identifier for specifying the evaluation model.
max_concurrent_requests
integer
default:"5"
Maximum number of concurrent API requests. Controls throughput and prevents rate limit issues.Recommendations:
  • 5-10: Most use cases
  • 20+: High-performance scenarios with adequate rate limits
timeout
float
default:"60.0"
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

messages
list[dict]
required
List of chat messages to evaluate. Each message should be a dictionary with role and content keys.Supported roles: system, user, assistant, tool
criteria
string | list[string]
Evaluation criterion or list of criteria. Multiple criteria are evaluated concurrently for better performance.
system
string
Optional system message to set AI behavior and context.
tools
list[dict]
Optional list of tool definitions for evaluating tool calls.
result
dict
Optional LLM result to append to the conversation.
block
boolean
default:"True"
If False, returns a dictionary with task_id instead of blocking for results.
tags
dict[str, Any]
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)
Example:
evaluate_latest
boolean
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.
explanation_cleaning
string
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

result
EvaluationResponse | list[EvaluationResponse]
  • Returns single EvaluationResponse if one criterion provided
  • Returns list[EvaluationResponse] if multiple criteria provided (evaluated concurrently)
  • Returns dict with task_id if block=False

Response Schema

EvaluationResponse
score
float | null
Evaluation score between 0.0 and 1.0. Returns null if criterion not applicable.
explanation
string
Detailed explanation of the evaluation score.
cleaned_explanation
string | null
A 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.

Examples

Basic Async Evaluation

Batch Evaluation with Concurrency

Multiple Criteria (Evaluated Concurrently)

High-Performance Batch Processing


evaluate_trace()

Asynchronously evaluate multi-agent traces.

Parameters

trace
MultiAgentTrace
required
Multi-agent trace object containing agent interactions.
criteria
string | list[string]
required
Evaluation criterion or list of criteria. Multiple criteria are evaluated concurrently.
model_core
ModelCore
Optional model core identifier.
block
boolean
default:"True"
If False, returns task_id instead of blocking.
tags
dict[str, Any]
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)
Example:
evaluate_latest
boolean
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.

Returns

result
MultiAgentTraceResponse | list[MultiAgentTraceResponse]
  • Single or list of trace evaluation responses
  • Multiple criteria evaluated concurrently

Example


Context Manager Usage

The AsyncComposo client supports async context managers for automatic resource cleanup:

Concurrency Control

The AsyncComposo client uses a semaphore to limit concurrent requests, preventing rate limit issues and excessive resource usage.

Best Practices

  1. Start Conservative: Begin with max_concurrent_requests=5 and increase if needed
  2. Monitor Rate Limits: Watch for RateLimitError exceptions and adjust accordingly
  3. Use Batching: For very large datasets, process in batches to manage memory
  4. Handle Errors: Use asyncio.gather(..., return_exceptions=True) for error resilience

Performance Optimization

Example: Optimal Batch Processing


Comparison with Sync Client

FeatureComposoAsyncComposo
Use CaseSingle evaluationsBatch processing
ConcurrencySequentialConcurrent
PerformanceSlower for batchesOptimized for batches
APISynchronousAsynchronous
ComplexitySimplerRequires async/await
Concurrency ControlN/Amax_concurrent_requests
When to use AsyncComposo:
  • Evaluating 10+ conversations
  • Multiple criteria per evaluation
  • High-throughput applications
  • Integration with async frameworks (FastAPI, aiohttp)
When to use Composo:
  • Single evaluations
  • Simple scripts
  • Synchronous applications
  • Learning/prototyping