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

Class OSInteraction

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

Source from the content-addressed store, hash-verified

144
145
146class OSInteraction(Task):
147
148 def __init__(self,
149 data_config,
150 docker_config,
151 round_limit=8,
152 tools=None,
153 env_driver: str = 'docker',
154 env_options: Optional[dict] = None,
155 **kwargs):
156 super().__init__(**kwargs)
157 self.round_limit: int = round_limit
158 self.data_config = data_config
159 self.docker_config = docker_config
160 self.tools = tools
161 self.full_async = True
162 self.problem_configs: Dict[str, Dict[str, Any]] = {} # {index: CONFIG}
163
164 matches = []
165 for item in self.data_config["files"]:
166 path = item["problem_file"]
167 for file in glob.glob(path):
168 if file.endswith(".json") or file.endswith(".jsonl"):
169 matches.append(
170 {
171 "problem_file": file,
172 "script_dir": item["script_dir"],
173 "index_prefix": item["index_prefix"]
174 + os.path.basename(file)
175 .removesuffix(".json")
176 .removesuffix(".jsonl")
177 + "-",
178 }
179 )
180 self.data_config["files"] = matches
181
182 next_idx = 0
183 for item in self.data_config["files"]:
184 problem_file = item["problem_file"]
185 single_file_configs = self._load_configs(problem_file, item["script_dir"])
186 dict_configs = {}
187 for config in single_file_configs:
188 dict_configs[next_idx] = {
189 "file": problem_file,
190 "config": config,
191 "index": next_idx,
192 }
193 next_idx += 1
194 self.problem_configs.update(dict_configs)
195
196 logging.info(f"Initialized OSInteraction with {len(self.problem_configs)} problem configs")
197
198 self.env_delegation = OSEnvironmentDelegation(self.docker_config['localhost'])
199 self.env_controller = create_controller(env_driver, self.env_delegation, **env_options)
200 self.env_controller_background_task = None
201
202 def _load_configs(self, config_path, script_root_dir=".") -> List[JudgeConfig]:
203 def load_script(script_obj):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected