Reputation: 11
I’m working on a LangGraph-based agent and running into an issue with state management when using LangGraph Studio. Specifically, I’m getting a KeyError: 'RAG_attempts' when my agent hits a downstream node, even though the key ('RAG_attempts') is initialized in my AgentState module. After some debugging, it seems like the key isn't even being passed into the first node, which might be causing this issue downstream.
When I run the agent in LangGraph Studio, I get this error when it hits the evaluator node:
def evaluator(state: AgentState, *, config: RunnableConfig) -> dict:
print("⚙️ Current Process: evaluator")
configuration = AgentConfiguration.from_runnable_config(config)
reval_attempts = state["RAG_attempts"] # KeyError happens here
Error Message:
KeyError: 'RAG_attempts'
AgentState class for reference:
from dataclasses import dataclass, field
from typing import TypedDict, Annotated, List, Literal
from langchain_core.documents import Document
from langchain_core.messages import AnyMessage
from langgraph.graph import add_messages
@dataclass(kw_only=True)
class AgentState(TypedDict):
"""Represents the input state for the agent."""
messages: Annotated[List[AnyMessage], add_messages]
label: dict = field(default_factory=lambda: {"type": "general", "logic": ""})
document_evaluation: str = field(default="GOOD")
documents: List[Document] = field(default_factory=list)
search_results: str = field(default="")
RAG_attempts: int = field(default=0)
So Far:
Now, I looked at many examples on github, youtube, and langgraph documentation, and it looks like what I have is pretty standard. I create a state with the keys I want to follow through the graph, and declare it as such:
self.workflow = StateGraph(AgentState)
Would love some help figuring this out!
Upvotes: 1
Views: 60