fix: extract leading system messages for AI SDK calls#42
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Summary by CodeRabbit
WalkthroughThe PR adds normalization of initial system messages for LLM generation requests via a new normalizeGenerationInput function. Leading system messages are extracted from the messages array and placed into a top-level system field (string or SystemModelMessage/array), while non-leading system messages remain unchanged. generationInput construction now uses this normalization. Tests were added to verify leading-system extraction, cache key behavior based on original messages, and preservation of non-leading system messages. Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Normalizer as normalizeGenerationInput
participant Cache as Cache
participant LLM as LLM.generateText
Client->>Normalizer: provide generation input (messages, model, etc.)
Normalizer-->>Client: normalized input (messages, optional system)
Client->>Cache: lookup cache using original messages key
alt cache hit
Cache-->>Client: cached response
else cache miss
Client->>LLM: call generateText(normalized input)
LLM-->>Client: generated response
Client->>Cache: store response with original messages key
end
Client-->>Client: return response to caller
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
Summary
systemmessages only at AI SDK call construction timesystemfield forgenerateTextandstreamTextWhy
AI SDK warns when
systemmessages are passed insidemessages. This change keeps the original request messages intact for cache-key calculation, and only rewrites the outboundgenerationInputshape before calling the SDK.Verification
pnpm --dir ./project test:run -- test/llm/client.test.tspnpm --dir ./project typecheck