Skip to content

Commit fcc8c4c

Browse files
committed
Improve null handling for encrypted in reasoning messages and refactor Message.Reasoning constructor for multi-part content
1 parent 6068b56 commit fcc8c4c

File tree

4 files changed

+13
-4
lines changed
  • prompt
    • prompt-executor/prompt-executor-clients
    • prompt-model/src/commonMain/kotlin/ai/koog/prompt/message

4 files changed

+13
-4
lines changed

prompt/prompt-executor/prompt-executor-clients/prompt-executor-anthropic-client/src/commonMain/kotlin/ai/koog/prompt/executor/clients/anthropic/AnthropicLLMClient.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ public open class AnthropicLLMClient(
329329
AnthropicMessage.Assistant(
330330
content = listOf(
331331
AnthropicContent.Thinking(
332-
signature = message.encrypted!!,
332+
signature = message.encrypted
333+
?: error("Encrypted signature is required for reasoning messages but was null"),
333334
thinking = message.content
334335
)
335336
)

prompt/prompt-executor/prompt-executor-clients/prompt-executor-bedrock-client/src/jvmMain/kotlin/ai/koog/prompt/executor/clients/bedrock/modelfamilies/anthropic/BedrockAnthropicClaudeSerialization.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ internal object BedrockAnthropicClaudeSerialization {
6666
BedrockAnthropicInvokeModelMessage.Assistant(
6767
content = listOf(
6868
BedrockAnthropicInvokeModelContent.Thinking(
69-
signature = msg.encrypted!!,
69+
signature = msg.encrypted
70+
?: error("Encrypted signature is required for reasoning messages but was null"),
7071
thinking = msg.content
7172
)
7273
)

prompt/prompt-executor/prompt-executor-clients/prompt-executor-openai-client-base/src/commonMain/kotlin/ai/koog/prompt/executor/clients/openai/base/AbstractOpenAILLMClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public abstract class AbstractOpenAILLMClient<TResponse : OpenAIBaseLLMResponse,
284284
is Message.Reasoning -> {
285285
flushPendingCalls()
286286
messages += OpenAIMessage.Assistant(
287-
content = Content.Text(message.content),
287+
content = OpenAIContent.Text(message.content),
288288
reasoningContent = message.content
289289
)
290290
}

prompt/prompt-model/src/commonMain/kotlin/ai/koog/prompt/message/Message.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,16 @@ public sealed interface Message {
176176
public data class Reasoning(
177177
public val id: String? = null,
178178
public val encrypted: String? = null,
179-
override val content: String,
179+
override val parts: List<ContentPart>,
180180
override val metaInfo: ResponseMetaInfo
181181
) : Response {
182+
183+
/**
184+
* Single content part reasoning message constructor
185+
*/
186+
public constructor(id: String? = null, encrypted: String? = null, content: String, metaInfo: ResponseMetaInfo) :
187+
this(id, encrypted, listOf(ContentPart.Text(content)), metaInfo)
188+
182189
override val role: Role = Role.Reasoning
183190

184191
override fun copy(updatedMetaInfo: ResponseMetaInfo): Reasoning = this.copy(metaInfo = updatedMetaInfo)

0 commit comments

Comments
 (0)