Add execution-model decision handoff and Jev AALC research

Browse Source
This commit is contained in:
Codex
2026-10-03 07:08:38 +08:00
parent 7188b4ac0f
commit 6c2d26e629
11 changed files with 958 additions and 27 deletions
+57 -4
View File
@@ -77,9 +77,9 @@ class AgentRuntimeTest(unittest.TestCase):
self.kernel.CreateMutexW.return_value = 12345 self.kernel.CreateMutexW.return_value = 12345
self.kernel.GetLastError.return_value = 0 self.kernel.GetLastError.return_value = 0
def run_agent(self, bridge, extra_args=(), constructor_error=None): def run_agent(self, bridge, extra_args=(), constructor_error=None, fixed=True, executor_decider=None):
output = io.StringIO() output = io.StringIO()
environment = dict(os.environ, LC_FIXED_FALLBACK='1') environment = dict(os.environ, LC_FIXED_FALLBACK='1' if fixed else '0')
environment.pop('OPENCODE_API_KEY', None) environment.pop('OPENCODE_API_KEY', None)
with mock.patch.object(agent, 'RUNTIME_HOME', self.home), \ with mock.patch.object(agent, 'RUNTIME_HOME', self.home), \
mock.patch.object(agent, 'STOP_FILE', self.home / 'JEV_STOP'), \ mock.patch.object(agent, 'STOP_FILE', self.home / 'JEV_STOP'), \
@@ -90,8 +90,8 @@ class AgentRuntimeTest(unittest.TestCase):
mock.patch.object(agent.time, 'sleep'), \ mock.patch.object(agent.time, 'sleep'), \
mock.patch.object(agent, 'button_enabled', return_value=False), \ mock.patch.object(agent, 'button_enabled', return_value=False), \
contextlib.redirect_stdout(output): contextlib.redirect_stdout(output):
agent.main() agent.main(executor_decider=executor_decider)
status = json.loads((self.home / 'jev_mirror_status.json').read_text()) status = json.loads((self.home / 'jev_mirror_status.json').read_text(encoding='utf-8'))
return status, factory return status, factory
def test_old_claim_context_does_not_complete_new_run_at_lobby(self): def test_old_claim_context_does_not_complete_new_run_at_lobby(self):
@@ -151,6 +151,59 @@ class AgentRuntimeTest(unittest.TestCase):
self.run_agent(bridge) self.run_agent(bridge)
self.assertEqual(self.kernel.CloseHandle.call_count, 1) self.assertEqual(self.kernel.CloseHandle.call_count, 1)
def test_no_jev_config_publishes_execution_model_request_without_input(self):
bridge = mock.Mock()
bridge.call.return_value = {'ok': True, 'items': [{'text': '路线', 'score': 1}]}
options = {
'wait': {'description': 'wait', 'action': {'tool': 'wait', 'args': {'seconds': .7}}},
'requires_analysis': {'description': 'inspect', 'action': {'tool': 'requires_analysis', 'args': {}}},
'route_w': {'description': 'event above', 'action': {'tool': 'route', 'args': {'key': 'w'}}},
}
with mock.patch.object(agent, 'candidates', return_value=options), mock.patch.object(agent, 'decide') as decide:
status, _ = self.run_agent(bridge, fixed=False)
self.assertEqual(status['state'], 'requires_decision')
self.assertEqual(status['decision_request']['reason'], 'no_jev_model')
self.assertEqual(bridge.call.call_args_list, [mock.call('get_state')])
decide.assert_not_called()
bridge.close.assert_called_once()
self.assertEqual(self.kernel.CloseHandle.call_count, 1)
pending = json.loads((self.home / 'decision_request.json').read_text(encoding='utf-8'))
run = json.loads((self.home / 'mirror_current_run.json').read_text())
self.assertEqual(pending['run_id'], run['run_id'])
self.assertEqual(run['status'], 'requires_decision')
def test_pending_execution_model_decision_can_resume_same_run(self):
save_json(self.home / 'mirror_current_run.json', {
'run_id': 'pending-run', 'start_utc': '2026-10-02T00:00:00+00:00',
'status': 'requires_decision', 'dungeon_completed': False, 'final_reward_claimed': False})
save_json(self.home / 'jev_shop_context.json', {'run_id': 'pending-run', 'floor': 3})
bridge = mock.Mock()
bridge.call.return_value = {'ok': True, 'items': []}
status, _ = self.run_agent(bridge, extra_args=['--resume'])
self.assertEqual(status['state'], 'stopped')
self.assertEqual(status['run_id'], 'pending-run')
def test_embedded_execution_model_selects_and_executes_without_jev(self):
bridge = mock.Mock()
bridge.call.return_value = {'ok': True, 'items': [{'text': '路线', 'score': 1}]}
options = {
'wait': {'description': 'wait', 'action': {'tool': 'wait', 'args': {'seconds': .7}}},
'requires_analysis': {'description': 'inspect', 'action': {'tool': 'requires_analysis', 'args': {}}},
'route_w': {'description': 'event above', 'action': {'tool': 'route', 'args': {'key': 'w'}}},
}
executor = mock.Mock(side_effect=lambda request: {'request_id': request['request_id'], 'choice': 'route_w'})
with mock.patch.object(agent, 'candidates', return_value=options), mock.patch.object(agent, 'decide') as decide:
status, _ = self.run_agent(bridge, fixed=False, executor_decider=executor)
self.assertEqual(status['state'], 'stopped')
executor.assert_called_once()
decide.assert_not_called()
self.assertEqual(bridge.call.call_args_list, [mock.call('get_state'),
mock.call('keypress', {'key': 'w'}), mock.call('keypress', {'key': 'enter'}),
mock.call('keypress', {'key': 'enter'})])
rows = [json.loads(line) for line in (self.home / 'jev_mirror_log.jsonl').read_text(encoding='utf-8').splitlines()]
self.assertEqual(rows[-1]['decision_engine'], 'executor')
self.assertEqual(rows[-1]['jev_ms'], 0)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()