#!/usr/bin/env python3 """Binance Agent OS / MCP adapter for the BaudCoin miner. The reference `miner.py` reads challenges on stdin and writes answers on stdout, so any wrapper process can supply solutions. This adapter shows the direct integration: override `solve()` so the agent's own model answers each challenge in-process, then run the live loop. Usage inside an agent runtime: from agent_os import run_with_model run_with_model(my_model_fn) where `my_model_fn(prompt: str) -> str` calls whatever LLM the agent is driving (Claude via the Anthropic SDK, an MCP tool, a local model, anything). """ import miner def run_with_model(model_fn): """Wire an LLM into the miner and start the live epoch loop. Args: model_fn: callable taking the challenge prompt and returning the answer. """ def solve(challenge): prompt = challenge.get("prompt", "") constraints = challenge.get("constraints", {}) # Give the model the constraints too; the coordinator validates against them. framed = ( prompt + "\n\nConstraints you must satisfy: " + ", ".join(f"{k}={v}" for k, v in constraints.items()) ) return model_fn(framed).strip() # Swap the reference stdin/stdout solver for the model-backed one. miner.solve = solve miner.cmd_mine() def demo_with_model(model_fn): """Same wiring, but against the offline demo lane. No wallet funding needed.""" def solve(challenge): return model_fn(challenge.get("prompt", "")).strip() miner.solve = solve miner.cmd_demo() if __name__ == "__main__": # Trivial echo model so `python agent_os.py` is runnable as a smoke test. # Replace with a real model in production. def echo_model(prompt): # A real agent returns a reasoned answer here. return "the euro [1][2]" print("Running the offline demo lane with a stub model.") print("Replace echo_model with your agent's LLM call.\n") demo_with_model(echo_model)