door: the one door to the model¶
Every topic calls the model through this small package. Ollama answers by default; LLM_MODEL switches every lab
to another model or a hosted provider, with no code changes. Settings live in ai-learning/.env (copy .env.example), read once on import; a variable set
in the shell wins. Setup per provider: providers/.
import door
reply = door.chat(messages, tools=[get_stock]) # Reply: text, tool_calls, thinking, in_tokens, out_tokens, ms
for call in reply.tool_calls:
messages += [reply.message(), door.tool_result(call, get_stock(**call.args))]
order = door.chat(messages, schema=Order).parse(Order) # structured output, validated by Pydantic
reply = await door.achat(messages) # async, same arguments
s = door.stream(messages); text = "".join(s); s.reply # text as it arrives, then the whole turn
vectors = door.embed(["M8 bolt", "nitrile gloves"]).vectors
reply = door.chat([{"role": "user", "content": "Read this list", "images": ["note.png"]}],
model=door.vision_model()) # images: file paths or bytes, on a user message
Why a door¶
- One shape for every provider. Labs read
reply.textandreply.tool_callsthe same way on Ollama, OpenAI or Claude. - Feature code never imports a provider SDK. Switching provider, adding a fallback or logging every call happens in one place.
- Messages stay plain dicts, so agent state can be saved as JSON and resumed later.
- Defaults that suit evals: temperature 0, thinking off, unless a call asks otherwise.
Files¶
| File | What it holds |
|---|---|
__init__.py |
chat, achat, stream, embed, describe: pick the backend from the model name, time the call |
types.py |
Reply, ToolCall, tool_result(), tool_spec() (a Python function becomes a JSON-schema tool), data_url() for images |
config.py |
LLM_MODEL, EMBED_MODEL and VISION_MODEL (default ollama/qwen3-vl:8b-instruct: qwen3:8b can't see); provider/model names (no provider means Ollama); load_env() reads .env |
local.py |
Ollama, native: to_ollama() translates messages; exact think on/off and token counts |
fake.py |
DOOR_FAKE=1: a stand-in for smoke runs. Schema-shaped JSON, one call to the first tool, hash vectors; meaningless answers, no model |
hosted.py |
Every other provider through LiteLLM: to_openai() translates messages; errors mapped to ConnectionError / TimeoutError; a 429 waits the provider's delay, up to DOOR_MAX_WAIT_S (120 s, 0 = off) |
test_door.py |
Model-free tests: translation, config, and the Ollama path with a fake client |
test_hosted.py |
The hosted path with LiteLLM's mock mode; skipped until .[hosted] is installed |
No model? DOOR_FAKE=1¶
DOOR_FAKE=1 python <lab>.py sends every call to fake.py: the lab runs end to end in seconds with nonsense answers.
It checks plumbing, not AI. CI uses it to run every lab on every push (python smoke_labs.py from the root).
Rules of thumb¶
- A model change is a prompt change: run the lab's eval again before trusting it.
- Change embedding models only with a re-index; the labs keep one vector store per embedding model.
- Pin gateway libraries (LiteLLM) to an exact version; they see every prompt and every key.
- The common mistake: appending tool results without
reply.message()first. The result then answers a call the model never sees.