-
Notifications
You must be signed in to change notification settings - Fork 133
Add runtime configuration API, graceful startup, and client SDK #993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
22ebb3f to
1492646
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds runtime resource configuration capabilities to the MemMachine server, enabling dynamic management of embedders, language models, rerankers, and memory configurations without requiring server restarts.
Changes:
- Introduces REST API endpoints for runtime configuration management
- Implements configuration persistence to YAML files
- Adds error tracking and retry mechanisms for failed resource initialization
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/memmachine/common/api/config_spec.py | Defines API request/response models for configuration operations |
| src/memmachine/common/api/doc.py | Adds documentation strings for configuration API endpoints |
| src/memmachine/common/configuration/init.py | Adds config file path tracking and save() method to Configuration |
| src/memmachine/common/configuration/embedder_conf.py | Adds null-safety check for embedder parsing |
| src/memmachine/common/configuration/language_model_conf.py | Adds null-safety check for language model parsing |
| src/memmachine/common/errors.py | Introduces ResourceNotReadyError for failed resource initialization |
| src/memmachine/common/resource_manager/base_manager.py | Creates base class with shared resource management logic |
| src/memmachine/common/resource_manager/embedder_manager.py | Refactors to use BaseResourceManager, adds add/remove operations |
| src/memmachine/common/resource_manager/language_model_manager.py | Refactors to use BaseResourceManager, adds add/remove operations |
| src/memmachine/common/resource_manager/reranker_manager.py | Refactors to use BaseResourceManager pattern |
| src/memmachine/common/resource_manager/resource_manager.py | Adds manager property accessors and save_config() method |
| src/memmachine/main/memmachine.py | Refactors default resolution logic, adds resource_manager property |
| src/memmachine/server/api_v2/config_router.py | Implements configuration API endpoints |
| src/memmachine/server/api_v2/config_service.py | Implements configuration service logic |
| src/memmachine/server/api_v2/exceptions.py | Extracts RestError class to separate module |
| src/memmachine/server/api_v2/router.py | Removes RestError class, adds config_router registration |
| tests/memmachine/common/api/test_version.py | Updates version regex to support additional local version identifiers |
| tests/memmachine/common/configuration/test_configuration.py | Adds tests for config file path tracking and save() method |
| tests/memmachine/common/resource_manager/test_resource_manager.py | Adds tests for save_config() functionality |
| tests/memmachine/server/api_v2/test_config_router.py | Adds comprehensive tests for configuration API endpoints |
| tests/memmachine/server/api_v2/test_config_service.py | Adds tests for configuration service functions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
299adeb to
4ee0fc9
Compare
694fa05 to
f92feae
Compare
- Add REST API endpoints for managing resources at runtime (add/remove/retry embedders, language models; view status) - Add PUT /api/v2/config/memory endpoint to update episodic and semantic memory configuration - Introduce graceful startup: resources that fail to build are tracked as FAILED instead of crashing the server - Add enabled/disabled flag for semantic memory with auto-disable when required fields (database, llm_model, embedding_model) are missing - Make episodic memory initialization resilient to missing embedder/reranker configuration - Extract shared resource manager logic into BaseResourceManager - Persist configuration changes to YAML file on updates - Add rest_client Config class wrapping all /api/v2/config endpoints with MemMachineClient.config() convenience accessor - Add comprehensive tests for config router, config service, and client SDK config module Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
f92feae to
34704c9
Compare
Purpose of the change
MemMachine currently requires all configured resources (embedders, language models, databases) to be available at startup. If any resource is unavailable — for example, a model is not yet deployed or an API key is not set — the server crashes. This makes it impossible to start the server in a partially configured state and add resources later.
This PR adds a runtime configuration API, makes startup graceful, and provides a client SDK module so users can:
Description
Graceful startup
EmbedderManager,LanguageModelManager,RerankerManager) now track build failures instead of crashing. Failed resources are recorded with statusFAILEDand can be retried later.BaseResourceManagerto reduce duplication across the three manager types.SemanticMemoryConfgains anenabledflag (defaultTrue) with amodel_validatorthat auto-disables when required fields (database,llm_model,embedding_model) are empty.MemMachine._initialize_default_episodic_configuration()now gracefully disables long-term or short-term episodic memory when the required embedder/reranker is not configured, instead of raising an error.MemMachine.start()andstop()skip the semantic service when semantic memory is disabled.Runtime configuration API (
/api/v2/config/...)GET/configGET/config/resourcesPUT/config/memoryPOST/config/resources/embeddersPOST/config/resources/language_modelsDELETE/config/resources/embedders/{name}DELETE/config/resources/language_models/{name}POST/config/resources/embedders/{name}/retryPOST/config/resources/language_models/{name}/retryPOST/config/resources/rerankers/{name}/retryRestErrorin a newexceptions.pymodule.Client SDK (
rest_client/config.py)Added a
Configclass to the Python SDK that wraps all configuration API endpoints:client.config()— convenience accessor onMemMachineClientget_config()/get_resources()— read current configuration and resource statusupdate_memory_config()— update episodic/semantic memory settingsadd_embedder()/add_language_model()— add new resourcesdelete_embedder()/delete_language_model()— remove resourcesretry_embedder()/retry_language_model()/retry_reranker()— retry failed resourcesFollows the same patterns as the existing
ProjectandMemorySDK classes (closed-client checks, timeout forwarding, Pydantic response parsing, exception logging).Fixes/Closes
Fixes #974
Type of change
How Has This Been Tested?
890+ unit tests pass (
pytest -m "not integration and not slow"), including:test_config_router.py— 27 tests covering all API endpoints including error casestest_config_service.py— 18 tests covering service-layer logic (add/remove/retry resources, memory config updates, persistence)test_configuration.py— 5 new tests for config save/load andconfig_file_pathtrackingtest_resource_manager.py— 3 new tests forsave_configand config property accesstest_config.py— 23 tests covering the client SDK Config class (happy paths, closed-client errors, timeout forwarding, exception propagation)Checklist
Maintainer Checklist
Screenshots/Gifs
N/A
Further comments
None