Spaces:
Running
Running
Sync Bash output handling
Browse filesFiles changed (3)
1v0.0.471v0.0.48
1323 unmodified lines13241325132613271328132913301331133213331334133513361323 unmodified lines)def execute_tool_item(item: dict[str, Any]) -> tuple[dict[str, Any], Any]:result = self.custom_call_tool(str(item["tool_name"]),item["tool_arguments"],workspace_root=resolved_workspace_root,runtime_deadline=runtime_deadline,model_name=self.model,)return item, resultfor batch_indexes in tool_execution_batches([str(item["tool_name"]) for item in tool_call_items]):1323 unmodified lines132413251326132713281329133013311332133313341335133613371338133913401323 unmodified lines)def execute_tool_item(item: dict[str, Any]) -> tuple[dict[str, Any], Any]:tool_name = str(item["tool_name"])try:result = self.custom_call_tool(tool_name,item["tool_arguments"],workspace_root=resolved_workspace_root,runtime_deadline=runtime_deadline,model_name=self.model,)except Exception as exc:result = f"[{tool_name}] Tool execution error: {type(exc).__name__}: {exc}"return item, resultfor batch_indexes in tool_execution_batches([str(item["tool_name"]) for item in tool_call_items]):
30 unmodified lines31323334353663 unmodified lines10010110210310410572 unmodified lines1781791801811821831845 unmodified lines19019119219319419519619730 unmodified linesDEFAULT_YIELD_MS = 200REPEAT_COLLAPSE_THRESHOLD = 3def _default_shell() -> str:return shutil.which("bash") or "/bin/bash"63 unmodified linesreturn compressed[:keep] + suffixclass Bash(ToolBase):name = "Bash"description = (72 unmodified linescommand,shell=True,capture_output=True,text=True,timeout=effective_timeout,cwd=str(cwd),env=sanitized_subprocess_env(base_root=base_root),5 unmodified linesreturn f"[Bash] Error executing command: {exc}"parts = [f"exit_code: {proc.returncode}"]stdout = _bounded_output(proc.stdout, max_output_chars=max_output_chars)stderr = _bounded_output(proc.stderr, max_output_chars=max_output_chars)if stdout:parts.append(f"stdout:\n{stdout}")if stderr:30 unmodified lines3132333435363763 unmodified lines10110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315472 unmodified lines2272282292302312322335 unmodified lines23924024124224324424524630 unmodified linesDEFAULT_YIELD_MS = 200REPEAT_COLLAPSE_THRESHOLD = 3def _default_shell() -> str:return shutil.which("bash") or "/bin/bash"63 unmodified linesreturn compressed[:keep] + suffixdef _looks_binary_output(data: bytes) -> bool:if not data:return Falsesample = data[:4096]if b"\x00" in sample:return Trueallowed_controls = {9, 10, 12, 13}control_count = sum(1 for byte in sample if byte < 32 and byte not in allowed_controls)return control_count / max(len(sample), 1) > 0.05def _truncate_output_bytes(data: bytes, *, max_output_chars: int) -> tuple[bytes, bool, int]:max_output_bytes = max(1, int(max_output_chars))if len(data) <= max_output_bytes:return data, False, 0omitted = len(data) - max_output_bytessuffix = f"\n[output truncated before decoding: omitted {omitted} bytes]\n".encode("utf-8")keep = max(0, max_output_bytes - len(suffix))return data[:keep] + suffix, True, omitteddef _safe_process_output(data: Union[str, bytes, None], *, max_output_chars: int = DEFAULT_OUTPUT_CHARS) -> str:if data is None or data == "":return ""if isinstance(data, str):return _bounded_output(data, max_output_chars=max_output_chars)if not data:return ""if _looks_binary_output(data):note = (f"[binary output omitted: {len(data)} bytes. ""Use file or a format-aware reader such as openpyxl/scipy.io.loadmat for binary files.]")if len(data) > max_output_chars:note += f"\n[output truncated before decoding: omitted {len(data) - max_output_chars} bytes]"return notebounded, _, _ = _truncate_output_bytes(data, max_output_chars=max_output_chars)try:decoded = bounded.decode("utf-8")prefix = ""except UnicodeDecodeError:decoded = bounded.decode("utf-8", errors="replace")prefix = "[non-UTF-8 bytes decoded with replacement characters]\n"return _bounded_output(prefix + decoded, max_output_chars=max_output_chars)class Bash(ToolBase):name = "Bash"description = (72 unmodified linescommand,shell=True,capture_output=True,text=False,timeout=effective_timeout,cwd=str(cwd),env=sanitized_subprocess_env(base_root=base_root),5 unmodified linesreturn f"[Bash] Error executing command: {exc}"parts = [f"exit_code: {proc.returncode}"]stdout = _safe_process_output(proc.stdout, max_output_chars=max_output_chars)stderr = _safe_process_output(proc.stderr, max_output_chars=max_output_chars)if stdout:parts.append(f"stdout:\n{stdout}")if stderr:
VERSION+1-1
agent_base/react_agent.py+11-7
agent_base/tools/tool_runtime.py+52-3