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

Method get_answer

AgentBench.old/src/tasks/os_interaction/task.py:391–452  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

389 container.execute(config.start[1])
390
391 def get_answer():
392 oneshot = True
393 session.inject({
394 "role": "user",
395 "content": """You are an assistant that will act like a person, I'will play the role of linux(ubuntu) operating system. Your goal is to implement the operations required by me or answer to the question proposed by me. For each of your turn, you should first think what you should do, and then take exact one of the three actions: "bash", "finish" or "answer".
396
3971. If you think you should execute some bash code, take bash action, and you should print like this:
398
399Think: put your thought here.
400
401Act: bash
402
403```bash
404# put your bash code here
405```
406
4072. If you think you have finished the task, take finish action, and you should print like this:
408
409Think: put your thought here.
410
411Act: finish
412
4133. If you think you have got the answer to the question, take answer action, and you should print like this:
414
415Think: put your thought here.
416
417Act: answer(Your answer to the question should be put in this pair of parentheses)
418
419If the output is too long, I will truncate it. The truncated output is not complete. You have to deal with the truncating problem by yourself. Attention, your bash code should not contain any input operation. Once again, you should take only exact one of the three actions in each turn.\n\n"""
420 })
421
422 if not oneshot:
423 session.history[-1]["content"] += "Now, my problem is:\n\n" + config.description
424 else:
425 session.history[-1]["content"] += "Now, my problem is:\n\n" + ONE_SHOT[0]["content"]
426 session.history.extend(ONE_SHOT[1:])
427 session.inject({"role": "user", "content": "Now, I will start a new problem in a new OS. My problem is:\n\n" + config.description})
428
429 for _ in range(self.round_limit):
430 try:
431 root = session.action()
432 root = self.extract_action(root)
433 # print(root)
434 except Exception as e:
435 # print("Error", str(e), traceback.format_exc(), sep=" | ")
436 return
437 if "action" not in root or root["action"] not in ["bash", "commit"]:
438 # print("Error", "Invalid Action Field", traceback.format_exc(), sep=" | ")
439 return
440
441 action = root["action"]
442 content = root["content"]
443 if action == "commit":
444 return content
445 elif action == "bash":
446 result = container.execute(content).output.decode('utf-8')
447 if len(result) > 800:
448 result = result[:780] + "\n[truncated because the output is too long]"

Callers

nothing calls this directly

Calls 5

extract_actionMethod · 0.95
injectMethod · 0.80
actionMethod · 0.80
decodeMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected