Prompts in Nodes
System messages.
Where should the system prompt live? Usually not in the state. If it's in the state, it's stored with every conversation. Instead, the node adds it, just before calling the model.

- Where does the prompt go?
- Not in the state
- Added by the node
Adding the system prompt
The system prompt is a constant. The node puts it in front of the messages, only for the model call. The state stays clean. Run it. The answer follows the shop's rules, and the final state holds only the user message and the reply, with no system message.
from langchain.chat_models import init_chat_model
from langchain.messages import SystemMessage
from langgraph.graph import MessagesState, StateGraph, START
model = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0)
SYSTEM = SystemMessage("You are the Riverside Books assistant. One short sentence. "
"Always suggest visiting our shop in Bath.")
def chat(s: MessagesState):
return {"messages": [model.invoke([SYSTEM] + s["messages"])]}
b = StateGraph(MessagesState); b.add_node(chat); b.add_edge(START, "chat")
out = b.compile().invoke({"messages": [{"role": "user", "content": "Any tips for a rainy day?"}]})
print(out["messages"][-1].text.strip())
print("stored:", [m.type for m in out["messages"]])Cozy up with a good mystery novel from our shop in Bath. stored: ['human', 'ai']
Prompt placement
Adding the prompt in the node keeps state small, and lets you change the prompt without touching stored conversations. Different nodes can have different prompts, which is how one graph can hold several specialists.
| key | value |
|---|---|
| In the node | not the state |
| Change freely | old chats unaffected |
| Per node | different prompts |
| Specialists | one graph, many roles |
Summary
Add the system prompt inside the node, just before the model call. The state stays clean. Next, giving models tools inside a graph.
Key takeaways- [SYSTEM] + messages
- State stays clean
- Prompt per node