Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

feat: generate a framework of config (#600)

Xiaogang Zhouf869c0a769ab
diff --git a/bot/vikingbot/config/loader.py b/bot/vikingbot/config/loader.py
index 343ce4190..74b6a6f47 100644
--- a/bot/vikingbot/config/loader.py
+++ b/bot/vikingbot/config/loader.py
@@ -53,7 +53,7 @@ def ensure_config(config_path: Path | None = None) -> Config:
# Create default config with empty bot section
default_config = Config()
- save_config(default_config, config_path)
+ save_config(default_config, config_path, include_defaults=True)
logger.info(f"[green]✓[/green] Created default config at {config_path}")
config = load_config()
@@ -149,13 +149,16 @@ def _merge_ov_server_config(bot_data: dict, ov_data: dict) -> None:
bot_data["mode"] = "local"
-def save_config(config: Config, config_path: Path | None = None) -> None:
+def save_config(
+ config: Config, config_path: Path | None = None, include_defaults: bool = False
+) -> None:
"""
Save configuration to ov.conf's bot field, preserving other sections.
Args:
config: Configuration to save.
config_path: Optional path to ov.conf file. Uses default if not provided.
+ include_defaults: Whether to include default values in the saved config.
"""
path = config_path or get_config_path()
path.parent.mkdir(parents=True, exist_ok=True)
@@ -170,7 +173,7 @@ def save_config(config: Config, config_path: Path | None = None) -> None:
pass
# Update bot section - only save fields that were explicitly set
- bot_data = config.model_dump(exclude_unset=True)
+ bot_data = config.model_dump(exclude_unset=not include_defaults)
if bot_data:
full_data["bot"] = convert_to_camel(bot_data)
else:
@@ -212,4 +215,4 @@ def camel_to_snake(name: str) -> str:
def snake_to_camel(name: str) -> str:
"""Convert snake_case to camelCase."""
components = name.split("_")
- return components[0] + "".join(x.title() for x in components[1:])
+ return components[0] + "".join(x.title() for x in components[1:])
\ No newline at end of file
diff --git a/bot/vikingbot/config/schema.py b/bot/vikingbot/config/schema.py
index 4fc4676e5..a29a625be 100644
--- a/bot/vikingbot/config/schema.py
+++ b/bot/vikingbot/config/schema.py
@@ -627,7 +627,8 @@ class Config(BaseSettings):
@property
def bot_data_path(self) -> Path:
"""Get expanded bot data path: {storage_workspace}/bot."""
- return Path(self.storage_workspace).expanduser() / "bot"
+ workspace = self.storage_workspace or "~/.openviking/data"
+ return Path(workspace).expanduser() / "bot"
@property
def workspace_path(self) -> Path:
@@ -733,4 +734,4 @@ class SessionKey(BaseModel):
file_name_split = safe_name.split("__")
return SessionKey(
type=file_name_split[0], channel_id=file_name_split[1], chat_id=file_name_split[2]
- )
+ )
\ No newline at end of file