WeKnora/internal/models/chat
wizardchen b00bc84f35 fix(agent): pass reasoning_content back to providers that require it
MiMo and DeepSeek V3.2/V4 reject multi-turn requests in thinking mode
when the prior assistant message lacks reasoning_content with HTTP 400:
"The reasoning_content in the thinking mode must be passed back to the API."

Agent's ReAct loop is the worst-case scenario — every round produces tool
calls, exactly the case DeepSeek's docs specify reasoning_content MUST
participate in subsequent context.

Plumb reasoning_content through the full assistant-message round-trip:
- chat.Message / types.ChatResponse / types.AgentStep gain a
  reasoning_content field (AgentStep persists via the existing
  Message.AgentSteps jsonb column, no migration needed).
- streamLLMToEventBus accumulates reasoning chunks into
  result.ReasoningContent and surfaces it on the round's ChatResponse.
- engine.runReActIteration writes it onto AgentStep so cross-turn replay
  preserves it.
- observe.appendToolResults attaches it to the same-turn assistant
  message; agent_history.buildAssistantHistoryMessages does the same on
  cross-turn replay.
- RemoteAPIChat.ConvertMessages forwards it on assistant turns to
  openai.ChatCompletionMessage.ReasoningContent (already supported by
  go-openai); providers that don't recognize the field ignore it.

Tests cover the three boundaries: ConvertMessages serializes it for
upstream, appendToolResults preserves it within the same turn, and
buildAssistantHistoryMessages replays it across turns.

Scope is intentionally limited to Agent mode — KnowledgeQA's chat
pipeline and Anthropic's signed thinking_blocks are separate fixes that
require schema changes (rendered_content / thinking_blocks columns).

Fixes #1302
2026-05-13 12:29:10 +08:00
..
anthropic.go fix: support Anthropic gateway streaming 2026-05-13 00:14:23 +08:00
anthropic_test.go fix: support Anthropic gateway streaming 2026-05-13 00:14:23 +08:00
chat.go fix(agent): pass reasoning_content back to providers that require it 2026-05-13 12:29:10 +08:00
chat_provider_spec.go refactor: Simplify WeKnoraCloud request customization and message conversion 2026-04-23 17:52:43 +08:00
config_from_model_test.go feat(models): support custom HTTP headers across all remote model calls 2026-04-23 23:36:40 +08:00
image_resolve.go feat: enhance multimodal support and image handling 2026-03-16 02:26:47 +08:00
json_field_extractor.go feat: implement final_answer tool and enhance agent duration tracking 2026-03-09 11:46:56 +08:00
json_field_extractor_test.go feat: implement final_answer tool and enhance agent duration tracking 2026-03-09 11:46:56 +08:00
langfuse_wrapper.go feat(observability): integrate Langfuse for LLM token tracking and tracing 2026-04-24 10:29:19 +08:00
llm_debug.go feat(logger): implement LLM debug logging functionality 2026-04-16 23:15:02 +08:00
llm_debug_wrapper.go feat(logger): implement LLM debug logging functionality 2026-04-16 23:15:02 +08:00
ollama.go fix(ollama): adapt to ToolCallFunctionArguments struct API 2026-05-09 13:58:55 +08:00
remote_api.go fix(agent): pass reasoning_content back to providers that require it 2026-05-13 12:29:10 +08:00
remote_api_test.go fix(agent): pass reasoning_content back to providers that require it 2026-05-13 12:29:10 +08:00
sse_reader.go fix: ReadEvent incompatible sse data format 2026-04-20 22:29:38 +08:00
timeout_test.go fix(chat): LLM 兜底超时仅在上层无 deadline 时生效,并修复 ChatStream raw HTTP 路径的 cancel 泄漏 2026-05-10 00:16:12 +08:00