Using a Language Model in Code › What We've Built

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 › What We've Built
Reading section 10 of 15 · What We've Built · 1 minSection 10 of 15 · 1 min

Book contents

Section 10 of 15 · 1 min read

Using a Language Model in Code › What We've BuiltOne section · Sections in this chapter10 / 15 ↓

In just a few dozen lines of code, you've created the foundation of an AI agent:

  • A function that can send prompts to a language model
  • Error handling for when things go wrong
  • A simple chat interface for interacting with the assistant
  • Understanding of how to control the model's behavior

This is the core of every AI agent. Everything else we build (tools, memory, planning, reasoning) will be additions and enhancements to this basic pattern of sending messages and receiving responses.