From de0896c54725462128e090738ed04305fab22d47 Mon Sep 17 00:00:00 2001 From: cthomas Date: Sat, 18 Oct 2025 17:43:30 -0700 Subject: [PATCH] fix: list index out of range empty message history (#5561) * fix: list index out of range empty message history * address kian comments --- letta/agents/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/letta/agents/helpers.py b/letta/agents/helpers.py index 7d81a6af..fa6e22cc 100644 --- a/letta/agents/helpers.py +++ b/letta/agents/helpers.py @@ -188,7 +188,7 @@ async def _prepare_in_context_messages_no_persist_async( # Check for approval-related message validation if len(input_messages) == 1 and input_messages[0].type == "approval": # User is trying to send an approval response - if current_in_context_messages[-1].role != "approval": + if current_in_context_messages and current_in_context_messages[-1].role != "approval": raise ValueError( "Cannot process approval response: No tool call is currently awaiting approval. " "Please send a regular message to interact with the agent." @@ -199,7 +199,7 @@ async def _prepare_in_context_messages_no_persist_async( ) else: # User is trying to send a regular message - if current_in_context_messages[-1].role == "approval": + if current_in_context_messages and current_in_context_messages[-1].role == "approval": raise PendingApprovalError(pending_request_id=current_in_context_messages[-1].id) # Create a new user message from the input but dont store it yet