The system prompt
create_agent puts the system prompt first in every model request and never stores it in the state, so a new prompt applies to the next call of every thread.
You save a conversation with a checkpointer, change the system prompt in your code, and resume the thread. The model follows the new prompt. You look for the old prompt in the saved state, and it is not there.
When you finish this section, you can say where the system prompt lives during a run and set it from runtime context. You can also find the prompt hub at the pin.
A string or a SystemMessage
System prompt: the instructions that go first in every model request of an agent.
The agents page says that the parameter takes a string or a SystemMessage, and that a prompt built at run time needs middleware. create_agent turns a string into a SystemMessage once, when it builds the graph.
Not in the state
The model node adds the system message to the request on each call. It does not write it to messages. Section 1.3 showed both halves of this. The model got system: You add numbers. first on both calls, and the final state held four messages with no SystemMessage:
"call": 2,
"messages": [
"system: You add numbers.",
"human: What is 2 + 3?",
"ai: calls add",
"tool: 5"
],Figure 3.7 draws the request that the model node builds. Three things follow from it.
- A checkpoint holds no prompt. A thread resumed by new code uses the new prompt from its next model call.
- Two agents can share one thread with two prompts. Each one sends its own prompt with the shared messages.
- The prompt costs input tokens on every call, because it is sent every time. Long prompts multiply with the number of steps.
A SystemMessage that you put in the input messages is different. It is a message, so add_messages stores it in the state, and every later call sends it again.
A prompt from runtime context
The dynamic_prompt decorator turns a function of the model request into middleware that sets the system prompt for each call. The kit reads the user name from the runtime context:
@dynamic_prompt
def by_user(request):
return f"You are helping {request.runtime.context['user']}."
…
out = create_agent(m, middleware=[by_user]).invoke(ask("hi, who are you helping?"), context={"user": "Ada"})The model got the prompt with the name filled in:
"messages": [
"system: You are helping Ada.",
"human: hi, who are you helping?"
]The model did not use the name. It answered Hi! I'm here to help you with any questions or tasks you might have. and more. A prompt sets what the model reads, not what it says.
For more control, a wrap_model_call middleware can read and replace the prompt of each request. The custom middleware page says to read and change the prompt through the system_message field of ModelRequest. Part 4 explains the middleware hooks and their order.
The prompt hub
The LangChain docs at commit 04d4d4a have no page on prompt templates for Python agents. The prompt hub moved to LangSmith. Its page says that the hub used to be the langchainhub package, which is now deprecated. The same page still shows from langchain_classic import hub, which is the legacy path that section 3.1 lists. Use the langsmith client to push and pull prompts, and pass the text to create_agent as a string.
LangChain (Python): langchain, langchain-core, langgraph, deepagents, langsmith 1.5.0 · c2f4036 · 2026-11-11 · Edition 2026.11