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.

This is the core business protection logic added to the agents.
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)