Skip to content

Conversation

@gowtham1412-p
Copy link

@gowtham1412-p gowtham1412-p commented Nov 2, 2025

Fixes the UnboundLocalError in _fetch_last_ai_and_tool_messages function where variables last_ai_index and last_ai_message were used before being assigned when no AIMessage exists in the messages list.

Changes

  • Initialize last_ai_index and last_ai_message to None
  • Add validation to raise a clear ValueError if no AIMessage is found
  • Prevents UnboundLocalError and provides better error messaging

Issue

Fixes #33696

Dependencies

None

Testing

  • Ran make format, make lint, and make test from libs/langchain_v1
  • All tests pass

@github-actions github-actions bot added documentation Improvements or additions to documentation langchain Related to the package `langchain` v1 Issue specific to LangChain 1.0 labels Nov 2, 2025
@gowtham1412-p gowtham1412-p changed the title Fix issue 33696 fix(langchain_v1): initialize variables in _fetch_last_ai_and_tool_messages Nov 2, 2025
@github-actions github-actions bot added fix documentation Improvements or additions to documentation and removed documentation Improvements or additions to documentation fix labels Nov 2, 2025
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Nov 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation fix langchain Related to the package `langchain` v1 Issue specific to LangChain 1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create_agent with tools fail as final LLM call does not happen and it errors out with UnboundLocalError

1 participant