Protocols
Section titled “Protocols”FormatMapper
Section titled “FormatMapper”One wire format's typed bidirectional mapping to the canonical IR.
Concrete mappers implement the same operations the container-facing
RelayMapperProtocol declares; the registry in the relay engine
holds FormatMapper implementations.
The wire format this mapper serves; concrete mappers define it.
Convert a source request DTO into canonical RelayRequest.
Convert a canonical RelayRequest into the target request DTO.
Convert a source response DTO into canonical RelayResponse.
Convert a canonical RelayResponse into the target response DTO.
Convert one source stream event into canonical StreamDeltas.
Convert one canonical StreamDelta into target stream events.
Classes
Section titled “Classes”ConversionContext
Section titled “ConversionContext”Per-conversion context with nil-safe callbacks and a loss sink.
Attributes:
options: Cross-protocol adaptation options. Zero-value when the
host supplied no context.
default_max_tokens: Claude max_tokens fallback lookup, always
callable.
safety_setting: Gemini safety threshold lookup, always callable.
supports_image_generation: Gemini image-generation capability
lookup, always callable.
preserve_thinking_suffix: Thinking-suffix bypass policy lookup,
always callable.
media_resolver: Resolver for URL media, or None.
upstream_model: Host model name substituted when the source
payload carries no model; empty when unset.
losses: Semantic losses recorded during conversion.
Adapt a host context, substituting nil-safe defaults.
| Parameter | Type | Description |
|---|---|---|
| `context` | RelayConversionContext | None | Host context, or ``None`` when the gateway supplied none. |
| Type | Description |
|---|---|
| ConversionContext | An adapter with callable callbacks and the host's loss list. |
Return the default max_tokens for model.
Negative callback results are treated as invalid and yield
None; mappers apply their own missing-option policy.
| Parameter | Type | Description |
|---|---|---|
| `model` | str | The already-selected upstream model name. |
| Type | Description |
|---|---|
| int | None | A non-negative default, or ``None`` when absent or invalid. |
Normalize a model name without selecting a different model.
| Parameter | Type | Description |
|---|---|---|
| `model` | str | Raw model name from the source payload. |
| Type | Description |
|---|---|
| str | The cleaned model name. |
Normalize a model name, substituting the host upstream model.
Empty source model names (e.g. Gemini responses that carry no
model) fall back to the host upstream_model so downstream
requests still identify the model.
| Parameter | Type | Description |
|---|---|---|
| `model` | str | Raw model name from the source payload. |
| Type | Description |
|---|---|
| str | The cleaned model name, or the upstream fallback. |
RelayConverterEngine
Section titled “RelayConverterEngine”Explicit source/target conversion over a caller-owned registry.
| Parameter | Type | Description |
|---|---|---|
| `registry` | The registry used when a conversion call does not pass its own ``registry`` override. |
Initialise the engine with a default registry.
Convert a request payload from source to target.
Convert a non-stream response payload from source to target.
Create a stateful stream session for one upstream stream.
Stateful stream conversion is delivered by the shared stream lifecycle in a later task; every current route reports no stream support.
Convert one source stream event through session.
| Exception | Description |
|---|---|
| RelayError | Stateful stream conversion is not implemented yet. |
Close a stream deterministically and return terminal events.
| Exception | Description |
|---|---|
| RelayError | Stateful stream conversion is not implemented yet. |
RelayConverterRegistry
Section titled “RelayConverterRegistry”Caller-owned registry of format mappers with derived routes.
__init__ creates an empty registry; with_defaults prepopulates
the four built-in mappers. A caller may build and mutate their own
instance without touching the process-global default registry.
Create an empty registry.
Return a registry prepopulated with the four built-in mappers.
Register a mapper for its declared wire format.
| Parameter | Type | Description |
|---|---|---|
| `mapper` | FormatMapper | A mapper exposing a ``format`` RelayFormat attribute. |
| Exception | Description |
|---|---|
| RelayError | With code ``duplicate_registration`` when a mapper is already registered for the format, or ``unsupported_format`` when the mapper does not declare a ``RelayFormat`` ``format`` attribute. |
Return the delegating route for a directed pair, or None.
Same-format pairs return None; the engine treats those as a
no-op conversion.
| Parameter | Type | Description |
|---|---|---|
| `source` | RelayFormat | Source wire format. |
| `target` | RelayFormat | Target wire format. |
| Type | Description |
|---|---|
| RelayMapperProtocol | None | The route mapper, or ``None`` when no route exists. |
Return every supported directed route pair.
| Type | Description |
|---|---|
| tuple[tuple[RelayFormat, RelayFormat], Ellipsis] | Sorted route pairs, excluding same-format no-op pairs. |
Return the registered mapper wire-format identifiers.
| Type | Description |
|---|---|
| tuple[str, Ellipsis] | Sorted mapper ids, one per registered mapper. |
Return the converter engine version string.
| Type | Description |
|---|---|
| str | The module-level ``CONVERTER_VERSION`` constant. |
Return the semantic-closeness quality for a directed pair.
Same-format pairs and unconfigured routes fall back to
GOOD/DISCOURAGED via the quality matrix.
| Parameter | Type | Description |
|---|---|---|
| `source` | RelayFormat | Source wire format. |
| `target` | RelayFormat | Target wire format. |
| Type | Description |
|---|---|
| ConversionQuality | The stable quality value for the pair. |
Return the route spec for a directed pair, or None.
Same-format pairs return None (no-op conversion).
| Parameter | Type | Description |
|---|---|---|
| `source` | RelayFormat | Source wire format. |
| `target` | RelayFormat | Target wire format. |
| Type | Description |
|---|---|
| RouteSpec | None | The route spec, or ``None`` when no route exists. |
Return the route spec carrying converter_id, or None.
| Parameter | Type | Description |
|---|---|---|
| `converter_id` | str | A stable ``" |
| Type | Description |
|---|---|
| RouteSpec | None | The matching route spec, or ``None`` when unknown. |
Return specs for every registered directed pair, sorted by id.
RelayModule
Section titled “RelayModule”Relay protocol conversion engine module for Oridecon applications.
Provides the caller-owned relay registry and the public conversion engine behind their contract protocols.
Usage
from oridecon.ai.relay import RelayModule
@module( imports=[RelayModule.configure()])class AppModule(Module): passfrom oridecon.ai.relay import RelayModule
@module( imports=[RelayModule.configure()])class AppModule(Module): passCreate a RelayModule with the built-in converter routes.
| Type | Description |
|---|---|
| DynamicModule | A DynamicModule descriptor. |
Create a RelayModule suitable for unit and integration testing.
Uses the same in-memory registry and synchronous engine as configure; no credentials or I/O are involved.
| Parameter | Type | Description |
|---|---|---|
| `config` | Any | Optional test configuration override; the relay module needs no configuration, so it is ignored. |
| Type | Description |
|---|---|
| DynamicModule | A DynamicModule descriptor. |
RouteSpec
Section titled “RouteSpec”Static metadata for one directed conversion route.
Attributes: source: Source wire format. target: Target wire format. quality: Semantic closeness of the conversion. request_supported: Whether request conversion is available. response_supported: Whether response conversion is available. stream_supported: Whether stateful stream conversion is available. feature_loss_policy: Machine-readable loss reasons this route is expected to record, in order.
Properties:
converter_id: Stable "<source>_to_<target>" identifier.
Stable "<source>_to_<target>" identifier for this route.
Functions
Section titled “Functions”convert_request_by_id
Section titled “convert_request_by_id”Convert a request through the route identified by ``converter_id``.
| Parameter | Type | Description |
|---|---|---|
| `registry` | RelayConverterRegistry | The registry carrying the route. |
| `payload` | RelayRequestPayload | The source request DTO. |
| `converter_id` | str | A stable ``" |
| `context` | RelayConversionContext | None | Optional host conversion context. |
| Type | Description |
|---|---|
| Result[RelayConvertResult[RelayRequestPayload], RelayError] | A request conversion result, or a relay error. |
convert_request_via
Section titled “convert_request_via”Convert a request through an explicit registry.
| Parameter | Type | Description |
|---|---|---|
| `registry` | RelayRegistryProtocol | The registry to resolve the route from. |
| `payload` | RelayRequestPayload | The source request DTO. |
| `source` | RelayFormat | Source wire format. |
| `target` | RelayFormat | Target wire format. |
| `context` | RelayConversionContext | None | Optional host conversion context. |
| Type | Description |
|---|---|
| Result[RelayConvertResult[RelayRequestPayload], RelayError] | A request conversion result, or a relay error. |
convert_response_by_id
Section titled “convert_response_by_id”Convert a response through the route identified by ``converter_id``.
| Parameter | Type | Description |
|---|---|---|
| `registry` | RelayConverterRegistry | The registry carrying the route. |
| `payload` | RelayResponsePayload | The source response DTO. |
| `converter_id` | str | A stable ``" |
| `context` | RelayConversionContext | None | Optional host conversion context. |
| Type | Description |
|---|---|
| Result[RelayConvertResult[RelayResponsePayload], RelayError] | A response conversion result, or a relay error. |
convert_response_via
Section titled “convert_response_via”Convert a response through an explicit registry.
| Parameter | Type | Description |
|---|---|---|
| `registry` | RelayRegistryProtocol | The registry to resolve the route from. |
| `payload` | RelayResponsePayload | The source response DTO. |
| `source` | RelayFormat | Source wire format. |
| `target` | RelayFormat | Target wire format. |
| `context` | RelayConversionContext | None | Optional host conversion context. |
| Type | Description |
|---|---|
| Result[RelayConvertResult[RelayResponsePayload], RelayError] | A response conversion result, or a relay error. |
malformed_payload
Section titled “malformed_payload”The wire payload did not match the expected shape.
| Parameter | Type | Description |
|---|---|---|
| `detail` | str | Human-readable description of the malformed field. |
| Type | Description |
|---|---|
| RelayError | A ``RelayError`` with code ``malformed_payload``. |
media_resolution_required
Section titled “media_resolution_required”URL media requires a resolver the host did not supply.
| Parameter | Type | Description |
|---|---|---|
| `detail` | str | The media URL that cannot be resolved. |
| Type | Description |
|---|---|
| RelayError | A ``RelayError`` with code ``media_resolution_required``. |
missing_required_option
Section titled “missing_required_option”A required field or host option is absent.
| Parameter | Type | Description |
|---|---|---|
| `detail` | str | Which required option is missing. |
| Type | Description |
|---|---|
| RelayError | A ``RelayError`` with code ``missing_required_option``. |
record_loss
Section titled “record_loss”Record a semantic loss on the conversion context.
The engine copies the accumulated losses into the
RelayConvertResult and surfaces warning/error losses as
warnings.
| Parameter | Type | Description |
|---|---|---|
| `context` | ConversionContext | The per-conversion context holding the loss sink. |
| `field` | str | Source wire field (or feature) that was dropped or adapted. |
| `target` | RelayFormat | Target format the loss applies to. |
| `reason` | str | Machine-readable reason (e.g. ``json_mode_not_supported``). |
| `severity` | str | ``error``, ``warning``, or ``info``. |
route_quality
Section titled “route_quality”Return the semantic-closeness quality for a directed pair.
| Parameter | Type | Description |
|---|---|---|
| `source` | RelayFormat | Source wire format. |
| `target` | RelayFormat | Target wire format. |
| Type | Description |
|---|---|
| ConversionQuality | :data:`ConversionQuality.GOOD` for same-format conversion and for routes without a configured quality, otherwise the configured matrix value. |
translate
Section titled “translate”Translate an unexpected exception into a stable error category.
RelayError passes through unchanged. DTO parsing failures
(ValueError, TypeError, KeyError) become
malformed_payload; any other exception becomes
serialization_error.
| Parameter | Type | Description |
|---|---|---|
| `exc` | Exception | The exception raised inside a mapper. |
| `detail` | str | Context describing what was being translated. |
| Type | Description |
|---|---|
| RelayError | A stable ``RelayError``. |
unsupported_feature
Section titled “unsupported_feature”The source feature cannot be converted to the target.
| Parameter | Type | Description |
|---|---|---|
| `detail` | str | The feature that could not be converted. |
| Type | Description |
|---|---|
| RelayError | A ``RelayError`` with code ``unsupported_feature``. |
unsupported_format
Section titled “unsupported_format”The payload does not belong to this mapper's wire format.
| Parameter | Type | Description |
|---|---|---|
| `detail` | str | The expected and actual payload shapes. |
| Type | Description |
|---|---|
| RelayError | A ``RelayError`` with code ``unsupported_format``. |
warning_messages
Section titled “warning_messages”Render losses into stable warning strings.
| Parameter | Type | Description |
|---|---|---|
| `losses` | Sequence[RelayLoss] | Loss records accumulated during conversion. |
| Type | Description |
|---|---|
| tuple[str, Ellipsis] | One ``"field: reason (target, severity)"`` string per loss. |