Skip to content

fix: support categorize component in agent - #16966

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

yuzhichang merged 3 commits into
infiniflow:mainfrom
Haruko386:master

Conversation

@Haruko386

@Haruko386 Haruko386 commented Jul 16, 2026 •

Copy link
Copy Markdown
Member
 __________________________________________
< Main fix: Let go-be read query/sys.query >
 ------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

image

@Haruko386
Haruko386 requested a review from yuzhichang July 16, 2026 02:40
@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:L This PR changes 100-499 lines, ignoring generated files. label Jul 16, 2026
@Haruko386
Haruko386 marked this pull request as draft July 16, 2026 02:40
@Haruko386
Haruko386 marked this pull request as ready for review July 16, 2026 02:40
@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: c344a3f9-d6e0-437e-b400-9ef8f8071f09

📥 Commits

Reviewing files that changed from the base of the PR and between a75cf67 and f8a4d7a.

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

📝 Walkthrough

Walkthrough

Changes

Categorize model and prompt flow

Layer / File(s) Summary
Centralize chat model resolution
internal/agent/component/llm_credentials.go, internal/agent/component/agent.go, internal/agent/component/categorize.go, internal/agent/component/categorize_test.go
Shared model reference resolution now supplies model, driver, credentials, and base URL for agent and categorize invocations, with tenant-model coverage.
Build runtime categorize prompts
internal/agent/component/categorize.go, internal/agent/component/categorize_test.go
Categorize supports runtime and input queries, bounded history, dynamic category prompts, conditional “Other” instructions, and query form metadata.
Parse and wire category metadata
internal/agent/component/categorize.go, internal/agent/component/categorize_test.go
Category descriptions, examples, routes, query configuration, and message-history settings are parsed and registered into component parameters, with routing and prompt validation.

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

Sequence Diagram(s)

sequenceDiagram
  participant CategorizeComponent
  participant CanvasState
  participant resolveChatModelRef
  participant TenantModelStore
  participant ChatInvoker
  CategorizeComponent->>resolveChatModelRef: resolve model reference
  resolveChatModelRef->>TenantModelStore: load tenant model credentials
  TenantModelStore-->>resolveChatModelRef: model configuration
  CategorizeComponent->>CanvasState: resolve runtime query and history
  CategorizeComponent->>ChatInvoker: send system and user prompts
  ChatInvoker-->>CategorizeComponent: classification response
Loading

Possibly related PRs

Suggested labels: 💞 feature

Suggested reviewers: yuzhichang

Poem

I’m a rabbit with prompts in my paws,
Sorting bright labels by model-made laws.
Queries hop from the canvas with care,
Descriptions and examples bloom there.
Tenant keys guide the moonlit way—
Categorize cleanly, hoppy hooray!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is only an image and does not include the required ### Summary section or written context. Add a ### Summary section with the PR purpose and background; keep the image only as optional supporting context.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding categorize component support in agents.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

@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: 6

🤖 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/component/categorize.go`:
- Around line 194-198: Update the instruction-building logic around the category
prompt in the categorize flow to emit the “Use Other only when no other category
fits” guidance only when `Other` is present in `p.Categories`; omit that line
for category sets that do not allow `Other`, while preserving the remaining
instructions unchanged.
- Around line 519-525: Update the category metadata handling in
internal/agent/component/categorize.go at lines 519-525 and 334-341 so
category_description is parsed independently of explicit categories: always
merge descriptions, examples, and routes from metadata, while using
metadata.Names as the selected category list only when explicit categories are
absent; preserve explicitly configured categories when present.
- Line 38: Remove the unsupported MessageHistoryWindowSize setting and its
message_history_window_size configuration surface, including related parsing,
propagation, and defaults, since it currently has no effect on classification
invocation or prompt construction.
- Around line 211-232: The categorizeExamples function currently returns after
adding category examples, discarding p.Items. Remove the early return and append
each non-empty, trimmed item to lines after the categorized examples, preserving
the existing formatting and returning the combined result.
- Around line 235-241: Update buildCategorizePrompt to replace newline
characters with spaces rather than deleting them, preserving separation between
words in multiline queries while keeping the existing prompt formatting
unchanged.
- Around line 243-261: The direct input handling in resolveCategorizeQuery
should only return inputs["query"] when its string value is non-empty; when it
is empty, continue through the existing queryRef resolution so the default
sys.query input or state value is used.
🪄 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: 7ed960c2-898f-4c66-aa00-8c870be99d99

📥 Commits

Reviewing files that changed from the base of the PR and between 4518a58 and 8f5b679.

📒 Files selected for processing (4)
  • internal/agent/component/agent.go
  • internal/agent/component/categorize.go
  • internal/agent/component/categorize_test.go
  • internal/agent/component/llm_credentials.go

Comment thread internal/agent/component/categorize.go Resolved
Comment thread internal/agent/component/categorize.go Resolved
Comment thread internal/agent/component/categorize.go Resolved
Comment thread internal/agent/component/categorize.go Resolved
Comment thread internal/agent/component/categorize.go Resolved
Comment thread internal/agent/component/categorize.go Resolved

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Comment on lines +446 to +449
var err error
p.ModelID, p.Driver, p.APIKey, p.BaseURL, err = resolveChatModelRef(ctx, p.ModelID, p.Driver, p.APIKey, p.BaseURL)
if err != nil {
return nil, err

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Refactor: use a common func to convert modelID to model, instance, provider

return apiKey, baseURL
}

func resolveChatModelRef(ctx context.Context, modelID, driver, apiKey, baseURL string) (string, string, string, string, error) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

common method

Comment on lines +149 to +157
func (c *CategorizeComponent) GetInputForm() map[string]any {
return map[string]any{
"query": map[string]any{
"type": "line",
"name": "Query",
},
}
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

for debug

Comment thread internal/agent/component/categorize.go Resolved
Comment on lines +178 to +204

if len(p.CategoryDescriptions) > 0 {
b.WriteString("\nHere's description of each category:\n")
for _, c := range cats {
desc := strings.TrimSpace(p.CategoryDescriptions[c])
if desc == "" {
continue
}
b.WriteString("\n------\nCategory: ")
b.WriteString(c)
b.WriteString("\nDescription: ")
b.WriteString(desc)
b.WriteString("\n")
}
}

b.WriteString("\n---- Instructions ----\n")
b.WriteString("- Consider both explicit mentions and implied context\n")
b.WriteString("- Prioritize the most specific applicable category\n")
b.WriteString("- Return only the category name without explanations\n")
b.WriteString("- Use \"Other\" only when no other category fits\n")

examples := categorizeExamples(p, cats)
if len(examples) > 0 {
b.WriteString("\n---- Examples ----\n")
for _, line := range examples {
b.WriteString(line)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

system prompt for LLM

Comment thread internal/agent/component/categorize.go Resolved
Comment thread internal/agent/component/categorize.go Resolved
Comment thread internal/agent/component/categorize.go Resolved
Comment thread internal/agent/component/categorize.go Resolved
@yuzhichang

Copy link
Copy Markdown
Member

LGTM

@yuzhichang
yuzhichang merged commit f9a1fbf into infiniflow:main Jul 16, 2026
3 checks passed
@Haruko386
Haruko386 deleted the master branch July 16, 2026 11:16
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:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants