mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-29 00:38:33 +00:00
Some checks failed
CI and Release / Docker / Build and test / amd64 (push) Has been cancelled
CI and Release / Docker / Build and test / arm64 (push) Has been cancelled
Security / CodeQL / Analyze python (push) Has been cancelled
CI / Python quality / Pre-commit (push) Has been cancelled
CI / Python tests / Unit Tests - py3.12 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.13 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.14 (push) Has been cancelled
CI / Python packages / Build and verify distributions (push) Has been cancelled
CI / Python quality / GitHub Actions (push) Has been cancelled
CI / Python tests / Hermes embedded - ubuntu-latest (push) Has been cancelled
CI / Python tests / Hermes embedded - windows-latest (push) Has been cancelled
CI / Python tests / Unit Tests - py3.11 (push) Has been cancelled
CI / ReMe Studio / Studio checks (push) Has been cancelled
Deploy / Documentation / Build documentation (push) Has been cancelled
CI / Windows / CLI smoke - py3.11 (push) Has been cancelled
Security / CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI and Release / Docker / Publish multi-platform tags (push) Has been cancelled
Deploy / Documentation / deploy (push) Has been cancelled
* refactor(core): reorganize the ReMe runtime and shared helpers * test(status): import the base component from its canonical module * test: remove redundant unit checks * refactor(core): use canonical runtime imports and shared CLI discovery Restore evolve behavior to the base branch and update its imports. Use Application as the runtime entry point and encode SSE in the HTTP service. * fix(cli): honor caller config when service replay is incomplete Use partial startup overrides for port probes and resolve named configs before requesting the service process working directory.
106 lines
5.5 KiB
Python
106 lines
5.5 KiB
Python
"""Application configuration models."""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
from pathlib import PurePosixPath, PureWindowsPath
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
|
|
|
from ..enumeration import component_type_name
|
|
from .event import Event
|
|
|
|
|
|
class ComponentConfig(BaseModel):
|
|
"""Base config for a component; extra fields allowed for backend-specific options."""
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
backend: str = Field(default="", description="Backend implementation class name")
|
|
|
|
|
|
class JobConfig(ComponentConfig):
|
|
"""Config for a job — an ordered sequence of step components. Keyed by name in ApplicationConfig.jobs."""
|
|
|
|
description: str = Field(default="", description="Human-readable description")
|
|
parameters: dict = Field(default_factory=dict, description="Job-level parameters")
|
|
steps: list[ComponentConfig] = Field(default_factory=list, description="Ordered step configs")
|
|
init_steps: list[ComponentConfig] = Field(
|
|
default_factory=list,
|
|
description="Cron-only steps run before entering the schedule; must be idempotent for supervisor retries",
|
|
)
|
|
enable_serve: bool = Field(default=True, description="Whether to expose this job through the service layer")
|
|
enabled: bool = Field(default=True, description="Whether to start, serve, and allow execution of this job")
|
|
track_execution: bool | None = Field(
|
|
default=None,
|
|
description="Record execution and step status in memory; defaults on for background/cron, off otherwise",
|
|
)
|
|
|
|
|
|
class ApplicationConfig(BaseModel):
|
|
"""Root config for the ReMe application."""
|
|
|
|
app_name: str = Field(default=os.getenv("APP_NAME", "ReMe"), description="Application display name")
|
|
environment: dict[str, str] = Field(
|
|
default_factory=dict,
|
|
description="Environment variables loaded once at startup and passed to agent subprocesses",
|
|
)
|
|
workspace_dir: str = Field(
|
|
default=".reme",
|
|
description="Workspace root directory for runtime files",
|
|
validate_default=True,
|
|
)
|
|
metadata_dir: str = Field(default="metadata", description="Subdirectory for ReMe persistent state")
|
|
session_dir: str = Field(default="session", description="Subdirectory for persisted agent sessions")
|
|
# dialog_dir was removed; standard transcripts are always derived as ``{session_dir}/dialog``.
|
|
mem_session_dir: str = Field(default="mem_session", description="Subdirectory for persisted agent sessions")
|
|
resource_dir: str = Field(default="resource", description="Subdirectory for external assets")
|
|
reme_agent_dir: str = Field(default="reme_agents", description="Subdirectory for application-owned agents")
|
|
daily_dir: str = Field(default="daily", description="Subdirectory for daily memory")
|
|
digest_dir: str = Field(default="digest", description="Subdirectory for digest memory")
|
|
notebook_dir: str = Field(default="notebook", description="Workspace-relative subdirectory for Todo and Idea files")
|
|
enable_logo: bool = Field(default=True, description="Show ASCII logo on startup")
|
|
timezone: str | None = Field(default="Asia/Shanghai", description="IANA timezone; None uses local time")
|
|
language: str = Field(default="", description="Default language for LLM interactions")
|
|
log_to_console: bool = Field(default=True, description="Log to console")
|
|
log_to_file: bool = Field(default=True, description="Log to file")
|
|
mcp_servers: dict[str, dict] = Field(default_factory=dict, description="MCP server configs by name")
|
|
plugins: list[str] = Field(default_factory=list, description="Installed plugins enabled for this app")
|
|
service: ComponentConfig = Field(default_factory=ComponentConfig, description="Service endpoint config")
|
|
jobs: dict[str, JobConfig] = Field(default_factory=dict, description="Job definitions keyed by job name")
|
|
thread_pool_max_workers: int = Field(default=0, description="Max worker threads; 0 to disable")
|
|
job_history_limit: int = Field(default=100, ge=0, description="Completed executions retained per job in memory")
|
|
components: dict[str, dict[str, ComponentConfig]] = Field(
|
|
default_factory=dict,
|
|
description="Component registry keyed by type then name",
|
|
)
|
|
|
|
@field_validator("components", mode="before")
|
|
@classmethod
|
|
def normalize_component_types(cls, value):
|
|
"""Canonicalize built-in enums and allow plugin-defined component type names."""
|
|
if value is None:
|
|
return {}
|
|
if not isinstance(value, dict):
|
|
return value
|
|
return {component_type_name(component_type): group for component_type, group in value.items()}
|
|
|
|
@field_validator("workspace_dir", mode="before")
|
|
@classmethod
|
|
def normalize_workspace_dir(cls, value) -> str:
|
|
"""Expand home-relative paths once so every component sees the same absolute workspace."""
|
|
return str(Path(value).expanduser().resolve(strict=False))
|
|
|
|
@field_validator("session_dir")
|
|
@classmethod
|
|
def validate_session_dir(cls, value: str) -> str:
|
|
"""Keep standard session storage inside the configured workspace."""
|
|
path = value.strip()
|
|
if PurePosixPath(path.replace("\\", "/")).is_absolute() or PureWindowsPath(path).anchor:
|
|
raise ValueError("session_dir must be a workspace-relative path")
|
|
return value
|
|
|
|
@field_validator("reme_agent_dir", "notebook_dir")
|
|
@classmethod
|
|
def validate_workspace_subdirectory(cls, value: str) -> str:
|
|
"""Require a normalized workspace-relative subdirectory."""
|
|
return Event.validate_paths([value])[0]
|