1. Understanding AI
  2. LLM Basics

Understanding AI

LLM Basics

Explains how a call to an LLM works and the settings that shape it: messages and roles, context windows, tokens and caching, reasoning, tools, structured output, files, and choosing a model.

A call to an LLM

Every call sends the model the whole conversation so far, plus the tools it may use. The model replies with text, one or more tool calls, or both. It keeps nothing between calls.

The GPT Chat Task does this bookkeeping for you. It stores each chat on the stub under a chat_name, adds your new messages, sends the conversation, runs the tools the model calls, and adds the results. You only send what's new.

Messages and roles

Each message in the conversation has a role:

Role What it holds
system Instructions: who the assistant is, what it must and mustn't do, and context it needs. Models give these more weight than user messages.
user What the person said, or input your template passes in on their behalf.
assistant What the model said, including the tool calls it made.
tool The result of a tool call. Stubber adds it when an action the model called finishes; you don't send it yourself.

In Stubber, set the main instructions with set_system_message. Use a penultimate system message for context that changes every turn, such as the current state or time: it sits just before the latest message, where the model pays most attention, and is filled in fresh on every call.

Context window

The context window is everything the model can see in one call: the instructions, the conversation, tool definitions, tool results, files, and the reply it writes. Current models take hundreds of thousands of tokens, and some up to about a million.

A large window is a limit, not a target. Models pay less attention to the middle of a long, cluttered context, and every token costs money and time. Give the model what the task needs:

  • Keep instructions short and specific.
  • Let the model fetch data with tools when it needs it, instead of loading everything up front.
  • Use separate chats, with their own chat_name, for separate jobs.
  • Turn on compaction for long-running chats, so older history is summarized automatically.

Tokens and caching

Models read and write in tokens, pieces of words. In English, a token is about four characters, or three quarters of a word. Other languages, code and data usually take more tokens per word.

Providers charge per token, separately for input and output. Reasoning tokens count as output.

Providers also cache the start of the prompt. When a call begins exactly like a recent one, the repeated part is cheaper and faster. To get the most from caching, keep the start of every call the same:

  • Keep the system message and tool definitions static. Don't put the time, stub data or other changing values in them. See setting up an action for tool calling.
  • Put changing information in the penultimate system message, a user message or a tool result.

Reasoning

Reasoning models think before they answer: they work through the problem, plan tool calls and check their work. More thinking gives better answers on hard problems, but costs more and takes longer.

Set reasoning_effort on the GPT Chat Task to choose how much: low for quick conversational turns, higher for decisions with several steps or rules to weigh. Models that don't reason ignore it.

Tools

You give the model tools, and it decides when to call them. In Stubber, a tool is an action with AI enabled: its name and description tell the model what it does, and its fields become the tool's inputs. The action runs on the stub like any other, and its result goes back to the model.

Models can call several tools in one turn and chain calls across turns, so an agent can look something up, act on it and report back without a fixed sequence. Control what it can do with the state the stub is in and the actions available there. See Tool calling.

Structured output

When a later task needs data rather than prose, ask for structured output. With response_format set to a JSON schema, the model's reply matches that schema. Use it to classify a message, extract details from a document, or make a decision your template branches on. See response_format.

Images, documents, audio and video

Most current models understand images, and many read PDFs. Some also take audio and video. Add files to a chat with include_attachments. Check which file types a model supports on LLM Models.

Choosing a model

Models differ in quality, speed, cost, context size and which inputs they accept. Pick for the job, not the newest release:

  • A fast, low-cost model for most conversations.
  • A stronger reasoning model for complex decisions, or as a subagent for one hard step.
  • A small, fast model for quick checks, such as safeguards.
  • A live voice model for calls. See Live Voice.

Stubber's model aliases, such as stubber-default-conversational, point at the model Stubber recommends for each job and move to better models as they come out. Use them unless you need a specific model. Test important flows with real examples before you switch.