diff --git a/README.md b/README.md index 53f022937eac2..a2c584c56907c 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@

-LangChain is a framework for building agents and LLM-powered applications. It helps you chain together interoperable components and third-party integrations to simplify AI application development — all while future-proofing decisions as the underlying technology evolves. +LangChain is a framework for building agents and LLM-powered applications. It helps you chain together interoperable components and third-party integrations to simplify AI application development — all while future-proofing decisions as the underlying technology evolves. ```bash pip install langchain diff --git a/libs/langchain_v1/langchain/agents/factory.py b/libs/langchain_v1/langchain/agents/factory.py index cdbb44db0d7d5..2065272dd30fa 100644 --- a/libs/langchain_v1/langchain/agents/factory.py +++ b/libs/langchain_v1/langchain/agents/factory.py @@ -1424,15 +1424,17 @@ def _resolve_jump( def _fetch_last_ai_and_tool_messages( messages: list[AnyMessage], ) -> tuple[AIMessage, list[ToolMessage]]: - last_ai_index: int - last_ai_message: AIMessage - + last_ai_index: int | None = None + last_ai_message: AIMessage | None = None for i in range(len(messages) - 1, -1, -1): if isinstance(messages[i], AIMessage): last_ai_index = i last_ai_message = cast("AIMessage", messages[i]) break + if last_ai_message is None or last_ai_index is None: + raise ValueError("No AIMessage found in messages list") + tool_messages = [m for m in messages[last_ai_index + 1 :] if isinstance(m, ToolMessage)] return last_ai_message, tool_messages