Introduction to Language Models › A Quick Preview

Michael BrenndoerferJune 9, 20251 min read
AI Agent HandbookAll chapters
Part 2 of 15Language Models - The Brain of the Agent
Chapter 3Introduction to Language Models › A Quick Preview
Reading section 3 of 6 · A Quick Preview · 1 minSection 3 of 6 · 1 min

Book contents

Section 3 of 6 · 1 min read

Introduction to Language Models › A Quick PreviewOne section · Sections in this chapter3 / 6 ↓

Before we dive into the details, let's see what we're building toward. Here's a glimpse of how simple it can be to use a language model (we'll explain every part of this in the upcoming sections):

In[3]:
Code
from openai import OpenAI

## GPT-5 is ideal for basic prompting and text generation tasks
## It provides reliable, coherent responses for straightforward questions
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))  # Replace with your actual API key

## Send a prompt to the model
response = client.chat.completions.create(
    model="gpt-5",
    messages=[{"role": "user", "content": "What is an AI agent?"}]
)

## Get the model's response
print(response.choices[0].message.content)
Out[3]:
Console
An AI agent is a software system that perceives its environment, reasons about what to do, and acts autonomously to achieve goals.

Key ideas:
- Sense-think-act loop: observe inputs (e.g., text, sensors, APIs) → plan/decide → take actions → observe results → adjust.
- Core components: perception, state/knowledge/memory, policy or planner, action/execution, and often learning to improve over time.
- Types:
  - Reactive vs. deliberative (planning) agents
  - Single-agent vs. multi-agent
  - Embodied (robots) vs. software-only (tools/APIs)
  - Rule-based vs. learning-based (including LLM-powered agents)
- Examples: customer support assistants, robotic vacuums, stock-trading bots, calendar/email assistants, game-playing bots, autonomous vehicles, workflow automations that use external tools.
- How it differs from a plain model: a model just maps inputs to outputs; an agent wraps models with goals, memory, tool use, and decision loops to act in the world.
- Limitations/considerations: reliability, safety/alignment, tool permissions, monitoring, data privacy, and evaluation of performance and side effects.

That's it. You send text in, you get text back. The language model reads your prompt and generates a response, one word (technically, one "token") at a time.

Of course, there's a lot happening under the hood. The model is drawing on patterns learned from billions of pages of text, calculating probabilities for what should come next, and generating coherent, contextually appropriate responses. But from your perspective as a developer, it's remarkably straightforward: you provide input, the model provides output.