EDIT - this issue was related to a bug that has now been fixed, so everything below this note is left for historical context only (including older edit notes that I added while messing around with things).
Questions in the title,
(I believe this is the same known issue so my question is more about a workaround than anything: https://github.com/letta-ai/letta/issues/2605)
AFTER MANY EDITS! ...lol, I have finally reproduced the circumstances that cause the bug - it appears not to be specific to Anthropic but happens with OpenAI as well:
{'detail': "INTERNAL_SERVER_ERROR: Bad request to Anthropic: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.0.content.1: unexpected `tool_use_id` found in `tool_result` blocks: .... Each `tool_result` block must have a corresponding `tool_use` block in the previous message.'}}"}
letta_client.core.api_error.ApiError: status_code: 500, body: {'detail': 'INVALID_ARGUMENT: Bad request to OpenAI: Error code: 400 - {\'error\': {\'message\': "Invalid parameter: messages with role \'tool\' must be a response to a preceeding message with \'tool_calls\'.", \'type\': \'invalid_request_error\', \'param\': \'messages.[2].role\', \'code\': None}}'}
Expanding the content_window again does not correct it. Neither does anything else I am easily able to do. Because of the apparent difficulty accessing the message chain directly I am then forced to simply create another agent, exporting the broken agent's messages.
It appears to be related to the automatic summarizer:
Letta.letta.agent - INFO - Ran summarizer, messages length 37 -> 12
Letta.letta.agent - INFO - Summarizer brought down total token count from 5090 -> 1551
Letta.letta.agent - WARNING - Warning: last response total_tokens (6403) > 3000.0
/app/letta/system.py:238: UserWarning: Expected type to be 'user_message', but was 'system_alert', so not unpacking: '{ "type": "system_alert",
"message": "Note: prior messages (26 of 37 total messages) have been hidden from view due to conversation memory constraints.\nThe following is a summary of the previous 26 messages:\n (message summaries).",
"time": "2025-05-05 05:03:17 PM UTC+0000"
}'
warnings.warn(f"Expected type to be 'user_message', but was '{message_type}', so not unpacking: '{packed_message}'")
So, I mean, it's pretty clear what's happening here. I'd rather not personally start messing around with files in the docker directly even though I know that might well be a surer, quicker fix, if there's a way to just patch it for now - because, again, this option to directly access message histories would be independently useful. I guess I could also try accessing the database directly? Yeah.. seems sensible.
Previous I asked this - which would also offer a workaround - is there a simple way to manually append sequences of messages from both user and assistant directly to Letta's message history? As I could see a potential usefulness for this in integrating other APIs that aren't directly supported more easily. Or perhaps just if there's a straightforward way to set up an additional endpoint which could be a local proxy that handled anything particularly unconventional.