Repository navigation
fix: support categorize component in agent - #16966
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughChangesCategorize model and prompt flow
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
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
internal/agent/component/agent.gointernal/agent/component/categorize.gointernal/agent/component/categorize_test.gointernal/agent/component/llm_credentials.go
| 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 |
There was a problem hiding this comment.
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) { |
| func (c *CategorizeComponent) GetInputForm() map[string]any { | ||
| return map[string]any{ | ||
| "query": map[string]any{ | ||
| "type": "line", | ||
| "name": "Query", | ||
| }, | ||
| } | ||
| } | ||
|
|
|
|
||
| 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) |
|
LGTM |
Uh oh!
There was an error while loading. Please reload this page.