Future return state=Finished KeyError #227

Closed
opened 2026-02-20 17:32:44 -05:00 by yindo · 1 comment
Owner

Originally created by @KushagraSahu20012000 on GitHub (Sep 8, 2024).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph/LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph/LangChain rather than my code.
  • I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code

from langchain_openai import AzureChatOpenAI
from langgraph.graph import StateGraph, END,START

class AgentState(TypedDict):
    messages: Annotated[Sequence[BaseMessage], operator.add]
    next: str

def predict_name(names):
'''PROMPT'''
  return {"message":llm.invoke(input={names})}

def predict_address(address):
'''PROMPT'''
  return {"message":llm.invoke(input={address})}

def final_result(state:AgentState):
  messages = state["messages"]
  return {"messages":messages}

members = ["predict_address","predict_name]

supervisor_prompt = " my prompt "

options = ["FINISH"] + members
options = members
agent_scratchpad = []

function_def = {
    "name": "route",
    "description": "Select the next role.",
    "parameters": {
        "title": "routeSchema",
        "type": "object",
        "properties": {
            "next": {
                "title": "Next",
                "anyOf": [
                    {"enum": options},
                ],
            }
        },
        "required": ["next"],
    },
}

prompt = ChatPromptTemplate.from_messages(
    [
        ("system", supervisor_prompt),
        MessagesPlaceholder(variable_name="messages"),
        (
            "system",
            "Given the conversation above, who should act next?"
            " Or should we END? Select one of: {options}",
        ),
    ]
).partial(options=str(options), members=",".join(members),names=names, address=address)

supervisor_chain = (prompt | llm_model.bind_functions(functions=[function_def], function_call="route") | JsonOutputFunctionsParser())

workflow = StateGraph(AgentState)

workflow.add_node("Supervisor",supervisor_chain)
workflow.add_node("predict_address",predict_address)
workflow.add_node("predict_name",predict_name)
workflow.add_node("final_result",final_result)

conditional_map = {k: k for k in members}
conditional_map["final_result"] = "final_result"
workflow.add_conditional_edges("Supervisor", lambda x: x["next"], conditional_map)
workflow.add_edge(START, "Supervisor")
for member in members:
    # We want our workers to ALWAYS "report back" to the supervisor when done
    workflow.add_edge("Supervisor",member)
    workflow.add_edge(member,"final_result")
    workflow.add_edge("Supervisor",END)

app = workflow.compile()

graph_input = {"messages":[""]}

response = app.invoke(graph_input)

Error Message and Stack Trace (if applicable)

Exception has occurred: KeyError
<Future at 0x15f32aa50 state=finished raised KeyError>
  File "/create_langgraph.py", line 418, in CreateLanggraph
    response = app.invoke(graph_input)
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kushagrasahu/Documents/projects/SLAM-AI/src/ai_comment_generation/defect_impact.py", line 87, in predict_impact
    config_output, hardware_output, final_impact = CreateLanggraph(names, address)
                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: <Future at 0x15f32aa50 state=finished raised KeyError>

Description

Occurring When calling the function CreateLanggraph from another file. No error when running I interpreter (Notebook)

System Info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 23.5.0: Wed May 1 20:13:18 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6030
Python Version: 3.11.8 (v3.11.8:db85d51d3e, Feb 6 2024, 18:02:37) [Clang 13.0.0 (clang-1300.0.29.30)]

Package Information

langchain_core: 0.2.28
langchain: 0.2.12
langchain_community: 0.2.11
langsmith: 0.1.98
langchain_aws: 0.1.15
langchain_openai: 0.1.20
langchain_text_splitters: 0.2.2
langgraph: 0.2.3

Packages not installed (Not Necessarily a Problem)

The following packages were not found:

langserve

Originally created by @KushagraSahu20012000 on GitHub (Sep 8, 2024). ### Checked other resources - [X] I added a very descriptive title to this issue. - [X] I searched the [LangGraph](https://langchain-ai.github.io/langgraph/)/LangChain documentation with the integrated search. - [X] I used the GitHub search to find a similar question and didn't find it. - [X] I am sure that this is a bug in LangGraph/LangChain rather than my code. - [X] I am sure this is better as an issue [rather than a GitHub discussion](https://github.com/langchain-ai/langgraph/discussions/new/choose), since this is a LangGraph bug and not a design question. ### Example Code ```python from langchain_openai import AzureChatOpenAI from langgraph.graph import StateGraph, END,START class AgentState(TypedDict): messages: Annotated[Sequence[BaseMessage], operator.add] next: str def predict_name(names): '''PROMPT''' return {"message":llm.invoke(input={names})} def predict_address(address): '''PROMPT''' return {"message":llm.invoke(input={address})} def final_result(state:AgentState): messages = state["messages"] return {"messages":messages} members = ["predict_address","predict_name] supervisor_prompt = " my prompt " options = ["FINISH"] + members options = members agent_scratchpad = [] function_def = { "name": "route", "description": "Select the next role.", "parameters": { "title": "routeSchema", "type": "object", "properties": { "next": { "title": "Next", "anyOf": [ {"enum": options}, ], } }, "required": ["next"], }, } prompt = ChatPromptTemplate.from_messages( [ ("system", supervisor_prompt), MessagesPlaceholder(variable_name="messages"), ( "system", "Given the conversation above, who should act next?" " Or should we END? Select one of: {options}", ), ] ).partial(options=str(options), members=",".join(members),names=names, address=address) supervisor_chain = (prompt | llm_model.bind_functions(functions=[function_def], function_call="route") | JsonOutputFunctionsParser()) workflow = StateGraph(AgentState) workflow.add_node("Supervisor",supervisor_chain) workflow.add_node("predict_address",predict_address) workflow.add_node("predict_name",predict_name) workflow.add_node("final_result",final_result) conditional_map = {k: k for k in members} conditional_map["final_result"] = "final_result" workflow.add_conditional_edges("Supervisor", lambda x: x["next"], conditional_map) workflow.add_edge(START, "Supervisor") for member in members: # We want our workers to ALWAYS "report back" to the supervisor when done workflow.add_edge("Supervisor",member) workflow.add_edge(member,"final_result") workflow.add_edge("Supervisor",END) app = workflow.compile() graph_input = {"messages":[""]} response = app.invoke(graph_input) ``` ### Error Message and Stack Trace (if applicable) ```shell Exception has occurred: KeyError <Future at 0x15f32aa50 state=finished raised KeyError> File "/create_langgraph.py", line 418, in CreateLanggraph response = app.invoke(graph_input) ^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/kushagrasahu/Documents/projects/SLAM-AI/src/ai_comment_generation/defect_impact.py", line 87, in predict_impact config_output, hardware_output, final_impact = CreateLanggraph(names, address) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ KeyError: <Future at 0x15f32aa50 state=finished raised KeyError> ``` ### Description Occurring When calling the function CreateLanggraph from another file. No error when running I interpreter (Notebook) ### System Info System Information ------------------ > OS: Darwin > OS Version: Darwin Kernel Version 23.5.0: Wed May 1 20:13:18 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6030 > Python Version: 3.11.8 (v3.11.8:db85d51d3e, Feb 6 2024, 18:02:37) [Clang 13.0.0 (clang-1300.0.29.30)] Package Information ------------------- > langchain_core: 0.2.28 > langchain: 0.2.12 > langchain_community: 0.2.11 > langsmith: 0.1.98 > langchain_aws: 0.1.15 > langchain_openai: 0.1.20 > langchain_text_splitters: 0.2.2 > langgraph: 0.2.3 Packages not installed (Not Necessarily a Problem) -------------------------------------------------- The following packages were not found: > langserve
yindo closed this issue 2026-02-20 17:32:46 -05:00
Author
Owner

@nfcampos commented on GitHub (Sep 21, 2024):

This seems to be an issue in your code, we don't have a function called CreateLanggraph in the library. I'd suggest looking inside your CreateLanggraph function and figuring where in there you are hitting a KeyError (eg from accessing a key of a dictionary that isn't set)

@nfcampos commented on GitHub (Sep 21, 2024): This seems to be an issue in your code, we don't have a function called CreateLanggraph in the library. I'd suggest looking inside your CreateLanggraph function and figuring where in there you are hitting a KeyError (eg from accessing a key of a dictionary that isn't set)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#227