agenticraft_foundation.protocols.compatibility¶
Protocol compatibility matrix — translation costs between protocol pairs.
Protocol compatibility relation.
Defines full, partial, or incompatible translation between protocols based on Definition 6 (Protocol Compatibility Relation) from the formal model.
Compatibility levels: - FULL: No semantic loss during translation. - PARTIAL: Some semantic loss possible. - NONE: No translation possible.
CompatibilityLevel
¶
Bases: str, Enum
Protocol compatibility levels.
Represents the degree of semantic preservation when translating between protocols.
FULL = 'full'
class-attribute
instance-attribute
¶
✓ No semantic loss - complete bidirectional translation
PARTIAL = 'partial'
class-attribute
instance-attribute
¶
⚡ Some semantic loss possible - requires validation
NONE = 'none'
class-attribute
instance-attribute
¶
✗ No translation possible - incompatible protocols
CompatibilityRelation
dataclass
¶
Protocol compatibility relation p₁ ∼_p p₂.
Based on Definition 6 (Protocol Compatibility Relation) from the formal model. For protocols p₁, p₂ ∈ P, p₁ ∼p p₂ ⟺ ∃ bidirectional translator T
| ATTRIBUTE | DESCRIPTION |
|---|---|
source |
Source protocol
TYPE:
|
target |
Target protocol
TYPE:
|
level |
Compatibility level (FULL, PARTIAL, NONE)
TYPE:
|
semantic_loss |
Estimated semantic loss (0.0 = no loss, 1.0 = total loss)
TYPE:
|
reversible |
Whether T⁻¹(T(m)) ≈ m holds
TYPE:
|
latency_factor |
Relative latency multiplier for translation
TYPE:
|
conditions |
Conditions under which translation works
TYPE:
|
feature_mapping |
Mapping of features between protocols
TYPE:
|
is_full
property
¶
Check if this is full compatibility.
is_partial
property
¶
Check if this is partial compatibility.
is_compatible
property
¶
Check if translation is possible (FULL or PARTIAL).
get_translation_cost()
¶
Calculate translation cost based on semantic loss and latency.
| RETURNS | DESCRIPTION |
|---|---|
float
|
Combined cost factor for routing decisions |
ProtocolCompatibilityMatrix
¶
Lookup and query protocol compatibility.
Provides efficient access to the protocol compatibility matrix for routing and translation decisions.
__init__(compatibility_data=None)
¶
Initialize compatibility matrix.
| PARAMETER | DESCRIPTION |
|---|---|
compatibility_data
|
Optional custom compatibility data. Uses PROTOCOL_COMPATIBILITY by default.
TYPE:
|
get_compatibility(source, target)
¶
Get compatibility relation between two protocols.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
Source protocol
TYPE:
|
target
|
Target protocol
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompatibilityRelation
|
CompatibilityRelation describing the translation |
can_translate(source, target)
¶
Check if translation is possible between protocols.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
Source protocol
TYPE:
|
target
|
Target protocol
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if translation is possible (FULL or PARTIAL) |
get_translation_cost(source, target)
¶
Get the cost of translating between protocols.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
Source protocol
TYPE:
|
target
|
Target protocol
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Translation cost (infinity if not possible) |
get_semantic_loss(source, target)
¶
Get the expected semantic loss for a translation.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
Source protocol
TYPE:
|
target
|
Target protocol
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Semantic loss (0.0 to 1.0, 1.0 if not possible) |
get_all_compatible(source, level=None)
¶
Get all protocols compatible with a source protocol.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
Source protocol
TYPE:
|
level
|
Optional level filter (FULL or PARTIAL)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[ProtocolName]
|
List of compatible protocols |
get_best_translation_path(source, target, max_hops=2)
¶
Find the best translation path (lowest semantic loss).
Uses breadth-first search with cost optimization.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
Source protocol
TYPE:
|
target
|
Target protocol
TYPE:
|
max_hops
|
Maximum number of intermediate translations
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[ProtocolName] | None
|
List of protocols in the path, or None if no path exists |
register_compatibility(relation)
¶
Register a new compatibility relation.
| PARAMETER | DESCRIPTION |
|---|---|
relation
|
Compatibility relation to register
TYPE:
|
get_statistics()
¶
Get matrix statistics.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary of statistics |