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:
2026-09-16 23:10:22 -04:00
parent 43e0de24d6
commit 19aa2b17d7
+3 -1
View File
@@ -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