Using a Language Model in Code › The Basic Pattern

Michael BrenndoerferJune 27, 20251 min read
AI Agent HandbookAll chapters
Part 2 of 15Language Models - The Brain of the Agent
Chapter 5Using a Language Model in Code › The Basic Pattern
Reading section 2 of 15 · The Basic Pattern · 1 minSection 2 of 15 · 1 min

Book contents

Section 2 of 15 · 1 min read

Using a Language Model in Code › The Basic PatternOne section · Sections in this chapter2 / 15 ↓

Every interaction with a language model follows the same fundamental pattern, regardless of which provider you use:

  1. Set up a connection to the model (usually via an API)
  2. Send a prompt (your instruction or question)
  3. Receive a response (the model's generated text)
  4. Use the response (display it, process it, or feed it into another step)

That's it. The complexity comes in how you craft your prompts and what you do with the responses, but the basic mechanics are straightforward.

Let's see this in action.