-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(models): memory fixes, provider code typing, cost calculation cleanup #2515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(models): memory fixes, provider code typing, cost calculation cleanup #2515
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR refactors memory management, improves provider type safety, and consolidates cost calculation logic. The changes address three key areas: Memory Management Improvements
Provider Type Safety
Cost Calculation Consolidation
Issues Found
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant AgentHandler
participant Provider
participant MemoryService
participant Database
Client->>AgentHandler: execute(block, inputs)
AgentHandler->>AgentHandler: buildMessages()
alt Memory Enabled
AgentHandler->>MemoryService: fetchMemoryMessages()
MemoryService->>Database: SELECT data FROM memory
Database-->>MemoryService: existing messages
alt First Run (no existing)
AgentHandler->>MemoryService: seedMemory(conversationMessages)
MemoryService->>Database: INSERT memory record
else Existing Memory
alt New User Message
AgentHandler->>MemoryService: appendToMemory(userMessage)
MemoryService->>Database: UPDATE with array concat
end
end
end
AgentHandler->>Provider: executeProviderRequest()
alt Streaming Response
Provider-->>AgentHandler: StreamingExecution
alt Memory Enabled
AgentHandler->>MemoryService: wrapStreamForPersistence()
MemoryService-->>AgentHandler: wrapped stream
end
AgentHandler-->>Client: stream chunks
Note over MemoryService: Stream accumulates content
MemoryService->>MemoryService: flush() callback
MemoryService->>Database: UPDATE memory (append assistant message)
MemoryService->>Provider: calculate cost from usage
else Non-Streaming Response
Provider-->>AgentHandler: BlockOutput
Provider->>Provider: calculate cost from tokens
alt Memory Enabled
AgentHandler->>MemoryService: persistResponseToMemory()
MemoryService->>Database: UPDATE memory (append assistant)
end
AgentHandler-->>Client: complete response
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
39 files reviewed, 1 comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
52 files reviewed, 4 comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Comments (1)
-
apps/sim/providers/openai/utils.ts, line 37-39 (link)logic: warns if usage data missing, but still calls
onCompletewith zerosif OpenAI doesn't return usage tokens (which can happen in some edge cases or errors), cost calculation will be zero. this creates silent underreporting of costs rather than failing visibly.
consider whether this should throw or use token estimation as fallback. is zero-cost acceptable for streams without usage data, or should you estimate tokens from accumulated content?
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
54 files reviewed, 12 comments
90e9d4f to
5f6e7ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
115 files reviewed, 6 comments
Summary
Type of Change
Testing
Tested manually with all providers with streaming and no streaming for OpenAI, Anthropic, Gemini.
Checklist