Provider

This chapter describes the concept of a provider.

Idea

A Provider in the Maia Framework is used as a bridge between an Agent and the model. As mentioned in previous chapters, Agent is just an abstraction, so in tests, agents can be used without worrying if it is OpenAI, Anthropic, or Ollama. However, we need to somehow tell the agent how it should communicate with the model - this is the job of the Provider.

Built-in providers

MAIA comes with built-in providers to build tests super-fast. This group will grow over time, developed either by the MAIA core team or by the community.

Generic Lite LLM

This provider is an implementation of the LiteLLM library, a popular abstraction over models. You can easily create a new agent by just providing the name of the model and the API endpoint.

Here is the example:

  self.create_agent(
      name="Bob",
      provider=GenericLiteLLMProvider(config={
          "model": "ollama/mistral",
          "api_base": "http://localhost:11434"
      }),
      system_message="You are an assistant who only suggests clothing."
  )

Note:

A provider can also be loaded using a configuration file (see: Config), but this is an advanced concept, so we encourage you to get familiar with the direct approach first.

Ollama

We also have a dedicated OllamaProvider:

  self.create_agent(
      name="Bob",
      provider=OllamaProvider(config={
          "model": "mistral"
      }),
      system_message="You are an assistant who only suggests clothing."
  )

Mock

Sometimes you might want to completely mock the AI agent. For instance, you might want to simulate an AI agent's response by providing some corner-case messages. You can do this by creating an agent with MockProvider:

  self.create_agent(
      name="Alice",
      provider=MockProvider(config={
          "responses": [
              "Hello, I am a mock agent.",
              "I am doing well, thank you for asking."
          ]
      })
  )

  def echo_bot(user_prompt):
      return f"You said: {user_prompt}"

  self.create_agent(
      name="Bob",
      provider=MockProvider(config={
          "response_function": echo_bot
      })
  )

The MockProvider takes a hardcoded list of responses or a response_function that can be used to react to a prompt.

Existing

Note:

This is an advanced concept for specific scenarios.

To be prepared for very custom providers, MAIA provides the ability to pass an existing agent solution. This means you can have your own private model solution and still use it in MAIA.

Here is an example of such an agent:

class ComplexResponseAgent:
    """An agent with a custom query method and a complex response format."""
    def query(self, prompt: str) -> dict:
        return {"response": f"Complex: {prompt}", "data": [1, 2, 3]}

...

    # Agent with a custom method name and a response extractor
    self.create_agent(
        name="ComplexAgent",
        provider=ExistingAgentProvider(config={
            "agent_instance": ComplexResponseAgent(),
            "call_method": "query",
            "response_extractor": lambda r: r["response"]
        })
    )

Note:

We will be constantly building new providers, but if you would like to contribute, we would be more than happy! The instructions on how to write a new provider will be shared soon. Stay tuned!