liveBook · Manning

Template

As explained in Build a Multi-Agent System (from Scratch)

A template is a modifiable text structure containing placeholders that can be filled with values before an LLM interaction.

A template is a text structure with placeholders that are filled with values before an LLM interaction. Templates standardize prompts for particular purposes and can also implement prompting techniques. section 4.1.2

In an LLMAgent, LLMAgentTemplates stores purpose-specific strings, including system messages and instructions for task execution. The agent can use default templates or receive a customized template set. section 4.1.2

Hailstone task instruction

An instruction template specifies the rules for generating a sequence and contains a {x} placeholder. Filling it with 4 produces the task instruction; the agent uses a tool to generate 4 -> 2 -> 1. section 4.3

A reflection template can give an LLM an episode’s task and result and ask it to produce a lesson for memory. The reflective-memory recipe accepts a user-supplied template or uses its default. section 7.4.2

Listing 4.2 Implementing LLMAgentTemplates
# llm_agents_from_scratch/agent/templates/llm_agent.py
from typing import TypedDict
 
 
class LLMAgentTemplates(TypedDict):
    """Prompt templates dict for LLMAgent."""
 
    system_message: str
    # for TaskHandler #A
    get_next_step: str
    step_rollout_chat_message: str
    step_rollout_content_instruction: str
    step_rollout_content_tool_call_request: str
    run_step_system_message_without_rollout: str
    run_step_system_message: str
    run_step_user_message: str
 
 
default_templates = LLMAgentTemplates( #B
    … #C
)

The LLMAgentTemplates TypedDict lists the purpose-specific string fields used by the agent. section 4.1.2

How Build a Multi-Agent System (from Scratch) covers it

How deep it goes
Defines placeholder filling, shows a purpose-keyed TypedDict schema, and demonstrates formatting a task instruction.
Examples
Uses a formatted Hailstone-sequence instruction and a customizable prompt for generating memory lessons.
What it assumes
Assumes familiarity with text-based LLM interaction and chat messages; introduces placeholder filling through agent examples.
What you can do after
Apply templates by filling task placeholders before passing instructions to LLMAgent, or supply a custom reflection template for memory.
How it connects
Connects templates to LLM agents, in-context learning, and episodic memory.

Also explained in

Compare how 29 books explain template →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Multi-Agent System (from Scratch). The section links point to the parts of the book it draws on.