-
Notifications
You must be signed in to change notification settings - Fork 41
Description
I often receive Assistant messages that have an empty .content field marked end turn and when I addMessage to add them to the chat history these messages fail to validate because they have an empty .content list.
I fixed this by removing these messages and not adding them back to the message params.
But not I'm using the websearch tool and I'm receiving WebSearchResultBlock with an empty .content field and these fail to validate as well. The WebSearchResultBlock has an .encrypted_content but not a content.
So basically the pattern of maintaining a chat session is broken.
It seems like message objects are too tightly specified in the JavaSDK and that the json form of these messages and search blocks would be accepted by the api?
This again also happens when an Assistant message has an empty content field.
com.anthropic/anthropic-java {:mvn/version "2.0.0"}
java.lang.IllegalStateException: `content` is required, but was not set
at com.anthropic.core.Check.checkRequired(Check.kt:12)
at com.anthropic.models.messages.WebSearchToolResultBlockParam$Builder.build(WebSearchToolResultBlockParam.kt:246)
at com.anthropic.models.messages.WebSearchToolResultBlock.toParam(WebSearchToolResultBlock.kt:39)
at com.anthropic.models.messages.ContentBlock$toParam$1.visitWebSearchToolResult(ContentBlock.kt:50)
at com.anthropic.models.messages.ContentBlock$toParam$1.visitWebSearchToolResult(ContentBlock.kt:36)
at com.anthropic.models.messages.ContentBlock.accept(ContentBlock.kt:108)
at com.anthropic.models.messages.ContentBlock.toParam(ContentBlock.kt:35)
at com.anthropic.models.messages.Message$toParam$1.invoke(Message.kt:55)
at com.anthropic.models.messages.Message$toParam$1.invoke(Message.kt:55)
at com.anthropic.core.JsonField.map$anthropic_java_core(Values.kt:197)
at com.anthropic.models.messages.Message.toParam(Message.kt:55)
at com.anthropic.models.messages.MessageCreateParams$Body$Builder.addMessage(MessageCreateParams.kt:1808)
at com.anthropic.models.messages.MessageCreateParams$Builder.addMessage(MessageCreateParams.kt:607)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:196)
at clojure.lang.Reflector.invokeInstanceMethodOfClass(Reflector.java:106)
at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:98)
at rebel_ai.llm.anthropic$send_message_tool_react_BANG_.invokeStatic(anthropic.clj:275)
And for the Assistant message
Error building MessageCreateParams or sending message
com.anthropic.errors.BadRequestException: 400: {type=error, error={type=invalid_request_error, message=messages.5: all messages must have non-empty content except for the optional final assistant message}}
at com.anthropic.errors.BadRequestException$Builder.build(BadRequestException.kt:74)
at com.anthropic.core.handlers.ErrorHandler$withErrorHandler$1.handle(ErrorHandler.kt:45)
at com.anthropic.services.blocking.MessageServiceImpl$WithRawResponseImpl$createStreaming$1.invoke(MessageServiceImpl.kt:142)
at com.anthropic.services.blocking.MessageServiceImpl$WithRawResponseImpl$createStreaming$1.invoke(MessageServiceImpl.kt:140)
at com.anthropic.core.http.HttpResponseForKt$parseable$1$parsed$2.invoke(HttpResponseFor.kt:14)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.anthropic.core.http.HttpResponseForKt$parseable$1.getParsed(HttpResponseFor.kt:14)
at com.anthropic.core.http.HttpResponseForKt$parseable$1.parse(HttpResponseFor.kt:16)
at com.anthropic.services.blocking.MessageServiceImpl.createStreaming(MessageServiceImpl.kt:52)
at com.anthropic.services.blocking.MessageService.createStreaming(MessageService.kt:51)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:196)
at clojure.lang.Reflector.invokeInstanceMethodOfClass(Reflector.java:106)
at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:98)
at rebel_ai.llm.anthropic$send_session_message.invokeStatic(anthropic.clj:207)
And in both of these cases I'm simply calling addMessage with the response from the MessageAccumulator back into the message params.