How to specify a dynamic system prompt in create_react_agent()? #2481
-
I want my system prompt to be dynamically constructed each time a new thread is created. A simple example would be:
I currently construct my graph with:
What is the easiest way to change this achieve my desired behavior? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@epistoteles def state_modifier(state):
system_prompt = """Today's date: {datetime.today().strftime('%Y-%m-%d')}<rest of the system prompt>"""
return [{"role": "system", "content": system_prompt}] + state["messages"] this actually allows passing more state variables into your prompt as well, for example if you have some state keys like hope this helps! |
Beta Was this translation helpful? Give feedback.
@epistoteles
state_modifier
can be a callable that takes a graph state and produces an input into the LLM, for example:this actually allows passing more state variables into your prompt as well, for example if you have some state keys like
user_info
etc, you can pass that information to the prompt as well. NOTE: if you need to add extra state keys tocreate_react_agent
, you'd need to also passstate_schema
parameter.hope this helps!