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

This commit is contained in:
agent-58ba63c88b4c9625 2026-04-22 22:16:59 +02:00
parent b018a03913
commit ef6b39aaa4
3 changed files with 150 additions and 0 deletions

View File

@ -13,6 +13,12 @@ except Exception:
DeltaCRDT = None # type: ignore
deterministic_merge = None # type: ignore
from .ledger import LedgerSigner, sign_and_append
try:
# Re-export optional CRDT helpers if present
from .ir import LocalArbProblem, SharedSignals # type: ignore
except Exception:
LocalArbProblem = None # type: ignore
SharedSignals = None # type: ignore
__all__ = [
"Asset",
@ -31,4 +37,7 @@ __all__ = [
# Delta synchronization primitives (optional extension)
"DeltaCRDT",
"deterministic_merge",
# IR scaffolds
"LocalArbProblem",
"SharedSignals",
]

View File

@ -31,3 +31,33 @@ class CentralCurator:
total = sum(d.get(k, 0.0) for d in local_deltas)
shared[k] = total / len(local_deltas)
return shared
def coordinate_admm(self, local_deltas: List[Dict[str, float]], rho: float = 0.5) -> Dict[str, float]:
"""Lightweight ADMM-inspired coordination.
Produces a conservative, stable cross-venue delta by combining the
simple average with a small correction towards the per-venue means.
This is a minimal, deterministic placeholder for a full ADMM-like
coordinator used in the MVP to illustrate cross-venue coherence.
"""
if not local_deltas:
return {}
# Primal (shared) update: average across venues
keys = set().union(*local_deltas)
shared: Dict[str, float] = {}
means: Dict[str, float] = {}
for k in keys:
values = [d.get(k, 0.0) for d in local_deltas]
means[k] = sum(values) / len(values) if values else 0.0
shared[k] = means[k]
# Dual-adjustment toward per-venue means (conservative bias)
adjusted: Dict[str, float] = {}
for k in keys:
adjusted[k] = shared.get(k, 0.0) - rho * (shared.get(k, 0.0) - means.get(k, 0.0))
return adjusted
def coordinate_with_admm(self, local_deltas: List[Dict[str, float]], rho: float = 0.5) -> Dict[str, float]:
"""Public wrapper to expose ADMM-like coordination."""
return self.coordinate_admm(local_deltas, rho)

111
deltax_forge_cross/ir.py Normal file
View File

@ -0,0 +1,111 @@
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Dict, List
@dataclass
class LocalArbProblem:
venue_id: str
assets: List[str]
target_delta_budget: float
liquidity_budget: float
latency_budget: float
def to_dict(self) -> Dict:
return {
"venue_id": self.venue_id,
"assets": list(self.assets),
"target_delta_budget": self.target_delta_budget,
"liquidity_budget": self.liquidity_budget,
"latency_budget": self.latency_budget,
}
@dataclass
class SharedSignals:
version: int
price_deltas: Dict[str, float] # asset_symbol -> delta
correlations: Dict[str, float] = field(default_factory=dict)
def to_dict(self) -> Dict:
return {
"version": self.version,
"price_deltas": dict(self.price_deltas),
"correlations": dict(self.correlations),
}
@dataclass
class PlanDeltaIR:
delta_actions: Dict[str, float]
timestamp: float
contract_id: str
author_signature: str
def to_dict(self) -> Dict:
return {
"delta_actions": dict(self.delta_actions),
"timestamp": self.timestamp,
"contract_id": self.contract_id,
"author_signature": self.author_signature,
}
@dataclass
class DualVariables:
shadow_prices: Dict[str, float] = field(default_factory=dict)
def to_dict(self) -> Dict:
return {"shadow_prices": dict(self.shadow_prices)}
@dataclass
class PrivacyBudget:
per_message_budget: float
total_budget: float
def to_dict(self) -> Dict:
return {
"per_message_budget": self.per_message_budget,
"total_budget": self.total_budget,
}
@dataclass
class AuditLog:
entries: List[str] = field(default_factory=list)
def to_dict(self) -> Dict:
return {"entries": list(self.entries)}
@dataclass
class TimeRounds:
rounds: int
round_length_seconds: float
def to_dict(self) -> Dict:
return {"rounds": self.rounds, "round_length_seconds": self.round_length_seconds}
@dataclass
class GoCRegistryEntry:
contract: str
version: str
metadata: Dict[str, str] = field(default_factory=dict)
def to_dict(self) -> Dict:
return {"contract": self.contract, "version": self.version, "metadata": dict(self.metadata)}
__all__ = [
"LocalArbProblem",
"SharedSignals",
"PlanDeltaIR",
"DualVariables",
"PrivacyBudget",
"AuditLog",
"TimeRounds",
"GoCRegistryEntry",
]