build(agent): new-agents-4#58ba63 iteration

This commit is contained in:
agent-58ba63c88b4c9625 2026-04-20 15:21:45 +02:00
parent 2d7cc3767c
commit dff020c9db
3 changed files with 197 additions and 0 deletions

View File

@ -12,3 +12,9 @@ Getting started
- The repository uses a minimal in-tree packaging setup (Python) and PyTest-based tests.
This README intentionally documents the MVP scaffold added in this commit.
Blueprints and Starter Interoperability
- This repository includes a minimal adapter blueprint and a toy cross-venue analytics pipeline to bootstrap MercuryMesh interoperability across ecosystems.
- blueprint/adapter_blueprint.py: A lean, copy-paste friendly adapter skeleton showing how to connect, extract signals, and emit MarketSignal-like payloads.
- blueprint/toy_cross_venue_pipeline.py: A tiny end-to-end example that simulates two venues and merges signals into an AggregatedSignal with a deterministic, offline-friendly merge strategy.
- You can adapt these templates to fit into your existing adapters and contract graph workflow.

View File

@ -0,0 +1,100 @@
"""
Adapter Blueprint for MercuryMesh MVP
This module provides a minimal, well-documented skeleton that teams can copy
when implementing new venue adapters. It is intentionally simple and self-contained
so it can be dropped into new repos or integrated into the existing codebase with
minimal friction.
The blueprint focuses on three responsibilities:
- Connect to a venue feed (simulated or real)
- Extract raw venue data and normalize it into a common signal format
- Emit a Signal contract compatible object that downstream components can consume
Note: This is a blueprint, not a fully-featured adapter. It lacks networking,
security, and production-grade error handling which should be added in production use.
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Dict, Any, Optional
import time
@dataclass
class LocalMarketContext:
venue_id: str
symbol: str
timeframe: str
@dataclass
class MarketSignal:
venue_id: str
symbol: str
timestamp: float
features: Dict[str, float]
class AdapterBlueprint:
"""Minimal adapter blueprint.
- venue_id: identifier for the venue this adapter connects to
- registry: optional contract/GoC registry payload (not required for the blueprint)
"""
def __init__(self, venue_id: str, registry: Optional[Dict[str, Any]] = None) -> None:
self.venue_id = venue_id
self.registry = registry or {}
self.connected = False
def connect(self) -> bool:
"""Simulate a connection to the venue feed.
In a real adapter this would establish a network connection, authenticate, etc.
For the blueprint, we simply mark as connected and return True.
"""
# In a real implementation, add try/except and reconnection logic
self.connected = True
return self.connected
def fetch_raw(self) -> Any:
"""Fetch a raw payload from the venue feed (simulated).
Returns a simple dict that a concrete subclass would parse.
"""
if not self.connected:
raise RuntimeError("Adapter not connected to venue feed")
# Simulated raw payload; in practice this would be a socket/HTTP feed, etc.
now = time.time()
return {
"venue": self.venue_id,
"symbol": "XYZ",
"ts": now,
"raw_features": {
"liquidity_proxy": 0.9,
"order_flow_intensity": 0.6,
"volatility_proxy": 1.1,
},
}
def extract_signal(self, raw: Any) -> MarketSignal:
"""Normalize and map raw payload to a MarketSignal contract."""
venue = str(raw.get("venue", self.venue_id))
symbol = str(raw.get("symbol", "UNKNOWN"))
timestamp = float(raw.get("ts", time.time()))
features = dict(raw.get("raw_features", {}))
return MarketSignal(venue_id=venue, symbol=symbol, timestamp=timestamp, features=features)
def emit(self, signal: MarketSignal) -> MarketSignal:
"""Hook for downstream consumers. In a real adapter this might publish to a bus."""
# For blueprint purposes, simply return the signal to show it was produced
return signal
if __name__ == "__main__":
# Simple demonstration when run as a script
adapter = AdapterBlueprint(venue_id="venue_example")
adapter.connect()
raw = adapter.fetch_raw()
sig = adapter.extract_signal(raw)
print("Blueprint adapter produced signal:", sig)

View File

@ -0,0 +1,91 @@
"""
Toy cross-venue analytics pipeline
This script demonstrates a very small, deterministic cross-venue merge
workflow that mirrors the MVP idea of aggregating signals from multiple venues
without sharing raw data.
It is intentionally lightweight and self-contained to serve as a starter.
Run: python3 blueprint/toy_cross_venue_pipeline.py
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Dict, List
import time
@dataclass
class LocalMarketContext:
venue_id: str
symbol: str
timeframe: str
@dataclass
class MarketSignal:
venue_id: str
symbol: str
timestamp: float
features: Dict[str, float]
@dataclass
class AggregatedSignal:
venue_set: List[str]
feature_vector: Dict[str, float]
privacy_budget_used: float
nonce: int
def simulate_two_venues() -> List[MarketSignal]:
now = time.time()
sigs = [
MarketSignal(
venue_id="venue-A",
symbol="ABC",
timestamp=now,
features={"liquidity_proxy": 0.82, "order_flow_intensity": 0.55, "volatility_proxy": 1.15},
),
MarketSignal(
venue_id="venue-B",
symbol="ABC",
timestamp=now,
features={"liquidity_proxy": 0.78, "order_flow_intensity": 0.60, "volatility_proxy": 1.10},
),
]
return sigs
def aggregate_signals(signals: List[MarketSignal]) -> AggregatedSignal:
if not signals:
return AggregatedSignal(venue_set=[], feature_vector={}, privacy_budget_used=0.0, nonce=0)
# Simple averaging across venues for each feature
keys = set().union(*(s.features.keys() for s in signals))
avg = {k: 0.0 for k in keys}
for s in signals:
for k in keys:
avg[k] = avg[k] + s.features.get(k, 0.0)
n = float(len(signals))
feature_vector = {k: (v / n) for k, v in avg.items()}
privacy_budget_used = min([s.features.get("privacy_budget", 0.0) for s in signals] or [0.0])
return AggregatedSignal(venue_set=[s.venue_id for s in signals], feature_vector=feature_vector, privacy_budget_used=privacy_budget_used, nonce=int(now_epoch()) )
def now_epoch() -> int:
return int(time.time())
def main():
signals = simulate_two_venues()
agg = aggregate_signals(signals)
print("Toy AggregatedSignal")
print(" venues:", agg.venue_set)
print(" features:")
for k, v in agg.feature_vector.items():
print(f" {k}: {v:.4f}")
print(" privacy_budget_used:", agg.privacy_budget_used)
print(" nonce:", agg.nonce)
if __name__ == "__main__":
main()