File size: 2,037 Bytes
fdb4876
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/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)