liveBook · Manning

Scratchpad

As explained in AI Agents in Action, Second Edition

A scratchpad is temporary storage for intermediate information generated during an agent's task execution.

A scratchpad is temporary external storage for intermediate information produced during an agent’s task. It acts as working memory: the agent writes plans, events, or partial results, then rereads them on later steps to maintain continuity across calls. section 5.4

A scratchpad does not think or reason by itself. It stores and tracks the outputs of an agent’s thinking. The agent remains responsible for interpreting, revising, and using those entries. section 5.4.1

Use a scratchpad when an agent needs to:

  • Break a complex task into steps and preserve intermediate results. section 5.4
  • Review and revise a global plan as individual goals are completed. section 5.4
  • Carry information between fresh invocations, preventing earlier events from disappearing. section 3.4
  • Support ReAct or tree-of-thought workflows when suitable instructions define how the stored thoughts are used. section 5.4.1

A time-tracking journal

A time-travel agent can call record_event to append each event to a journal and call load_journal to retrieve the entries before producing a summary. A module-level in-memory list is sufficient for a single-agent, single-process demonstration, but the same shared list has different correctness properties when multiple agents connect to one server. section 3.4

Listing 5.9 04_sequential_thinking_agent.py
thinking_srv = MCPServerStdio(    #1
    name="sequential-thinking",
    params={
        "command": "npx",
        "args": [
            "-y", 
            "@modelcontextprotocol/server-sequential-thinking"
            ],
    },
)

instructions = """
You are helpful planning assistant.
"""
agent = Agent(
    name="Assistant",
    instructions=instructions,
    mcp_servers=[thinking_srv],    #2
)
async with thinking_srv:
    tools = await thinking_srv.list_tools()
    print("Available tools:", tools)    #3
    goal = """
Discover and output the tool and functions you have available.
"""
    print("Running...", goal)
    result = await Runner.run(agent, goal)
    print(result.final_output)

Inspect a minimal MCP configuration that exposes the SequentialThinking tool to an agent, lists its tools, and runs a planning request. section 5.4.1

How AI Agents in Action, Second Edition covers it

How deep it goes
Explains storage, rereading, revision, tool exposure, and deployment boundaries, but stops short of implementing a durable storage system.
Examples
Uses a SequentialThinking MCP server and a time-travel journal with record_event and load_journal tools.
What it assumes
Assumes familiarity with agents and tools while demonstrating from first principles that storage does not perform reasoning.
What you can do after
Apply it via MCP tools or an in-memory journal to preserve intermediate reasoning and events across an agent’s execution loop.
How it connects
Connects scratchpads with working memory, planning, ReAct, tree-of-thought, journals, and agent memory.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action, Second Edition. The section links point to the parts of the book it draws on.