Hybrid AI mode • local / BYOK / owner fallback

Zero seller API bill by design.

The agents now include an intelligent provider priority: local Ollama first when selected, client BYOK when the client wants external API power, owner fallback only for rare support/demos.

AI mode
Structured French teacher + controlled AI costs.

Provider priority

This is the core business protection logic added to the agents.

1. Local OllamaAI_MODE=local. Local/free inference on the client machine after setup.
2. Client BYOKCLIENT_OPENAI_KEY. The client controls and pays API usage.
3. Owner fallbackOWNER_OPENAI_KEY. Optional and rare, for demos or special support only.

Code integrated in the agent core

import os

class BaseTutorAgent:
    def __init__(self, kb_path):
        self.client_key = os.environ.get("CLIENT_OPENAI_KEY", "")
        self.owner_key  = os.environ.get("OWNER_OPENAI_KEY", "")
        self.use_local  = os.environ.get("AI_MODE", "") == "local"

        if self.use_local:
            self.mode = "ollama"
        elif self.client_key:
            self.mode = "api_client"
        elif self.owner_key:
            self.mode = "api_owner"
        else:
            self.mode = "ollama"

    def ask_llm(self, prompt, mode=None, module_id=None):
        if self.mode == "ollama":
            return self._ask_ollama(prompt)
        key = self.client_key or self.owner_key
        return self._ask_openai(prompt, key)

Client-facing promise

The autonomous package can run locally with Ollama or deterministic fallback, which helps keep questions on the client device and avoids recurring seller API consumption. If the client wants external model power, they can use BYOK.