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

Method execute

src/server/tasks/os_interaction/task.py:53–87  ·  view source on GitHub ↗

异步执行命令

(self, command: str)

Source from the content-addressed store, hash-verified

51 await self.controller.end_session(self.session_id)
52
53 async def execute(self, command: str):
54 """异步执行命令"""
55
56 class DummyOutput:
57 output: bytes
58 exit_code: int
59
60 def __init__(self, code, o):
61 self.output = o
62 self.exit_code = code
63
64 # call environment controller to renew session
65 await self.controller.renew_session(self.session_id)
66
67 if not isinstance(command, str):
68 logging.warning("Invalid command type, expected string")
69 return DummyOutput(-1, b"")
70
71 output = await self.controller.execute_shell(self.container_id, command)
72
73 # Clean up the output by removing terminal control sequences, removes escape sequences starting with
74 # ESC (0x1b), followed by...
75 # ... any characters, an '@' character, any characters, ending with '#' or '$'
76 output = re.sub(b"\x1b.+@.+[#|$] ", b'', output)
77 # ... '[' and any combination of digits and semicolons, ending with a letter (a-z or A-Z)
78 output = re.sub(b'\x1b\\[[0-9;]*[a-zA-Z]', b'', output)
79 # ... ']' and any digits, a semicolon, any characters except BEL (0x07), and ending with BEL
80 output = re.sub(b'\x1b][0-9]*;[^\x07]*\x07', b'', output)
81 # ... '[?2004' and either 'h' or 'l'
82 output = re.sub(b'\x1b\[\?2004[hl]', b'', output)
83
84 # Remove BEL characters (0x07)
85 output = re.sub(b'\x07', b'', output)
86
87 return DummyOutput(0, output)
88
89 async def execute_independent(self, command, *params) -> Tuple[int, bytes, bytes]:
90 """异步执行独立命令"""

Callers 2

_execute_bash_commandMethod · 0.45

Calls 1

DummyOutputClass · 0.85

Tested by

no test coverage detected