AI Agents

10. AI Agents#

An AI agent uses a model to decide which tools to call and in what order to finish a task. This chapter shows how tool calling works, how agent loops plan and stop, and how protocols and permissions keep agents safe inside organizational systems.

  • Tool Use: Function calling lets a model request actions that your code performs and reports back.

  • Agent Loops: Agents repeat plan, act, and observe steps until a stopping condition is met.

  • Agent Protocols: Standards such as the Model Context Protocol, plus permissions and human approval, control what agents can do.

Chapter Video

This explainer shows how a model requests a function call, how your code runs it, and how the result flows back, the core mechanism behind every agent.

LLMs Can Use Tools, Just Like You and I - LLM Function Calling Explained (7:58) by Gary Explains

Hosted on YouTube; property of its original creator, embedded here for educational reference only.

Learning Objectives

By the end of this chapter, you will be able to:

  1. Define tools with schemas that a model can call.

  2. Implement a tool-calling loop that executes calls and returns results to the model.

  3. Set stopping conditions and step limits for agent loops.

  4. Apply least privilege and human approval to agent actions.

  5. Build a Python agent that looks up and updates service tickets through tools.

Chapter Flow

Glossary

#

Term

Explanation

1

AI agent

A system in which a model chooses actions, such as tool calls, to complete a task.

2

Tool

A function or service an agent can call, such as a database query or an email sender.

3

Function calling

A model capability to return a structured request to run a named function.

4

Tool schema

A description of a tool’s name, purpose, and parameters given to the model.

5

Tool result

The output of a tool call, sent back to the model.

6

Agent loop

The repeated cycle of model decision, tool execution, and observation.

7

Planning

Breaking a task into steps before or while acting.

8

Agent memory

Information an agent keeps across steps or sessions.

9

Stopping condition

A rule that ends an agent loop, such as task completion or a step limit.

10

Model Context Protocol (MCP)

An open protocol for connecting models to tools and data sources.

11

Least privilege

Granting only the permissions a component needs to do its job.

12

Human approval

A required human confirmation before an agent takes a consequential action.

13

Dispatcher

Application code selecting an allowed tool implementation.

14

Observation

The actual outcome returned from a tool attempt.

15

Side effect

An externally visible state change.

16

Repeated-call detector

A check preventing an unwanted identical tool repeat.

17

Terminal status

The explicit reason an agent run ends.

18

Action binding

Connecting approval to an exact operation, target, and version.

19

Delegated authorization

A defined grant of authority to act for an identity.

20

Agent trace

Recorded proposals, decisions, operations, and outcomes.

21

Audit log

A record connecting actions to actors and outcomes.