Fix _build_prompt receiving state dict instead of messages list
LangGraph passes the full agent state dict {"messages": [...]} to the
prompt callable, not just the messages list. Iterating a dict yields
its keys, so "messages" (the string) was getting appended to the LLM
input — causing the agent to respond as if the literal word "messages"
was the user's query.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1232,11 +1232,13 @@ if google_gmail_enabled:
|
||||
|
||||
|
||||
@RunnableLambda
|
||||
def _build_prompt(messages: list, config: RunnableConfig = None) -> list:
|
||||
def _build_prompt(state, config: RunnableConfig = None) -> list:
|
||||
"""Inject the per-request system prompt, replacing any prior system messages."""
|
||||
system_prompt = (
|
||||
(config or {}).get("configurable", {}).get("system_prompt", SIMBA_SYSTEM_PROMPT)
|
||||
)
|
||||
# LangGraph passes the full state dict {"messages": [...]}, not just the list
|
||||
messages = state["messages"] if isinstance(state, dict) else state
|
||||
non_system = [m for m in messages if not isinstance(m, SystemMessage)]
|
||||
return [SystemMessage(content=system_prompt)] + non_system
|
||||
|
||||
|
||||
Reference in New Issue
Block a user