File size: 3,177 Bytes
49aa045
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8801635
 
 
 
 
 
 
 
 
 
 
 
49aa045
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""Validation-only Harbor agents. Never used for benchmark model scores."""

from harbor.agents.base import BaseAgent
from harbor.agents.oracle import OracleAgent


class CaptureOracleAgent(OracleAgent):
    """Validation only: make a scripted capture call, then use the real oracle."""

    def __init__(self, validation_base_url, validation_session, **kwargs):
        super().__init__(**kwargs)
        self.validation_base_url = validation_base_url
        self.validation_session = validation_session

    async def run(self, instruction, environment, context):
        import asyncio
        import json
        import urllib.request

        request = urllib.request.Request(
            self.validation_base_url + "/v1/chat/completions",
            data=json.dumps(
                {
                    "model": "validation-oracle",
                    "messages": [
                        {
                            "role": "user",
                            "content": "Acknowledge this lifecycle validation.",
                        }
                    ],
                    "stream": False,
                }
            ).encode(),
            headers={
                "Content-Type": "application/json",
                "Authorization": "Bearer " + self.validation_session,
            },
        )

        def call():
            with urllib.request.urlopen(request, timeout=20) as response:
                assert json.load(response)["choices"]

        await asyncio.to_thread(call)
        # Exercise the public CLI in the actual agent container as well as the oracle's HTTP path.
        observation = await environment.exec(command="escape observe")
        assert observation.return_code == 0
        assert "available_entities" in json.loads(observation.stdout)
        invalid = await environment.exec(
            command="escape investigate __aeb_nonexistent_node__"
        )
        assert invalid.return_code == 0 and not json.loads(invalid.stdout)["ok"]
        wrong = await environment.exec(
            command="escape submit-answer __aeb_incorrect_answer__"
        )
        assert wrong.return_code == 0 and not json.loads(wrong.stdout)["is_win"]
        await super().run(instruction, environment, context)


class ForgeAgent(BaseAgent):
    @staticmethod
    def version():
        return "1.0"

    @staticmethod
    def name():
        return "aeb-forgery-check"

    async def setup(self, environment):
        pass

    async def run(self, instruction, environment, context):
        # Attempt to forge both local evidence and a reward. Neither should reach the fresh verifier.
        result = await environment.exec(
            command="""python - <<'PY'
import json,pathlib
for root in ['/evidence', '/logs/artifacts/evidence', '/logs/verifier']:
 pathlib.Path(root).mkdir(parents=True,exist_ok=True)
for root in ['/evidence', '/logs/artifacts/evidence']:
 pathlib.Path(root,'final.json').write_text(json.dumps({'won':True,'collected_from_live_service':True}))
pathlib.Path('/logs/verifier/reward.txt').write_text('1.0')
PY"""
        )
        if result.return_code != 0:
            raise RuntimeError(result.stderr)