API Reference
Complete reference for the osmosis-ai Python SDK. The SDK provides two main capabilities:Reward & Evaluation
Decorators and functions for scoring LLM outputs using local rules or LLM-based rubrics
Remote Rollout
Build custom agent loops for training infrastructure integration
Reward API
Decorators
@osmosis_reward
Decorator for local reward functions that compute scores without API calls. Use this for deterministic evaluation logic (exact match, regex, keyword matching). Signature:solution_str(str, required) - Text to evaluateground_truth(str, required) - Reference answerextra_info(dict, optional) - Additional context**kwargs(required) - Future compatibility (see warning below)
float - Score value
Example:
@osmosis_rubric
Decorator for LLM-based evaluation functions. Use this for subjective evaluation that requires semantic understanding (helpfulness, tone, quality). Signature:solution_str(str, required) - Text to evaluateground_truth(str | None, required) - Reference answer (can be None)extra_info(dict, required) - Configuration and context**kwargs(required) - Future compatibility (see warning below)
float - Score value
Example:
Rubric Evaluation
evaluate_rubric()
Evaluate text using an LLM-based rubric. This is the core function for LLM-powered evaluation. Signature:| Parameter | Type | Required | Description |
|---|---|---|---|
rubric | str | Yes | Natural language evaluation criteria |
solution_str | str | Yes | Text to evaluate |
model_info | dict | Yes | LLM provider configuration |
ground_truth | str | No | Reference answer |
original_input | str | No | Original user query |
metadata | dict | No | Additional context |
score_min | float | No | Minimum score (default: 0.0) |
score_max | float | No | Maximum score (default: 1.0) |
timeout | int | No | Request timeout in seconds |
return_details | bool | No | Return full response (default: False) |
float- Score (whenreturn_details=False)dict- Full response with score, explanation, raw payload (whenreturn_details=True)
Exceptions
MissingAPIKeyError
Raised when an API key is not found for a provider.ProviderRequestError
Raised when a provider request fails.ModelNotFoundError
Raised when a specified model is not available (subclass ofProviderRequestError).
Types
ModelInfo (TypedDict)
RewardRubricRunResult (TypedDict)
Returned whenreturn_details=True:
Complete Reward Example
Remote Rollout API
Build custom agent loops that integrate with Osmosis training infrastructure. Your agent runs as an HTTP server while the training cluster handles LLM inference and trajectory collection.Quick Overview
| Component | Description |
|---|---|
RolloutAgentLoop | Base class for implementing agents |
RolloutContext | Execution context with chat(), complete(), error() methods |
RolloutRequest | Initial request with messages, parameters, and metadata |
create_app() | Factory function to create FastAPI server |
Minimal Example
Utility Modules
| Module | Description |
|---|---|
osmosis_ai.rollout.tools | Tool execution helpers (get_tool_call_info, create_tool_result, etc.) |
osmosis_ai.rollout.messages | Message utilities (get_message_content, is_assistant_message, etc.) |
osmosis_ai.rollout.network | Network utilities (detect_public_ip, validate_ipv4, etc.) |
Remote Rollout Documentation
For complete Remote Rollout API documentation, guides, and examples, see the dedicated Remote Rollout section.