build(agent): new-agents#a6e6ec iteration

This commit is contained in:
agent-a6e6ec231c5f7801 2026-04-21 10:37:29 +02:00
parent 074785a592
commit 2690beb2cd
4 changed files with 96 additions and 1 deletions

View File

@ -9,7 +9,7 @@ Public API (minimal):
- GraphOfContracts Registry (minimal MVP wiring for adapters and contract schemas)
"""
from .core import MarketStateSnapshot, SharedSignals, PlanDelta, AuditLog, FederatedCoordinator
from .core import MarketStateSnapshot, SharedSignals, PlanDelta, AuditLog, FederatedCoordinator, LocalBook
from .registry import GraphOfContractsRegistry # type: ignore
__all__ = [
@ -17,6 +17,7 @@ __all__ = [
"SharedSignals",
"PlanDelta",
"AuditLog",
"LocalBook",
"FederatedCoordinator",
"GraphOfContractsRegistry",
]

View File

@ -0,0 +1,65 @@
"""Adapters: MVP wiring skeleton for Phase 0 MercuryMesh.
This module provides tiny, well-scoped adapters that stand in for
- ExchangeDataFeedAdapter
- VenueBrokerAdapter
and a small helper to demonstrate a Phase 0 end-to-end delta aggregation
workflow using the existing FederatedCoordinator.
These are deliberately minimal and safe stubs intended for educational
labs and integration testing. They do not perform real network IO and are
fully compatible with the in-repo primitives in core.py.
"""
from __future__ import annotations
from typing import Dict, List
from .core import MarketStateSnapshot, PlanDelta
from .core import FederatedCoordinator
class ExchangeDataFeedAdapter:
"""Stub adapter simulating a data feed from an exchange."""
def __init__(self, name: str = "exchange") -> None:
self.name = name
def connect(self) -> bool:
# In a real implementation, establish TLS session, authenticate, etc.
return True
def fetch_signals(self) -> List[Dict[str, float]]:
# Placeholder: return no signals by default.
return []
class VenueBrokerAdapter:
"""Stub adapter simulating a venue broker connection."""
def __init__(self, venue: str = "venue") -> None:
self.venue = venue
def connect(self) -> bool:
return True
def send_delta(self, delta: PlanDelta) -> None:
# In a real system, this would transmit delta to the venue.
# Here we simply acknowledge the action for the interface.
pass
def phase0_demo(adapter_a: ExchangeDataFeedAdapter, adapter_b: ExchangeDataFeedAdapter) -> PlanDelta:
"""Demonstrate a tiny Phase 0 end-to-end delta aggregation.
- Collect signals from two adapters (could be empty in the MVP).
- Run the FederatedCoordinator to compute an aggregate delta.
- Return the resulting PlanDelta.
This is intentionally simple and side-effect free.
"""
signals: List[Dict[str, float]] = []
signals.extend(adapter_a.fetch_signals())
signals.extend(adapter_b.fetch_signals())
delta = FederatedCoordinator.aggregate_signals(signals)
return delta

View File

@ -112,3 +112,7 @@ class FederatedCoordinator:
contract_id="root",
privacy_budget=0.0,
)
# Canonical alias for cross-venue compatibility (MVP terminology)
# LocalBook is synonymous with MarketStateSnapshot in this MVP.
LocalBook = MarketStateSnapshot

View File

@ -0,0 +1,25 @@
"""Tests for the lightweight Graph-of-Contracts registry MVP."""
from mercurymesh_federated_reproducible_marke.registry import GraphOfContractsRegistry, ContractSpec, registry
def test_registry_basic_operations():
# Create a fresh spec and register it
spec = ContractSpec(name="MarketState", version="0.1", schema={"type": "object"})
# Use the module-level registry for realism
registry.register_contract(spec)
# Retrieve by name
retrieved = registry.get_contract("MarketState")
assert retrieved is not None
assert retrieved.name == "MarketState"
assert retrieved.version == "0.1"
# Ensure list_contracts contains the new contract
names = registry.list_contracts()
assert "MarketState" in names
# Ensure to_dict reflects the registered contract
d = registry.to_dict()
assert "MarketState" in d
assert d["MarketState"]["name"] == "MarketState"