
import os
import shutil
import subprocess
from typing import List, Callable, Union, Optional, Any, Dict
from collections import defaultdict
from pydantic import BaseModel

from gwenflow.agents.agent import Agent


class AgentCodeExecutor(Agent):


    def _validate_docker_installation(self) -> None:
        """Check if Docker is installed and running."""
        if not shutil.which("docker"):
            raise RuntimeError(
                f"Docker is not installed. Please install Docker to use code execution with agent: {self.role}"
            )

        try:
            subprocess.run(
                ["docker", "info"],
                check=True,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
            )
        except subprocess.CalledProcessError:
            raise RuntimeError(
                f"Docker is not running. Please start Docker to use code execution with agent: {self.role}"
            )