bug fix
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
from dataclasses import dataclass, field, is_dataclass
|
import os
|
||||||
|
from dataclasses import dataclass
|
||||||
from typing import Any
|
from typing import Any
|
||||||
import tyro
|
|
||||||
import os.path as osp
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
from lang_agent.config import InstantiateConfig
|
||||||
|
|
||||||
|
|
||||||
class BaseFilesystemBackend(ABC):
|
class BaseFilesystemBackend(ABC):
|
||||||
@@ -25,4 +27,25 @@ class BaseFilesystemBackend(ABC):
|
|||||||
if hasattr(self.config, "rt_skills_dir"):
|
if hasattr(self.config, "rt_skills_dir"):
|
||||||
return {"skills" : [self.config.rt_skills_dir]}
|
return {"skills" : [self.config.rt_skills_dir]}
|
||||||
else:
|
else:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class FilesystemBackendConfig(InstantiateConfig):
|
||||||
|
"""
|
||||||
|
Shared filesystem backend config behavior.
|
||||||
|
If subclasses define these fields, this hook ensures they exist:
|
||||||
|
- skills_dir
|
||||||
|
- workspace_dir
|
||||||
|
"""
|
||||||
|
|
||||||
|
def _ensure_dir_if_present(self, attr_name: str) -> None:
|
||||||
|
path = getattr(self, attr_name, None)
|
||||||
|
if not isinstance(path, str) or not path.strip():
|
||||||
|
return
|
||||||
|
os.makedirs(path, exist_ok=True)
|
||||||
|
logger.info(f"Ensured {attr_name} exists: {path}")
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
self._ensure_dir_if_present("skills_dir")
|
||||||
|
self._ensure_dir_if_present("workspace_dir")
|
||||||
@@ -8,13 +8,12 @@ from loguru import logger
|
|||||||
from daytona import Daytona, DaytonaConfig, FileUpload
|
from daytona import Daytona, DaytonaConfig, FileUpload
|
||||||
from langchain_daytona import DaytonaSandbox
|
from langchain_daytona import DaytonaSandbox
|
||||||
|
|
||||||
from lang_agent.config import InstantiateConfig
|
from lang_agent.fs_bkends.base import BaseFilesystemBackend, FilesystemBackendConfig
|
||||||
from lang_agent.fs_bkends import BaseFilesystemBackend
|
|
||||||
|
|
||||||
|
|
||||||
@tyro.conf.configure(tyro.conf.SuppressFixed)
|
@tyro.conf.configure(tyro.conf.SuppressFixed)
|
||||||
@dataclass
|
@dataclass
|
||||||
class DaytonaSandboxConfig(InstantiateConfig):
|
class DaytonaSandboxConfig(FilesystemBackendConfig):
|
||||||
_target: Type = field(default_factory=lambda: DaytonaSandboxBk)
|
_target: Type = field(default_factory=lambda: DaytonaSandboxBk)
|
||||||
|
|
||||||
api_key: Optional[str] = None
|
api_key: Optional[str] = None
|
||||||
@@ -27,6 +26,7 @@ class DaytonaSandboxConfig(InstantiateConfig):
|
|||||||
"""runtime skills path inside the sandbox (auto-set from sandbox workdir)"""
|
"""runtime skills path inside the sandbox (auto-set from sandbox workdir)"""
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
|
super().__post_init__()
|
||||||
if self.api_key is None:
|
if self.api_key is None:
|
||||||
self.api_key = os.environ.get("DAYTONA_API_KEY")
|
self.api_key = os.environ.get("DAYTONA_API_KEY")
|
||||||
if self.api_key is None:
|
if self.api_key is None:
|
||||||
|
|||||||
@@ -1,21 +1,16 @@
|
|||||||
from dataclasses import dataclass, field, is_dataclass
|
from dataclasses import dataclass, field
|
||||||
from typing import Type, TypedDict, Literal, Dict, List, Tuple, Optional
|
from typing import Type
|
||||||
import tyro
|
import tyro
|
||||||
import os.path as osp
|
|
||||||
from abc import ABC, abstractmethod
|
|
||||||
import glob
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from deepagents.backends.utils import create_file_data
|
|
||||||
from deepagents.backends import LocalShellBackend
|
from deepagents.backends import LocalShellBackend
|
||||||
|
|
||||||
from lang_agent.config import InstantiateConfig
|
from lang_agent.fs_bkends.base import BaseFilesystemBackend, FilesystemBackendConfig
|
||||||
from lang_agent.fs_bkends import BaseFilesystemBackend
|
|
||||||
|
|
||||||
|
|
||||||
@tyro.conf.configure(tyro.conf.SuppressFixed)
|
@tyro.conf.configure(tyro.conf.SuppressFixed)
|
||||||
@dataclass
|
@dataclass
|
||||||
class LocalShellConfig(InstantiateConfig):
|
class LocalShellConfig(FilesystemBackendConfig):
|
||||||
_target:Type = field(default_factory=lambda:LocalShell)
|
_target:Type = field(default_factory=lambda:LocalShell)
|
||||||
|
|
||||||
workspace_dir:str = "./workspace"
|
workspace_dir:str = "./workspace"
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
from dataclasses import dataclass, field, is_dataclass
|
from dataclasses import dataclass, field
|
||||||
from typing import Type, TypedDict, Literal, Dict, List, Tuple, Optional
|
from typing import Type
|
||||||
import tyro
|
import tyro
|
||||||
import os.path as osp
|
import os.path as osp
|
||||||
from abc import ABC, abstractmethod
|
|
||||||
import glob
|
import glob
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from deepagents.backends.utils import create_file_data
|
from deepagents.backends.utils import create_file_data
|
||||||
from deepagents.backends import StateBackend
|
from deepagents.backends import StateBackend
|
||||||
|
|
||||||
from lang_agent.config import InstantiateConfig
|
from lang_agent.fs_bkends.base import BaseFilesystemBackend, FilesystemBackendConfig
|
||||||
from lang_agent.fs_bkends import BaseFilesystemBackend
|
|
||||||
|
|
||||||
def read_as_utf8(file_path:str):
|
def read_as_utf8(file_path:str):
|
||||||
with open(file_path, "r", encoding="utf-8") as f:
|
with open(file_path, "r", encoding="utf-8") as f:
|
||||||
@@ -31,7 +29,7 @@ def build_skill_fs_dict(skill_dir:str, virt_path:str="/skills"):
|
|||||||
|
|
||||||
@tyro.conf.configure(tyro.conf.SuppressFixed)
|
@tyro.conf.configure(tyro.conf.SuppressFixed)
|
||||||
@dataclass
|
@dataclass
|
||||||
class StateBkConfig(InstantiateConfig):
|
class StateBkConfig(FilesystemBackendConfig):
|
||||||
_target:Type = field(default_factory=lambda:StateBk)
|
_target:Type = field(default_factory=lambda:StateBk)
|
||||||
|
|
||||||
skills_dir:str = "./assets/skills"
|
skills_dir:str = "./assets/skills"
|
||||||
@@ -40,10 +38,6 @@ class StateBkConfig(InstantiateConfig):
|
|||||||
rt_skills_dir:str = "/skills"
|
rt_skills_dir:str = "/skills"
|
||||||
"""path to directory with skills in runtime directory"""
|
"""path to directory with skills in runtime directory"""
|
||||||
|
|
||||||
def __post_init__(self):
|
|
||||||
err_msg = f"{self.skills_dir} does not exist"
|
|
||||||
assert osp.exists(self.skills_dir), err_msg
|
|
||||||
|
|
||||||
|
|
||||||
class StateBk(BaseFilesystemBackend):
|
class StateBk(BaseFilesystemBackend):
|
||||||
def __init__(self, config:StateBkConfig):
|
def __init__(self, config:StateBkConfig):
|
||||||
|
|||||||
Reference in New Issue
Block a user