Skip to content

Dependency Resolvers

Dependency resolvers are a key component of Rustic AI's dependency injection system. They provide agents with access to external services, resources, and capabilities in a modular, configurable way.

Overview

Rustic AI's dependency resolver system allows agents to:

  • Access external services (databases, APIs, LLMs, etc.)
  • Share resources efficiently
  • Swap implementations without changing agent code
  • Configure services in a consistent way
  • Test with mock dependencies

Available Resolvers by Package

Rustic AI provides dependency resolvers across multiple packages:

Core

Core dependencies for essential functionality: - FileSystemResolver - File system access - InMemoryKVStoreResolver - In-memory key-value store - PythonExecExecutorResolver - Python code execution - InProcessCodeInterpreterResolver - In-process code interpretation - EnvSecretProviderResolver - Environment-based secret management

Redis

Redis-based dependencies: - RedisKVStoreResolver - Persistent key-value store backed by Redis

LiteLLM

Large language model integration: - LiteLLMResolver - Unified LLM access across multiple providers

Chroma

Vector database integration: - ChromaResolver - Vector database for embeddings

LangChain

LangChain framework integration: - OpenAIEmbeddingsResolver - OpenAI embeddings - CharacterSplitterResolver - Character-based text splitting - RecursiveSplitterResolver - Recursive text splitting

Using Dependency Resolvers

Dependency resolvers are configured in guild or agent specifications and then injected into agent handlers:

# In guild configuration
from rustic_ai.core.guild.builders import GuildBuilder
from rustic_ai.core.guild.dsl import DependencySpec

guild_builder = (
    GuildBuilder("my_guild", "My Guild", "Guild with dependencies")
    .add_dependency_resolver(
        "filesystem",
        DependencySpec(
            class_name="rustic_ai.core.guild.agent_ext.depends.filesystem.filesystem.FileSystemResolver", 
            properties={"path_base": "/tmp/rusticai/files", "protocol": "file", "storage_options": {}}
        )
    )
)

# In agent code
from rustic_ai.core.guild import Agent, agent

class FileAgent(Agent):
    @agent.processor(clz=FileRequest, depends_on=["filesystem"])
    def handle_file_request(self, ctx: agent.ProcessContext, filesystem):
        # Use the filesystem dependency
        with filesystem.open("data.txt", "w") as f:
            f.write("Hello, World!")

Dependency Resolution Process

When an agent handler with dependencies is invoked:

  1. The system identifies dependencies listed in depends_on
  2. For each dependency:
    • First checks agent-level dependency_map
    • Then checks guild-level dependency_map
  3. For each dependency specification:
    • The resolver class is instantiated with the provided properties
    • The resolver's resolve() method is called to create the dependency
    • The result is injected as an argument to the handler

Creating Custom Resolvers

To create a custom resolver:

  1. Extend the DependencyResolver base class
  2. Implement the resolve(guild_id, agent_id) method
  3. Configure the resolver in your guild or agent specification

For detailed information on the dependency system, see Dependencies Core Documentation and Dependency Injection Guide.