How can I add System Message in Langgraph?

Hi @dhirajsuvarna ! Are you trying to add a System Message at runtime? In that case that would be the correct way

Otherwise you could define your system prompt somewhere in your project (could be outside of the node, LangSmith Prompt Hub etc) and invoke your model like

system_prompt = """
You are a helpful assistant.
"""

def my_node(state: State):
    ...
    response = llm.invoke([SystemMessage(system_prompt)] + state["messages"])

Example to manage the list of messages.

Let me know if it helped!

1 Like