Skip to content

fix: support message content - #16980

Merged
yuzhichang merged 3 commits into
infiniflow:mainfrom
Haruko386:major
Jul 16, 2026
Merged

yuzhichang merged 3 commits into
infiniflow:mainfrom
Haruko386:major

Conversation

@Haruko386

@Haruko386 Haruko386 commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Summary

 ____________________
< I do this for 5 hrs >
 --------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

As Title
image

@Haruko386 Haruko386 added 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration labels Jul 16, 2026
@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jul 16, 2026
@Haruko386
Haruko386 marked this pull request as draft July 16, 2026 06:26
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bcde8064-1cd4-4338-a384-2683f899d7c2

📥 Commits

Reviewing files that changed from the base of the PR and between 04dd3df and e3228d1.

📒 Files selected for processing (1)
  • internal/agent/component/agent.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/agent/component/agent.go

📝 Walkthrough

Walkthrough

The PR adds reasoning-aware model streaming, structured thinking/message events, simplified message component streaming, and handler-owned SSE completion. Runner channels can close without emitting done; handlers now append the final [DONE] frame.

Changes

Agent reasoning and streaming

Layer / File(s) Summary
Thinking data contracts
internal/agent/runtime/context.go, internal/entity/models/*, internal/agent/component/llm.go, internal/agent/component/agent_test.go
Reasoning deltas, callbacks, response fields, and "thinking" outputs are propagated through runtime, model, and LLM component contracts.
ReAct agent streaming
internal/agent/component/agent.go
The ReAct agent consumes streamed model chunks, forwards content and reasoning deltas, supports thinking parameters, and prevents duplicate emissions.
Structured message events
internal/service/agent.go, internal/service/agent_test.go
Agent message events represent thinking boundaries, inline <think> sections, chunked content, and guarded final emission.

Message and SSE stream contracts

Layer / File(s) Summary
Message component stream contract
internal/agent/component/message.go, internal/agent/component/message_test.go
Template resolution errors are returned, memory ID fallback is removed, and streaming emits one content chunk without streamed_chunks or a done marker.
SSE completion contract
internal/agent/canvas/runner.go, internal/handler/agent.go, internal/handler/agent_test.go, internal/service/bot_completion.go, internal/service/*_test.go
Runner channels close after terminal events, handlers synthesize missing done events, and SSE completion uses data:[DONE]\n\n.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Model as EinoChatModel
  participant Agent as AgentComponent
  participant Runtime as RuntimeEmitter
  participant Service as AgentService
  participant Handler as SSEHandler
  Model->>Agent: stream content and reasoning
  Agent->>Runtime: emit deltas
  Runtime->>Service: forward agent message events
  Service->>Handler: write structured SSE events
  Handler->>Handler: append done after channel close
Loading

Possibly related PRs

Suggested labels: agent, 🧪 test

Suggested reviewers: yuzhichang

Poem

I twitch my nose as thoughts stream bright,
Reason hops beside reply,
SSE waits till channels close,
Then sends [DONE] across the sky.
Hop, hop—clean events fly!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only says 'As Title' and lacks the required summary and background context from the template. Add a brief Summary describing the bug, what behavior changed, and any relevant background so reviewers understand why this PR exists.
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: adding message content support and related streaming/thinking updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Haruko386
Haruko386 marked this pull request as ready for review July 16, 2026 06:26

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/handler/agent.go (1)

405-420: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Make the handler the sole owner of the final terminator.

Producer done events are currently written immediately. If one arrives before another queued event, clients stop at [DONE] and miss the trailing event. Skip producer done events and unconditionally write exactly one terminator after the channel closes.

Proposed completion handling
-	doneSent := false
 	for ev := range events {
 		if ev.Type == "done" {
-			doneSent = true
+			continue
 		}
 		if err := service.WriteChatbotRunEvent(c.Writer, ev); err != nil {
 			return
 		}
 	}
-	if !doneSent {
-		_ = service.WriteChatbotRunEvent(c.Writer, canvas.RunEvent{Type: "done"})
-	}
+	_ = service.WriteChatbotRunEvent(c.Writer, canvas.RunEvent{Type: "done"})

As per coding guidelines, “Prefer deletion over compatibility shims, deprecated branches, wrapper APIs, and dual-track migration notes; converge coexisting implementations to one path unless an external contract requires compatibility.”

Also applies to: 1031-1072

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/handler/agent.go` around lines 405 - 420, The event loop in the
handler should not forward producer-generated "done" events. Update the flow
around doneSent and WriteChatbotRunEvent to skip those events, then
unconditionally write exactly one final RunEvent with Type "done" after the
events channel closes, preserving client-disconnect handling.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/agent/canvas/runner.go`:
- Around line 48-49: Update the comments at
internal/agent/canvas/runner.go:48-49 to state that the HTTP/SSE handler appends
the terminator after channel closure, removing the Python migration reference;
update internal/agent/runtime/context.go:41-42 to describe the marker as
tracking streamed Agent message chunks; and update
internal/entity/models/types.go:175-178 to describe the current canvas consumer
behavior without Python comparisons.

In `@internal/agent/component/agent.go`:
- Around line 242-257: Replace the canvas-wide AgentMessageEventsEmittedKey
usage in the Agent streaming and fallback emission paths with state scoped to
the current Agent invocation or node, so each Agent can emit independently.
Update all corresponding checks and writes, including the additional paths noted
in the comment, and add a regression test that runs two sequential Agent
components and verifies both produce visible output.

In `@internal/service/agent.go`:
- Around line 98-143: Update makeAgentMessageDeltaEmitter to process both
thinkingDelta and contentDelta in the same callback instead of returning after
reasoning, preserving their streaming order and buffered inline content. Return
an EOF finalizer that closes any active thinking phase and flushes remaining
ThinkStreamState content, and invoke it before message_end; add coverage for
combined deltas and streams ending immediately after reasoning.

---

Outside diff comments:
In `@internal/handler/agent.go`:
- Around line 405-420: The event loop in the handler should not forward
producer-generated "done" events. Update the flow around doneSent and
WriteChatbotRunEvent to skip those events, then unconditionally write exactly
one final RunEvent with Type "done" after the events channel closes, preserving
client-disconnect handling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: de4a48ec-ddc4-4d8a-bddd-a65afc7ae523

📥 Commits

Reviewing files that changed from the base of the PR and between 92ae4f6 and 5a5e8fc.

📒 Files selected for processing (16)
  • internal/agent/canvas/runner.go
  • internal/agent/component/agent.go
  • internal/agent/component/agent_test.go
  • internal/agent/component/llm.go
  • internal/agent/component/message.go
  • internal/agent/component/message_chunked_test.go
  • internal/agent/component/message_test.go
  • internal/agent/runtime/context.go
  • internal/entity/models/llm.go
  • internal/entity/models/types.go
  • internal/handler/agent.go
  • internal/handler/agent_test.go
  • internal/service/agent.go
  • internal/service/agent_run_e2e_test.go
  • internal/service/agent_test.go
  • internal/service/bot_completion.go
💤 Files with no reviewable changes (1)
  • internal/agent/component/message_chunked_test.go

Comment thread internal/agent/canvas/runner.go Resolved
Comment thread internal/agent/component/agent.go Resolved
Comment thread internal/service/agent.go Resolved
@yuzhichang

Copy link
Copy Markdown
Member

LGTM

@yuzhichang
yuzhichang merged commit 101155b into infiniflow:main Jul 16, 2026
3 checks passed
@Haruko386
Haruko386 deleted the major branch July 16, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants