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

string
Your Composo API key for authentication. If not provided, will be loaded from the COMPOSO_API_KEY environment variable.
string
default:"https://platform.composo.ai"
API base URL. Change only if using a custom Composo deployment.
integer
default:"1"
Number of retries on request failure. Each retry uses exponential backoff with jitter. Minimum value is 1 (retries cannot be disabled).
string
Optional model core identifier for specifying the evaluation model.
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
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

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
string | list[string]
Evaluation criterion or list of criteria. Multiple criteria are evaluated concurrently for better performance.
string
Optional system message to set AI behavior and context.
list[dict]
Optional list of tool definitions for evaluating tool calls.
dict
Optional LLM result to append to the conversation.
boolean
default:"True"
If False, returns a dictionary with task_id instead of blocking for results.
dict[str, Any]
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)
Example:
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.
string
default:"standard"
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.
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

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

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

Returns

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

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