synth_ai.sdk.optimization.policy.mipro_online_session
MIPRO online session SDK wrapper.
This module provides the MiproOnlineSession class for managing online MIPRO
optimization sessions. In online mode, you drive rollouts locally while the
backend provides prompt candidates through proxy URLs.
Online MIPRO workflow:
- Create a session with your MIPRO configuration
- Get proxy URLs for prompt selection
- Run rollouts locally, calling the proxy URL for each LLM call
- Report rewards back to the session
- Backend generates new prompt proposals based on rewards
Lever/Sensor Integration
Online MIPRO sessions emit canonical lever/sensor outputs through status and result APIs:lever_summary: prompt lever id + per-candidate lever version lineage.lever_versions: resolved lever versions for the selected/best candidate.best_lever_version: scalar best lever version.sensor_frames: summarized rollout telemetry grouped into sensor frames.
PolicyOptimizationResult and PromptLearningResult), including typed helpers:
lever_summary_typedsensor_frame_summaries_typed
Classes
MiproOnlineSession
Client wrapper for online MIPRO optimization sessions.
Manages a single MIPRO online optimization session. In online mode, you
control the rollout loop locally while the backend provides prompt candidates
through proxy URLs. This allows real-time prompt evolution as you report
rewards.
Key features:
- Proxy URLs: Backend provides URLs that select prompt candidates
- Reward reporting: Report rewards after each rollout
- Session management: Pause, resume, or cancel optimization
- Real-time evolution: Prompts evolve as rewards are reported
session_id: Unique session identifierbackend_url: Backend API base URLapi_key: Synth API key for authenticationcorrelation_id: Optional correlation ID for trackingproxy_url: Proxy URL for prompt selection (deprecated, use online_url)online_url: Stable proxy URL for prompt selectionchat_completions_url: URL for chat completions endpointtimeout: HTTP request timeout in seconds
create_async
backend_url: Backend API URL (defaults to production)api_key: Synth API key (defaults to SYNTH_API_KEY env var)config: MIPRO config dict, file path, or Path objectconfig_name: Name of config to load from backendconfig_path: Path to TOML config fileconfig_body: Config dictionaryoverrides: Config overrides to applymetadata: Optional session metadatasession_id: Optional session ID (for resuming)correlation_id: Optional correlation ID for trackingagent_id: Optional agent ID (used as correlation_id if provided)timeout: HTTP request timeout in seconds
- MiproOnlineSession instance with proxy URLs populated
ValueError: If config is invalid or response is malformedFileNotFoundError: If config_path doesn’t exist
create
create_async. See create_async for
detailed parameter documentation.
Returns:
- MiproOnlineSession instance
get_online_url_async
session_id: Existing session IDbackend_url: Backend API URL (defaults to production)api_key: Synth API key (defaults to SYNTH_API_KEY env var)correlation_id: Optional correlation IDtimeout: HTTP request timeout in seconds
- Proxy URL string for prompt selection
ValueError: If response is invalid or missing online_url
get_online_url
get_online_url_async. See that method for
detailed parameter documentation.
Returns:
- Proxy URL string for prompt selection
status_async
- Dictionary with session status information
status
status_async.
Returns:
- Dictionary with session status information
pause
- Dictionary with pause status
resume
- Dictionary with resume status
cancel
- Dictionary with cancellation status
update_reward_async
reward_info: Reward information (must include “score” key)artifact: Optional artifact data from the rolloutmetadata: Optional metadata about the rolloutcorrelation_id: Optional correlation ID (overrides session default)rollout_id: Optional rollout identifiercandidate_id: Optional candidate prompt identifiertrace_ref: Optional trace referencestop: Optional flag to stop optimization
- Dictionary with reward acknowledgment
update_reward
update_reward_async. See that method for
detailed parameter documentation.
Returns:
- Dictionary with reward acknowledgment
get_prompt_urls_async
correlation_id: Optional correlation ID (overrides session default)
- Dictionary with “online_url” and optionally “chat_completions_url”
get_prompt_urls
get_prompt_urls_async. See that method for
detailed parameter documentation.
Returns:
- Dictionary with proxy URLs