Chapter 14: Productionizing AI agents: Memory, guardrails, and beyond
The chapter introduction explains why production agents need more than models and tools, and identifies memory and guardrails as two capabilities that support reliable behavior.
After this chapter you will be able to
- Production Agent Reliability. Explain why connecting a language model to tools is not enough for a reliable production agent. Describe the need to maintain context, respect application boundaries, and handle unexpected situations.
- Memory for Conversation Continuity. Explain how remembering past interactions helps an agent carry on a natural conversation, answer follow-up questions, and recover from interruptions.
- Guardrails for Agent Boundaries. Explain how guardrails help keep an agent within its intended scope and policies by filtering requests and, when needed, catching inappropriate responses.
- Memory for conversation continuity. Explain why memory matters for production-ready chatbot agents, contrasting conversations that retain context with interactions that start fresh.
- Three scopes of agent memory. Distinguish short-term memory, long-term user memory, and long-term application-level memory by their persistence and whose interactions they support.
- Short-term conversation context. Explain why a stateless assistant struggles with follow-up questions and how retaining conversation history addresses the problem.
- Checkpoint snapshots and super-steps. Explain what a checkpoint saves, when LangGraph saves one, and why it provides more than a stored message list.
- Thread-linked state restoration. Trace how a thread ID lets a later graph invocation find the right checkpoint and continue a conversation.
- Conversation thread identity. Explain why the original chat loop has no continuity and how passing the same thread ID in a RunnableConfig on every invocation identifies one conversation.
- Graph state checkpointing. Describe how adding an in-memory checkpointer when compiling the graph preserves state for the next turn.
- Previous response ID continuity. Explain how use_previous_response_id maintains LLM conversation continuity with the Responses API and why omitting it causes an error in the described setup.
- Follow-up question context. Explain why the assistant understands that “same town” means Penzance in a follow-up question.
- Restoring conversational context. Trace the manual rewind from a saved checkpoint to a context-dependent follow-up, and explain how it relates to subsequent turns using the same thread_id.
- Guardrail purpose and response. Explain how guardrails keep an agent within its intended scope and policies, and describe what can happen when a check fails.
- Guardrail workflow placement. Describe the four points in an agent workflow where guardrail checks can be applied and what each checks.
- Early domain filtering benefits. Explain why the assistant checks whether a question is travel-related before agent reasoning: rejecting unrelated questions reduces inaccurate answers and unnecessary LLM use.
- Structured guardrail policy. Describe how the lightweight LLM classifier makes a structured travel-relevance decision and what roles the policy components play.
- Router refusal and exit path. Trace how the router handles a failed versus a passed guardrail check, including the refusal message, state update, and early exit through the graph.
- Layered input guardrails. Explain why each agent needs its own input guardrail even when the chatbot has a router-level guardrail. Distinguish the router’s early filter from the agents’ narrower checks.
- Pre-model refusal filter. Trace how pre_model_guardrail processes an agent’s input and how it is attached to both agents.
- Production readiness beyond basics. Explain why memory and guardrails may not be enough before deploying an AI agent to real users. Additional considerations depend on the application’s domain, scale, and compliance requirements.
- Persistent memory and personalization. Explain how long-term memory differs from short- to medium-term memory and why a production agent might retain user information over time.
- Human review for uncertain requests. Explain when the Cornwall travel assistant should escalate a request to a human travel expert and when that review occurs.
- Post-model guardrail role. Distinguish post-model guardrails from the pre-model guardrails used earlier in the chapter, and explain why output needs a final check even when an LLM answer looks reasonable.
- Four evaluation dimensions. Distinguish functional, behavioral, performance, and regression testing for the Cornwall travel assistant, including what each checks.
- Continuous production evaluation. Explain why evaluation belongs both on the preproduction checklist and in ongoing operation, rather than treating memory and guardrails as sufficient for production readiness.
- Deployment model tradeoffs. Explain how infrastructure strategy, privacy and compliance policies, and operational preferences affect agent deployment. Describe the choice between managed SaaS hosting and deployment in an organization’s own cloud environment.
- LangGraph Platform hosting. Describe what LangGraph Platform provides when deploying a LangGraph-based agent system and why it can ease the move from prototype to production.
- Open Agent Platform orchestration. Describe OAP’s role as a runtime and orchestration layer, including how its extensible agent patterns and integrations support coordinated enterprise agents.
What it builds on
- Agent state: Tracking the conversation (chapter 11) · Introduces agent state as a way to track a conversation.
- How tool calling works with LLMs (chapter 11) · Earlier explanation of how tool calling works with LLMs.
- State management and typing (chapter 5) · Assumes familiarity with state in a LangGraph graph.
- Building a router-based travel assistant (chapter 12) · The router-based travel assistant being modified.
- Routing logic (chapter 12) · The router’s existing choice between travel and weather agents.
- Refactoring to use the LangGraph ReAct agent (chapter 11) · The prebuilt LangGraph ReAct agent
- Observing and debugging with LangSmith (chapter 11) · The earlier use of LangSmith for observing and debugging agents.
- The Supervisor pattern: An agent of agents (chapter 12) · The supervisor agent pattern used as an example of an OAP prebuilt pattern.
Section by section
Introduction
The chapter introduction explains why production agents need more than models and tools, and identifies memory and guardrails as two capabilities that support reliable behavior.
- Production Agent Reliability: Explain why connecting a language model to tools is not enough for a reliable production agent. Describe the need to maintain context, respect application boundaries, and handle unexpected situations.
Why it matters: Reliability depends on the whole agent system, not just the model’s capabilities. - Memory for Conversation Continuity: Explain how remembering past interactions helps an agent carry on a natural conversation, answer follow-up questions, and recover from interruptions.
Why it matters: A conversation feels coherent when the agent can use what happened earlier. - Guardrails for Agent Boundaries: Explain how guardrails help keep an agent within its intended scope and policies by filtering requests and, when needed, catching inappropriate responses.
Why it matters: Guardrails help an assistant stay focused and avoid unsafe or inappropriate exchanges.
Key terms: production systems, safeguards, application boundaries, memory, past interactions, follow-up questions, guardrails, intended scope, policy framework
14.1 Memory
This section explains why memory matters for conversational AI agents: it preserves context across interactions so users can follow up naturally.
- Memory for conversation continuity: Explain why memory matters for production-ready chatbot agents, contrasting conversations that retain context with interactions that start fresh.
Why it matters: Remembering earlier turns lets a chatbot handle follow-up questions without making the user repeat context.
Key terms: memory, context, stateful workflows
14.1.1 Types of memory
Defines three scopes of AI-agent memory by how long information persists and who can use it.
- Three scopes of agent memory: Distinguish short-term memory, long-term user memory, and long-term application-level memory by their persistence and whose interactions they support.
Why it matters: These distinctions clarify what an agent can remember during a conversation versus across later conversations or for other users.
Key terms: short-term memory, long-term user memory, long-term application-level memory
14.1.2 Why short-term memory is needed
The section explains how retaining conversation history lets a tool-calling assistant handle follow-up questions without losing context.
- Short-term conversation context: Explain why a stateless assistant struggles with follow-up questions and how retaining conversation history addresses the problem.
Why it matters: Conversation history lets an assistant understand follow-ups such as “same town” without making the user start over. - Tool-calling conversation sequence: Trace the typical interaction from a user message through optional tool calls to the LLM’s final answer.
Why it matters: This sequence establishes what happens during an interaction before the next user turn needs its context.
Key terms: stateless, conversation history, stateful, short-term memory, tool-calling protocol, tool calls, tool results
14.1.3 Checkpoints in LangGraph
Explains how LangGraph checkpoints save graph state and use thread IDs to restore the right state across invocations.
- Checkpoint snapshots and super-steps: Explain what a checkpoint saves, when LangGraph saves one, and why it provides more than a stored message list.
Why it matters: Saving the whole graph state makes checkpoints useful for more than remembering a conversation. - Thread-linked state restoration: Trace how a thread ID lets a later graph invocation find the right checkpoint and continue a conversation.
Why it matters: The thread ID keeps follow-up turns connected to the correct saved session, even when a user has multiple sessions. - Uses beyond chat memory: Describe how saving full graph state supports recovery and human-in-the-loop pauses as well as multi-turn conversation.
Why it matters: These uses show why checkpointing is a more general mechanism than saving chat messages.
Key terms: checkpoint, checkpointer, super-step, graph state, configuration, thread, thread ID, state rehydration, human-in-the-loop workflows, multi-turn conversational context
14.1.4 Adding short-term memory to our travel assistant
The section adds short-term memory to a router-based travel assistant by identifying conversation threads, checkpointing graph state, and configuring the LLM to reference previous responses.
- Conversation thread identity: Explain why the original chat loop has no continuity and how passing the same thread ID in a RunnableConfig on every invocation identifies one conversation.
Why it matters: The thread ID lets LangGraph associate separate turns with the right conversation. - Graph state checkpointing: Describe how adding an in-memory checkpointer when compiling the graph preserves state for the next turn.
Why it matters: A thread ID identifies the session, while checkpointing preserves the graph state it needs on the next turn. - Production checkpoint storage: Distinguish the development use of InMemorySaver from the persistent storage needed for a production assistant.
Why it matters: The demonstration's in-memory saver does not provide the durability expected in production. - Previous response ID continuity: Explain how use_previous_response_id maintains LLM conversation continuity with the Responses API and why omitting it causes an error in the described setup.
Why it matters: Graph checkpointing and the LLM's handling of prior turns are both configured for this assistant's conversation continuity.
Key terms: thread ID, RunnableConfig, state, travel_assistant.invoke(), checkpointer, state snapshots, InMemorySaver, persistent storage backend, SqliteSaver, PostgresSaver
14.1.5 Executing the checkpointer-enabled assistant
This subsection shows that a checkpointer-enabled travel assistant can use conversation history to understand a follow-up question.
- Follow-up question context: Explain why the assistant understands that “same town” means Penzance in a follow-up question.
Why it matters: Conversation history lets the assistant make sense of follow-up questions that omit details already given.
Key terms: LangGraph checkpointer, short-term conversational memory, full conversation history
14.1.6 Rewinding the state to a past checkpoint
This section uses a manual checkpoint rewind to show how LangGraph restores conversational context for a follow-up turn.
- Checkpoint state history: Describe what appears in LangGraph’s state history and what a checkpoint snapshot contains.
Why it matters: Inspecting snapshots lets you see which conversation and execution context a checkpoint can restore. - Restoring conversational context: Trace the manual rewind from a saved checkpoint to a context-dependent follow-up, and explain how it relates to subsequent turns using the same thread_id.
Why it matters: It explains why a follow-up can refer to something said before without restating it.
Key terms: state history, StateSnapshot, checkpoint, START node, checkpointer, thread_id, checkpoint_id, rehydrate, short-term conversational memory
14.2 Guardrails
This section explains what guardrails do, the main ways they make checks, and where those checks can fit in an agent workflow.
- Guardrail purpose and response: Explain how guardrails keep an agent within its intended scope and policies, and describe what can happen when a check fails.
Why it matters: This is the reason a travel assistant can stay focused on travel instead of responding to unrelated requests. - Three guardrail approaches: Distinguish rule-based, retrieval-based, and model-based guardrails by what each uses to make a check.
Why it matters: The three categories show that guardrails need not all rely on the agent’s main language model. - Guardrail workflow placement: Describe the four points in an agent workflow where guardrail checks can be applied and what each checks.
Why it matters: Where a check sits determines whether it prevents an LLM call, filters an answer, controls routing, or blocks a tool action.
Key terms: guardrails, validation layers, rule-based, retrieval-based, model-based, pre-model checks, post-model checks, routing-stage checks, tool-level checks
14.2.1 Implementing guardrails to reject nontravel-related questions
This section adds a domain-relevance guardrail to a UK travel assistant so nontravel questions receive a refusal before reaching downstream agents.
- Early domain filtering benefits: Explain why the assistant checks whether a question is travel-related before agent reasoning: rejecting unrelated questions reduces inaccurate answers and unnecessary LLM use.
Why it matters: Filtering early protects answer quality and avoids spending resources on questions the assistant is not meant to handle. - Structured guardrail policy: Describe how the lightweight LLM classifier makes a structured travel-relevance decision and what roles the policy components play.
Why it matters: A clearly defined, structured decision gives the router a consistent basis for accepting or refusing a question. - Router refusal and exit path: Trace how the router handles a failed versus a passed guardrail check, including the refusal message, state update, and early exit through the graph.
Why it matters: The graph’s early-exit path ensures rejected requests never consume downstream agent work.
Key terms: domain relevance check, prefilter, in-scope, GuardrailDecision, is_travel, reason, GUARDRAIL_SYSTEM_PROMPT, REFUSAL_INSTRUCTION, llm_guardrail, router agent
14.2.2 Implementing more restrictive guardrails at the agent level
This section adds Cornwall-specific input guardrails to two agents, supplementing the router’s broader travel filter.
- Layered input guardrails: Explain why each agent needs its own input guardrail even when the chatbot has a router-level guardrail. Distinguish the router’s early filter from the agents’ narrower checks.
Why it matters: A check at the chatbot entrance cannot always protect an agent used on its own. - Cornwall-specific agent policy: Explain the permitted scope for the travel information and accommodation booking agents and why the restriction applies to each.
Why it matters: The agent-level policy matches what the agents are meant or able to handle. - Pre-model refusal filter: Trace how pre_model_guardrail processes an agent’s input and how it is attached to both agents.
Why it matters: This filter lets each agent reject requests beyond its coverage before its LLM handles them.
Key terms: router-level, agent-level, input guardrails, fail-fast filter, Cornwall, travel information agent, accommodation booking agent, vector store, pre_model_guardrail(), pre_model_hook
14.3 Beyond this chapter
This section explains that memory and guardrails are important for production-ready agents, but deployment may require further work depending on the application.
- Production readiness beyond basics: Explain why memory and guardrails may not be enough before deploying an AI agent to real users. Additional considerations depend on the application’s domain, scale, and compliance requirements.
Why it matters: It helps you avoid treating memory and guardrails as a complete deployment checklist.
Key terms: memory, guardrails, production-ready, domain, scale, compliance requirements
14.3.1 Long-term user and application memory
This section contrasts session-limited memory with persistent memory and identifies the benefits and planning challenges of retaining user information over time.
- Persistent memory and personalization: Explain how long-term memory differs from short- to medium-term memory and why a production agent might retain user information over time.
Why it matters: The retention period and purpose of memory change what an agent can remember about a returning user. - Long-term memory planning challenges: Describe the example provisions and challenges the section identifies for persistent user memory, without assuming a particular implementation.
Why it matters: Remembering users over time requires planning for manageable storage and responsible handling of personal information.
Key terms: short- to medium-term memory, long-term memory, personalization, dedicated vector stores, summarization and pruning, personally identifiable information (PII), privacy and compliance controls
14.3.2 Human-in-the-loop
This section explains when a travel assistant should involve a human expert and how human review can improve the assistant over time.
- Human review for uncertain requests: Explain when the Cornwall travel assistant should escalate a request to a human travel expert and when that review occurs.
Why it matters: Human review helps the assistant avoid giving an unreliable answer when a request needs judgment or verification. - Production feedback from human reviews: Describe why human review is especially useful in early production and how its findings can reduce future escalations.
Why it matters: Expert review can both catch problems now and show developers where the assistant needs improvement.
Key terms: human-in-the-loop, escalated, human travel expert, early production deployments, human reviews, guardrails, automated policies
14.3.3 Post-model guardrails
This section explains how post-model guardrails check a travel assistant’s output before it reaches a user or downstream service.
- Post-model guardrail role: Distinguish post-model guardrails from the pre-model guardrails used earlier in the chapter, and explain why output needs a final check even when an LLM answer looks reasonable.
Why it matters: A relevant request can still produce an answer that should not be delivered unchanged. - Travel output checks: Describe the kinds of output problems post-model guardrails could catch in the Cornwall-focused travel assistant, using the section’s examples.
Why it matters: These examples show that a final check can address more than factual accuracy.
Key terms: post-model guardrails, final safety net, downstream service, filtering outdated or incorrect details, redacting sensitive information, brand tone and style, verifying structured output
14.3.4 Evaluation of AI agents and applications
This section explains what to evaluate in a production travel assistant and why evaluation must continue after launch.
- Four evaluation dimensions: Distinguish functional, behavioral, performance, and regression testing for the Cornwall travel assistant, including what each checks.
Why it matters: These checks reveal different kinds of failures that a single answer-quality test could miss. - Continuous production evaluation: Explain why evaluation belongs both on the preproduction checklist and in ongoing operation, rather than treating memory and guardrails as sufficient for production readiness.
Why it matters: An assistant that works at launch can still become unreliable as its system or the world around it changes.
Key terms: functional testing, behavioral testing, performance testing, regression testing, ground truths, systematic evaluation, continuous evaluation, production readiness
14.3.5 Deployment on the LangGraph platform and Open Agent Platform
This section compares deployment paths for production agents and explains how infrastructure and compliance needs shape the choice between managed hosting and greater operational control.
- Deployment model tradeoffs: Explain how infrastructure strategy, privacy and compliance policies, and operational preferences affect agent deployment. Describe the choice between managed SaaS hosting and deployment in an organization’s own cloud environment.
Why it matters: The right production setup depends as much on organizational constraints as on agent functionality. - LangGraph Platform hosting: Describe what LangGraph Platform provides when deploying a LangGraph-based agent system and why it can ease the move from prototype to production.
Why it matters: Managed hosting can make a production agent easier to scale and operate without giving up visibility into its behavior. - Open Agent Platform orchestration: Describe OAP’s role as a runtime and orchestration layer, including how its extensible agent patterns and integrations support coordinated enterprise agents.
Why it matters: OAP is particularly relevant when an organization needs to extend and coordinate several agents rather than only host one application.
Key terms: SaaS, data residency, compliance, client’s own cloud environment, LangGraph Platform, horizontal scalability, persistent state management, LangSmith, Open Agent Platform, OAP
14.4 Summary
The summary connects conversational memory, guardrails, and production practices that help agents resume work, stay within scope, and operate reliably.
Concepts explained in this chapter
- guardrailA guardrail is a constraint or control that limits model behavior to satisfy safety, quality, or policy requirements.
- dialogueA chat message history is an ordered collection of user and language-model messages representing a conversation.
- checkpointerA checkpointer is a component that saves and restores workflow state, including conversational information, across executions or interactions.
- checkpointingA checkpoint is a designated point in a process at which its state or progress is recorded or evaluated, often to support recovery, continuation, or control.
- memoryMemory is stored information that an agent or application can retain and use across steps or interactions.
- pre-model hookA pre-model hook is a callback that runs before a language model invocation and can inspect or modify the model input.
- human-in-the-loopHuman-in-the-loop is a system pattern in which people provide input, judgment, review, or intervention within an automated process.
- llm classificationLLM classification is the use of a large language model to assign an input to one of several specified categories.
- nodeA node is a LangGraph workflow component that performs processing by reading the current state and returning state updates.
- routingA router function is a callable that examines workflow conditions and returns the name of the next execution path.
- conversational aiA chatbot is a conversational software interface that maintains context across multiple exchanges for dialogue and interactive question answering.
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.
