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

Method execute

AgentBench.old/src/tasks/os_interaction/task.py:44–79  ·  view source on GitHub ↗
(self, command: str)

Source from the content-addressed store, hash-verified

42 pass
43
44 def execute(self, command: str):
45 class DummyOutput:
46 output: bytes
47 exit_code: int
48
49 def __init__(self, code, o):
50 self.output = o
51 self.exit_code = code
52
53 # print("=== EXECUTING ===\n", command)
54 if not isinstance(command, str):
55 return DummyOutput(-1, b'')
56 self.sock.send(command.encode("utf-8") + b'\n')
57 # ignore input line
58 data = self.sock.recv(8)
59 _, n = struct.unpack('>BxxxL', data)
60 _ = self.sock.recv(n)
61 output = b''
62 while True:
63 try:
64 data = self.sock.recv(8)
65 # print(data)
66 if not data:
67 break
68 _, n = struct.unpack('>BxxxL', data)
69 line = self.sock.recv(n)
70 output += line
71 if re.search(b"\x1b.+@.+[#|$] ", line):
72 break
73 except TimeoutError:
74 break
75 except socket.timeout:
76 break
77 # replace the very end \x1b.+@.+[#|$] into nothing (required the suffix)
78 # output = re.sub(b"\x1b.+@.+[#|$] $", b"", output)
79 return DummyOutput(0, output)
80
81 def execute_independent(self, command, *params):
82 # print("=== EXECUTING INDEPENDENT ===\n", command)

Callers 2

_judgeMethod · 0.45
get_answerMethod · 0.45

Calls 3

DummyOutputClass · 0.85
encodeMethod · 0.80
searchMethod · 0.80

Tested by

no test coverage detected