liveBook · Manning

Chapter 4: The LLMAgent Class

What you will learn in chapter 4 of Build a Multi-Agent System (from Scratch)

This introduction connects the framework’s LLM and tool components to an agent and explains how to configure the chapter notebook’s LLM.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction connects the framework’s LLM and tool components to an agent and explains how to configure the chapter notebook’s LLM.

Key terms: LLMAgent, backbone LLM, tools, processing loop, planning, tool-calling, make_llm(), OLLAMA_API_KEY, LLM_PROVIDER, OPENAI_API_KEY

4.1 LLMAgent: a simple LLM agent class

This section outlines the LLMAgent design, its task execution interface, and the data structures and attributes it uses.

Key terms: LLMAgent, backbone LLM, tools, tool-call requests, run(), processing loop, Task, TaskResult, id_, instruction

4.1.1 Implementing Task and TaskResult

This section explains the attributes of Task and TaskResult and how they link a task to its result.

Key terms: Task, TaskResult, instruction, id_, task_id, content

4.1.2 Implementing LLMAgent: Part 1

This section implements the LLMAgent’s template storage, initialization, and tool registration, leaving its processing loop for later.

Key terms: templates, placeholder variables, LLMAgentTemplates, system message, __init__(), llm, tool_registry, tools, @property, add_tool()

4.2 Implementing a processing loop for LLMAgent

This section introduces the role of LLMAgent.run() and the discrete-step processing loop it will use to execute tasks.

Key terms: LLMAgent, run(), Task, TaskResult, processing loop, TaskHandler, step execution

4.2.1 Designing a processing loop

This section designs the agent’s processing loop, its supporting data structures and task handler, and describes the ReAct loop as an alternative pattern.

Key terms: processing loop, sub-step, planning, tool-calling, stopping condition, TaskStep, TaskStepResult, NextStepDecision, task_id, kind

4.2.2 Implementing TaskStep, TaskStepResult, and NextStepDecision

This section describes how task steps are associated with tasks and how next-step decisions are represented as structured output.

Key terms: TaskStep, TaskStepResult, task_id, Task, NextStepDecision, pydantic.BaseModel, structured output, get_next_step(), TaskHandler

4.2.3 Implementing LLMAgent: Part 2

The section implements LLMAgent task execution through a TaskHandler, structured next-step decisions, single-turn sub-step chats, and an asynchronous processing loop.

Key terms: run(), TaskHandler, get_next_step(), run_step(), TaskStepResult, TaskResult, NextStepDecision, structured output, TaskStep, backbone LLM

4.3 Putting it all together: Hailstone LLM agent

This section constructs and runs a Hailstone LLMAgent, retrieves its result, and inspects its execution rollout.

Key terms: parametric knowledge, Hailstone tool, tool-calling, make_llm(), backbone LLM, LLMAgent, Task, instruction string, TaskHandler, asyncio.Future

4.4 Extending to MAS: LLMAgent

The section explains how LLMAgent instances can participate in multi-agent systems as coordinated subagents or remotely accessible agents.

Key terms: subagents, coordinator, delegation pattern, backbone LLM, prompt templates, processing loop, remote A2A agent, A2A protocol, server

4.5 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 3: Working with LLMs Chapter 5: MCP Tools →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.