fix: fix bug
This commit is contained in:
parent
4df605e8db
commit
1204d841ae
@ -6,6 +6,7 @@ from pydantic import BaseModel, Field, model_validator
|
|||||||
|
|
||||||
from app.llm import LLM
|
from app.llm import LLM
|
||||||
from app.logger import logger
|
from app.logger import logger
|
||||||
|
from app.sandbox.client import SANDBOX_CLIENT
|
||||||
from app.schema import ROLE_TYPE, AgentState, Memory, Message
|
from app.schema import ROLE_TYPE, AgentState, Memory, Message
|
||||||
|
|
||||||
|
|
||||||
@ -149,7 +150,7 @@ class BaseAgent(BaseModel, ABC):
|
|||||||
self.current_step = 0
|
self.current_step = 0
|
||||||
self.state = AgentState.IDLE
|
self.state = AgentState.IDLE
|
||||||
results.append(f"Terminated: Reached max steps ({self.max_steps})")
|
results.append(f"Terminated: Reached max steps ({self.max_steps})")
|
||||||
|
await SANDBOX_CLIENT.cleanup()
|
||||||
return "\n".join(results) if results else "No steps executed"
|
return "\n".join(results) if results else "No steps executed"
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
@ -210,18 +210,17 @@ class Config:
|
|||||||
def llm(self) -> Dict[str, LLMSettings]:
|
def llm(self) -> Dict[str, LLMSettings]:
|
||||||
return self._config.llm
|
return self._config.llm
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sandbox(self) -> SandboxSettings:
|
||||||
|
return self._config.sandbox
|
||||||
|
|
||||||
def sandbox(self) -> SandboxSettings:
|
@property
|
||||||
return self._config.sandbox
|
def browser_config(self) -> Optional[BrowserSettings]:
|
||||||
|
return self._config.browser_config
|
||||||
|
|
||||||
|
@property
|
||||||
def browser_config(self) -> Optional[BrowserSettings]:
|
def search_config(self) -> Optional[SearchSettings]:
|
||||||
return self._config.browser_config
|
return self._config.search_config
|
||||||
|
|
||||||
|
|
||||||
@property
|
|
||||||
def search_config(self) -> Optional[SearchSettings]:
|
|
||||||
return self._config.search_config
|
|
||||||
|
|
||||||
|
|
||||||
config = Config()
|
config = Config()
|
||||||
|
@ -189,7 +189,7 @@ class LocalSandboxClient(BaseSandboxClient):
|
|||||||
self.sandbox = None
|
self.sandbox = None
|
||||||
|
|
||||||
|
|
||||||
async def create_sandbox_client() -> LocalSandboxClient:
|
def create_sandbox_client() -> LocalSandboxClient:
|
||||||
"""Creates a sandbox client.
|
"""Creates a sandbox client.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
@ -100,7 +100,6 @@ class StrReplaceEditor(BaseTool):
|
|||||||
}
|
}
|
||||||
_file_history: DefaultDict[PathLike, List[str]] = defaultdict(list)
|
_file_history: DefaultDict[PathLike, List[str]] = defaultdict(list)
|
||||||
_local_operator: LocalFileOperator = LocalFileOperator()
|
_local_operator: LocalFileOperator = LocalFileOperator()
|
||||||
# todo: Sandbox resources need to be destroyed at the appropriate time.
|
|
||||||
_sandbox_operator: SandboxFileOperator = SandboxFileOperator()
|
_sandbox_operator: SandboxFileOperator = SandboxFileOperator()
|
||||||
|
|
||||||
# def _get_operator(self, use_sandbox: bool) -> FileOperator:
|
# def _get_operator(self, use_sandbox: bool) -> FileOperator:
|
||||||
@ -129,7 +128,7 @@ class StrReplaceEditor(BaseTool):
|
|||||||
operator = self._get_operator()
|
operator = self._get_operator()
|
||||||
|
|
||||||
# Validate path and command combination
|
# Validate path and command combination
|
||||||
await self.validate_path(command, path, operator)
|
await self.validate_path(command, Path(path), operator)
|
||||||
|
|
||||||
# Execute the appropriate command
|
# Execute the appropriate command
|
||||||
if command == "view":
|
if command == "view":
|
||||||
@ -164,14 +163,12 @@ class StrReplaceEditor(BaseTool):
|
|||||||
|
|
||||||
return str(result)
|
return str(result)
|
||||||
|
|
||||||
# <<<<<<< HEAD
|
|
||||||
async def validate_path(
|
async def validate_path(
|
||||||
self, command: str, path: Path, operator: FileOperator
|
self, command: str, path: Path, operator: FileOperator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Validate path and command combination based on execution environment."""
|
"""Validate path and command combination based on execution environment."""
|
||||||
# Check if path is absolute
|
# Check if path is absolute
|
||||||
if not path.is_absolute():
|
if not path.is_absolute():
|
||||||
# suggested_path = f"/{path}"
|
|
||||||
raise ToolError(f"The path {path} is not an absolute path")
|
raise ToolError(f"The path {path} is not an absolute path")
|
||||||
|
|
||||||
# Only check if path exists for non-create commands
|
# Only check if path exists for non-create commands
|
||||||
@ -184,27 +181,6 @@ class StrReplaceEditor(BaseTool):
|
|||||||
# Check if path is a directory
|
# Check if path is a directory
|
||||||
is_dir = await operator.is_directory(path)
|
is_dir = await operator.is_directory(path)
|
||||||
if is_dir and command != "view":
|
if is_dir and command != "view":
|
||||||
# =======
|
|
||||||
# def validate_path(self, command: str, path: Path):
|
|
||||||
# """
|
|
||||||
# Check that the path/command combination is valid.
|
|
||||||
# """
|
|
||||||
# # Check if its an absolute path
|
|
||||||
# if not path.is_absolute():
|
|
||||||
# raise ToolError(f"The path {path} is not an absolute path")
|
|
||||||
# # Check if path exists
|
|
||||||
# if not path.exists() and command != "create":
|
|
||||||
# raise ToolError(
|
|
||||||
# f"The path {path} does not exist. Please provide a valid path."
|
|
||||||
# )
|
|
||||||
# if path.exists() and command == "create":
|
|
||||||
# raise ToolError(
|
|
||||||
# f"File already exists at: {path}. Cannot overwrite files using command `create`."
|
|
||||||
# )
|
|
||||||
# # Check if the path points to a directory
|
|
||||||
# if path.is_dir():
|
|
||||||
# if command != "view":
|
|
||||||
# >>>>>>> upstream/main
|
|
||||||
raise ToolError(
|
raise ToolError(
|
||||||
f"The path {path} is a directory and only the `view` command can be used on directories"
|
f"The path {path} is a directory and only the `view` command can be used on directories"
|
||||||
)
|
)
|
||||||
|
@ -69,7 +69,7 @@ temperature = 0.0 # Controls randomness for vision mod
|
|||||||
## Sandbox configuration
|
## Sandbox configuration
|
||||||
#[sandbox]
|
#[sandbox]
|
||||||
#use_sandbox = false
|
#use_sandbox = false
|
||||||
#image = "python:3.10-slim"
|
#image = "python:3.12-slim"
|
||||||
#work_dir = "/workspace"
|
#work_dir = "/workspace"
|
||||||
#memory_limit = "1g" # 512m
|
#memory_limit = "1g" # 512m
|
||||||
#cpu_limit = 2.0
|
#cpu_limit = 2.0
|
||||||
|
@ -12,7 +12,7 @@ from app.sandbox.client import LocalSandboxClient, create_sandbox_client
|
|||||||
@pytest_asyncio.fixture(scope="function")
|
@pytest_asyncio.fixture(scope="function")
|
||||||
async def local_client() -> AsyncGenerator[LocalSandboxClient, None]:
|
async def local_client() -> AsyncGenerator[LocalSandboxClient, None]:
|
||||||
"""Creates a local sandbox client for testing."""
|
"""Creates a local sandbox client for testing."""
|
||||||
client = await create_sandbox_client()
|
client = create_sandbox_client()
|
||||||
try:
|
try:
|
||||||
yield client
|
yield client
|
||||||
finally:
|
finally:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user