Skip to main content

Overview

The Composo class provides a synchronous client for evaluating chat messages against custom criteria. Suitable for single evaluations or small batch scenarios with automatic retry mechanisms.

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. If not provided, uses the default evaluation model.
timeout
float
default:"60.0"
Request timeout in seconds. Total time to wait for a single request (including retries).

Example


evaluate()

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. Mutually exclusive with input.Supported roles: system, user, assistant, toolExample:
input
string | list
Raw OpenAI Responses API input — the value passed as input to openai.responses.create(). Mutually exclusive with messages. Use this when evaluating responses from the OpenAI Responses API alongside the result parameter.Example:
criteria
string | list[string]
Evaluation criterion or list of criteria. Can be a custom criterion string or use pre-built criteria from composo.criteria.Example:
system
string
Optional system message to set AI behavior and context for the evaluation.
tools
list[dict]
Optional list of tool definitions for evaluating tool calls. Each tool should follow the OpenAI function calling format.
result
dict | openai.types.responses.Response
Optional LLM result to append to the conversation for evaluation. Accepts a standard dict or an openai.types.responses.Response object returned by openai.responses.create() — Composo auto-detects the type and adapts it automatically.
block
boolean
default:"True"
If False, returns a dictionary with task_id instead of blocking for results. Use for async job submission.
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 (converted to strings), 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
  • 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 the criterion was deemed not applicable.
explanation
string
Detailed explanation of the evaluation score and reasoning.
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 Evaluation

Multiple Criteria Evaluation

Tool Call Evaluation

Non-blocking Evaluation

OpenAI Responses API — Built-in Tools

Pass the Response object returned by openai.responses.create() directly as result. Use input instead of messages to match the Responses API’s input format.
Known limitation: Composo evaluates only the context provided in the current call — it cannot follow the previous_response_id chain to reconstruct prior turns. If your workflow uses multi-turn Responses API conversations (i.e. passing previous_response_id to link responses), make sure to pass the full conversation history explicitly via messages rather than relying on input + result alone.

OpenAI Responses API — Remote MCP Server


evaluate_trace()

Evaluate multi-agent traces with full conversation history across multiple agents.

Parameters

trace
MultiAgentTrace
required
Multi-agent trace object containing agent interactions, initial input, and final output.
criteria
string | list[string]
required
Evaluation criterion or list of criteria for trace evaluation.
model_core
ModelCore
Optional model core identifier for trace evaluation.
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 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]
  • Returns single MultiAgentTraceResponse if one criterion provided
  • Returns list[MultiAgentTraceResponse] if multiple criteria provided
  • Returns dict with task_id if block=False

Response Schema

MultiAgentTraceResponse
agent_scores
dict
Per-agent evaluation scores mapping agent IDs to their individual scores.
overall_score
float
Overall trace score aggregated across all agents.
explanation
string
Detailed explanation of the trace evaluation.
criterion
string
The criterion that was evaluated.

Example


Context Manager Usage

The Composo client supports context managers for automatic resource cleanup: