feat(kiro): implement official reasoningContentEvent and improve metadat

This commit is contained in:
Ravens2121
2025-12-18 04:38:22 +08:00
parent 0155a01bb1
commit d687ee2777
3 changed files with 431 additions and 477 deletions
File diff suppressed because it is too large Load Diff
@@ -222,20 +222,19 @@ func BuildKiroPayload(claudeBody []byte, modelID, profileArn, origin string, isA
kiroTools := convertClaudeToolsToKiro(tools) kiroTools := convertClaudeToolsToKiro(tools)
// Thinking mode implementation: // Thinking mode implementation:
// Kiro API doesn't accept max_tokens for thinking. Instead, thinking mode is enabled // Kiro API supports official thinking/reasoning mode via <thinking_mode> tag.
// by injecting <thinking_mode> and <max_thinking_length> tags into the system prompt. // When set to "enabled", Kiro returns reasoning content as official reasoningContentEvent
// We use a fixed max_thinking_length value since Kiro handles the actual budget internally. // rather than inline <thinking> tags in assistantResponseEvent.
// We use a high max_thinking_length to allow extensive reasoning.
if thinkingEnabled { if thinkingEnabled {
thinkingHint := `<thinking_mode>interleaved</thinking_mode> thinkingHint := `<thinking_mode>enabled</thinking_mode>
<max_thinking_length>200000</max_thinking_length> <max_thinking_length>200000</max_thinking_length>`
IMPORTANT: You MUST use <thinking>...</thinking> tags to show your reasoning process before providing your final response. Think step by step inside the thinking tags.`
if systemPrompt != "" { if systemPrompt != "" {
systemPrompt = thinkingHint + "\n\n" + systemPrompt systemPrompt = thinkingHint + "\n\n" + systemPrompt
} else { } else {
systemPrompt = thinkingHint systemPrompt = thinkingHint
} }
log.Infof("kiro: injected thinking prompt, has_tools: %v", len(kiroTools) > 0) log.Infof("kiro: injected thinking prompt (official mode), has_tools: %v", len(kiroTools) > 0)
} }
// Process messages and build history // Process messages and build history
@@ -231,20 +231,19 @@ func BuildKiroPayloadFromOpenAI(openaiBody []byte, modelID, profileArn, origin s
kiroTools := convertOpenAIToolsToKiro(tools) kiroTools := convertOpenAIToolsToKiro(tools)
// Thinking mode implementation: // Thinking mode implementation:
// Kiro API doesn't accept max_tokens for thinking. Instead, thinking mode is enabled // Kiro API supports official thinking/reasoning mode via <thinking_mode> tag.
// by injecting <thinking_mode> and <max_thinking_length> tags into the system prompt. // When set to "enabled", Kiro returns reasoning content as official reasoningContentEvent
// We use a fixed max_thinking_length value since Kiro handles the actual budget internally. // rather than inline <thinking> tags in assistantResponseEvent.
// We use a high max_thinking_length to allow extensive reasoning.
if thinkingEnabled { if thinkingEnabled {
thinkingHint := `<thinking_mode>interleaved</thinking_mode> thinkingHint := `<thinking_mode>enabled</thinking_mode>
<max_thinking_length>200000</max_thinking_length> <max_thinking_length>200000</max_thinking_length>`
IMPORTANT: You MUST use <thinking>...</thinking> tags to show your reasoning process before providing your final response. Think step by step inside the thinking tags.`
if systemPrompt != "" { if systemPrompt != "" {
systemPrompt = thinkingHint + "\n\n" + systemPrompt systemPrompt = thinkingHint + "\n\n" + systemPrompt
} else { } else {
systemPrompt = thinkingHint systemPrompt = thinkingHint
} }
log.Debugf("kiro-openai: injected thinking prompt") log.Debugf("kiro-openai: injected thinking prompt (official mode)")
} }
// Process messages and build history // Process messages and build history