Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
refactor: Refactor S3 configuration structure and fix Python 3.9 compatibility issues (#73)
baojun-zhang3ffde5821e32
diff --git a/openviking/agfs_manager.py b/openviking/agfs_manager.pyindex 6e3d18123..66e96a746 100644--- a/openviking/agfs_manager.py+++ b/openviking/agfs_manager.py@@ -38,14 +38,19 @@ class AGFSManager:manager.start()# 2. S3 backend+ from openviking.utils.config.agfs_config import AGFSConfig, S3Config+config = AGFSConfig(path="./data",port=8080,backend="s3",- s3_bucket="my-bucket",- s3_region="us-east-1",- s3_access_key="your-access-key",- s3_secret_key="your-secret-key",+ s3=S3Config(+ bucket="my-bucket",+ region="us-east-1",+ access_key="your-access-key",+ secret_key="your-secret-key",+ endpoint="https://s3.amazonaws.com"+ ),log_level="debug")manager = AGFSManager(config=config)@@ -73,13 +78,13 @@ class AGFSManager:self.port = config.portself.log_level = config.log_levelself.backend = config.backend- self.s3_bucket = config.s3_bucket- self.s3_region = config.s3_region- self.s3_access_key = config.s3_access_key- self.s3_secret_key = config.s3_secret_key- self.s3_endpoint = config.s3_endpoint- self.s3_prefix = config.s3_prefix- self.s3_use_ssl = config.s3_use_ssl+ self.s3_bucket = config.s3.bucket+ self.s3_region = config.s3.region+ self.s3_access_key = config.s3.access_key+ self.s3_secret_key = config.s3.secret_key+ self.s3_endpoint = config.s3.endpoint+ self.s3_prefix = config.s3.prefix+ self.s3_use_ssl = config.s3.use_sslself.process: Optional[subprocess.Popen] = Noneself.config_file: Optional[Path] = Nonediff --git a/openviking/utils/config/agfs_config.py b/openviking/utils/config/agfs_config.pyindex 454b23552..f7b963eb5 100644--- a/openviking/utils/config/agfs_config.py+++ b/openviking/utils/config/agfs_config.py@@ -5,63 +5,88 @@ from typing import Optionalfrom pydantic import BaseModel, Field, model_validator-class AGFSConfig(BaseModel):- """Configuration for AGFS (Agent Global File System)."""-- path: str = Field(default="./data", description="AGFS data storage path")-- port: int = Field(default=8080, description="AGFS service port")-- log_level: str = Field(default="warn", description="AGFS log level")+class S3Config(BaseModel):+ """Configuration for S3 backend."""- url: Optional[str] = Field(- default="http://localhost:8080", description="AGFS service URL for service mode"- )+ bucket: Optional[str] = Field(default=None, description="S3 bucket name")- backend: str = Field(- default="local", description="AGFS storage backend: 'local' | 's3' | 'memory'"- )-- timeout: int = Field(default=10, description="AGFS request timeout (seconds)")-- retry_times: int = Field(default=3, description="AGFS retry times on failure")-- # S3 backend configuration- # These settings are used when backend is set to 's3'.- # AGFS will act as a gateway to the specified S3 bucket.- s3_bucket: Optional[str] = Field(default=None, description="S3 bucket name")-- s3_region: Optional[str] = Field(+ region: Optional[str] = Field(default=None,description="AWS region where the bucket is located (e.g., us-east-1, cn-beijing)",)- s3_access_key: Optional[str] = Field(+ access_key: Optional[str] = Field(default=None,description="S3 access key ID. If not provided, AGFS may attempt to use environment variables or IAM roles.",)- s3_secret_key: Optional[str] = Field(+ secret_key: Optional[str] = Field(default=None,description="S3 secret access key corresponding to the access key ID.",)- s3_endpoint: Optional[str] = Field(+ endpoint: Optional[str] = Field(default=None,description="Custom S3 endpoint URL. Required for S3-compatible services like MinIO or LocalStack. ""Leave empty for standard AWS S3.",)- s3_prefix: Optional[str] = Field(+ prefix: Optional[str] = Field(default="",description="Optional key prefix for namespace isolation. All objects will be stored under this prefix.",)- s3_use_ssl: bool = Field(+ use_ssl: bool = Field(default=True,description="Enable/Disable SSL (HTTPS) for S3 connections. Set to False for local testing without HTTPS.",)+ def validate_config(self):+ """Validate S3 configuration completeness"""+ missing = []+ if not self.bucket:+ missing.append("bucket")+ if not self.endpoint:+ missing.append("endpoint")+ if not self.region:+ missing.append("region")+ if not self.access_key:+ missing.append("access_key")+ if not self.secret_key:+ missing.append("secret_key")++ if missing:+ raise ValueError(f"S3 backend requires the following fields: {', '.join(missing)}")++ return self+++class AGFSConfig(BaseModel):+ """Configuration for AGFS (Agent Global File System)."""++ path: str = Field(default="./data", description="AGFS data storage path")++ port: int = Field(default=8080, description="AGFS service port")++ log_level: str = Field(default="warn", description="AGFS log level")++ url: Optional[str] = Field(+ default="http://localhost:8080", description="AGFS service URL for service mode"+ )++ backend: str = Field(+ default="local", description="AGFS storage backend: 'local' | 's3' | 'memory'"+ )++ timeout: int = Field(default=10, description="AGFS request timeout (seconds)")++ retry_times: int = Field(default=3, description="AGFS retry times on failure")++ # S3 backend configuration+ # These settings are used when backend is set to 's3'.+ # AGFS will act as a gateway to the specified S3 bucket.+ s3: S3Config = Field(default_factory=lambda: S3Config(), description="S3 backend configuration")+@model_validator(mode="after")def validate_config(self):"""Validate configuration completeness and consistency"""@@ -75,21 +100,7 @@ class AGFSConfig(BaseModel):raise ValueError("AGFS local backend requires 'path' to be set")elif self.backend == "s3":- missing = []- if not self.s3_bucket:- missing.append("s3_bucket")- if not self.s3_endpoint:- missing.append("s3_endpoint")- if not self.s3_region:- missing.append("s3_region")- if not self.s3_access_key:- missing.append("s3_access_key")- if not self.s3_secret_key:- missing.append("s3_secret_key")-- if missing:- raise ValueError(- f"AGFS S3 backend requires the following fields: {', '.join(missing)}"- )+ # Validate S3 configuration+ self.s3.validate_config()return selfdiff --git a/tests/misc/test_config_validation.py b/tests/misc/test_config_validation.pyindex 35e50b0b1..0e5686e7e 100644--- a/tests/misc/test_config_validation.py+++ b/tests/misc/test_config_validation.py@@ -5,7 +5,7 @@import sys-from openviking.utils.config.agfs_config import AGFSConfig+from openviking.utils.config.agfs_config import AGFSConfig, S3Configfrom openviking.utils.config.embedding_config import EmbeddingConfig, EmbeddingModelConfigfrom openviking.utils.config.vectordb_config import VectorDBBackendConfigfrom openviking.utils.config.vlm_config import VLMConfig@@ -46,10 +46,13 @@ def test_agfs_validation():try:config = AGFSConfig(backend="s3",- s3_bucket="my-bucket",- s3_region="us-west-1",- s3_access_key="fake-access-key-for-testing",- s3_secret_key="fake-secret-key-for-testing-12345",+ s3=S3Config(+ bucket="my-bucket",+ region="us-west-1",+ access_key="fake-access-key-for-testing",+ secret_key="fake-secret-key-for-testing-12345",+ endpoint="https://s3.amazonaws.com"+ ),)print(" Pass")except ValueError as e: