Skip to content

feat(providers): implement ProviderContext for portable storage directory #2138

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rhuss
Copy link
Contributor

@rhuss rhuss commented May 12, 2025

[This PR implements #2139 but generalizes to separate runtime environments/contexts from specific provider configuration]

This PR introduces a new ProviderContext object that decouples execution environment concerns from provider configuration. In this first iteration, the ProviderContext is used to introduce storage directory which providers should use as base directory (e.g. for SQLite dbs). This allows removing absolute paths from templates and make the whole distribution more portable across environments. E.g. the current default to store everything in ~/.llama might be difficult to use in a containerized environment where the notion of a $HOME directory might differ from base image to base image.

Solution Details

  • Introduced a new ProviderContext class that encapsulates runtime environment information
  • Separates concerns between static configuration and runtime variables that depend on execution context
    - Updated provider interfaces to follow a consistent context, config, deps pattern
  • Provides consistent access to environment information across the codebase
  • Implemented a lookup for defining the storage directory:
    • CLI option (--storage-dir)
    • Environment variable (LLAMA_STACK_STORAGE_DIR)
    • Default distribution directory

Note

  • Only inline (local) providers have been updated in this PR
  • Remote adapters and other provider types are left out for the moment

Next Steps

  • Add ProviderContext objects to remote adapters (for now it is added only for local providers)
  • Update templates to use relative pathes

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 12, 2025
@rhuss rhuss force-pushed the feature/provider-context branch from f1c18ac to 6e5cde7 Compare May 12, 2025 18:10
- Introduce ProviderContext class to decouple provider storage paths from absolute paths
- Add storage_dir attribute to StackRunConfig to accept CLI options
- Implement storage directory resolution with prioritized fallbacks:
  1. CLI option (--state-directory)
  2. Environment variable (LLAMA_STACK_STATE_DIR)
  3. Default distribution directory
- Standardize provider signatures to follow context, config, deps pattern
- Update provider implementations to use the new context-based approach
- Add comprehensive tests to verify state directory resolution
@rhuss rhuss force-pushed the feature/provider-context branch from a89ded7 to e6c9aeb Compare May 14, 2025 07:52
@rhuss rhuss changed the title feat(providers): implement ProviderContext for portable state management feat(providers): implement ProviderContext for portable storage directory May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants