MCPcopy Create free account
hub / github.com/THUDM/AgentTuning / findValidActionWithSystem2

Function findValidActionWithSystem2

eval_heldout/science-world/eval_utils.py:421–616  ·  view source on GitHub ↗
(predictions, env, task_id, task_description, look, 
                               recent_actions, recent_reward, recent_obs, recent_locs, recent_looks, failed_messages,
                               demo_data, logger, sbert_model, step, last_time_system2_steps, 
                               useful_focus_on, focus_on_done, force_system_1, force_system_2, 
                               gpt_version="gpt-4", llm=None)

Source from the content-addressed store, hash-verified

419
420
421def findValidActionWithSystem2(predictions, env, task_id, task_description, look,
422 recent_actions, recent_reward, recent_obs, recent_locs, recent_looks, failed_messages,
423 demo_data, logger, sbert_model, step, last_time_system2_steps,
424 useful_focus_on, focus_on_done, force_system_1, force_system_2,
425 gpt_version="gpt-4", llm=None):
426
427 inventory = env.inventory()
428 #### Done preparing valid actions ####
429 validActions = getFilteredValidActions(env, look, task_id=task_id, task_desc=task_description)
430 enable_system2 = True
431
432 # if not force_system_2:
433 if True:
434 # 1) if acton in top 3 is valid, try to choose it
435 found_valid_in_top = False
436 action = None
437 if recent_actions[-1].startswith("wait") and predictions[0].startswith("wait"):
438 predictions = predictions[1:]
439 for pred in predictions[:1]:
440 # pred = pred.replace("green house", "greenhouse")
441 pred = try_to_replace(pred, validActions, look, inventory)
442 action = pred.strip()
443 if pred.strip().startswith("focus on") and focus_on_done:
444 break
445 if pred.strip() in validActions:
446 found_valid_in_top = True
447 break
448
449
450
451 logger.info(f"found_valid_in_top={found_valid_in_top} ({action}) ")
452
453
454
455
456 if found_valid_in_top and len(recent_actions) < 10:
457 # Use fast agent in the first 10 steps
458 enable_system2 = False
459
460 if found_valid_in_top and step - last_time_system2_steps[-1] < 5:
461 # only when we did not use System 2 in the past five time steps
462 enable_system2 = False
463
464 if found_valid_in_top and sum(recent_reward[-5:]) > 0:
465 logger.info("Recent scores has increased in recent 5 timesteps. Not doing System 2.")
466 enable_system2 = False
467
468 if found_valid_in_top and action not in recent_actions[-3:]:
469 logger.info("No such actions in recent 3 timesteps. Not doing System 2.")
470 enable_system2 = False
471
472 if found_valid_in_top and not enable_system2 and not force_system_2:
473 assert action is not None
474 logger.info("Using Fast System output.")
475 return False, action
476
477 if ((not found_valid_in_top and step - last_time_system2_steps[-1] <= 2) or force_system_1) and not force_system_2:
478 # only when we did not use System 2 in the past five time steps

Callers

nothing calls this directly

Calls 9

completion_with_backoffFunction · 0.90
getFilteredValidActionsFunction · 0.85
try_to_replaceFunction · 0.85
compose_prompt_to_planFunction · 0.85
post_processFunction · 0.85
sbert_searchFunction · 0.85
encodeMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected