Closed
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
Greptile OverviewGreptile SummaryThis PR implements proper persistence of tool calls to conversation memory in OpenAI-compatible format. The changes enable the system to save and restore complete conversation turns including tool invocations and their results. Key Changes:
Additional Fix:
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant Agent
participant Provider
participant Memory
participant Tool
User->>Agent: Send message with tools enabled
Agent->>Memory: Load conversation history
Memory-->>Agent: Return messages (grouped by turns)
Agent->>Provider: Send request with sanitized messages
Note over Provider: sanitizeMessagesForProvider()<br/>removes orphaned tool calls/results
Provider->>Provider: Generate response with tool_calls
Provider-->>Agent: Response with tool_calls array
Agent->>Agent: buildMessagesForMemory()
Note over Agent: Create assistant message<br/>with tool_calls array
Agent->>Memory: Persist assistant message with tool_calls
loop For each tool call
Agent->>Tool: Execute tool with arguments
Tool-->>Agent: Tool result
Agent->>Agent: Create tool role message
Note over Agent: Include tool_call_id and name
Agent->>Memory: Persist tool result message
end
Agent->>Provider: Continue with tool results
Provider->>Provider: Generate final response
Provider-->>Agent: Final assistant message
Agent->>Agent: buildMessagesForMemory()
Agent->>Memory: Persist final assistant message
Agent-->>User: Return complete response
|
Comment on lines
+110
to
+112
| input: typeof tc.function?.arguments === 'string' | ||
| ? JSON.parse(tc.function.arguments) | ||
| : tc.function?.arguments || tc.arguments || {}, |
Contributor
There was a problem hiding this comment.
logic: JSON.parse() can throw if tc.function.arguments is malformed JSON
Suggested change
| input: typeof tc.function?.arguments === 'string' | |
| ? JSON.parse(tc.function.arguments) | |
| : tc.function?.arguments || tc.arguments || {}, | |
| input: typeof tc.function?.arguments === 'string' | |
| ? (() => { try { return JSON.parse(tc.function.arguments) } catch { return {} } })() | |
| : tc.function?.arguments || tc.arguments || {}, |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/providers/anthropic/index.ts
Line: 110:112
Comment:
**logic:** `JSON.parse()` can throw if `tc.function.arguments` is malformed JSON
```suggestion
input: typeof tc.function?.arguments === 'string'
? (() => { try { return JSON.parse(tc.function.arguments) } catch { return {} } })()
: tc.function?.arguments || tc.arguments || {},
```
How can I resolve this? If you propose a fix, please make it concise.| * Remove orphaned tool messages that don't have a corresponding tool_calls message | ||
| * This prevents errors like "tool_result without corresponding tool_use" | ||
| */ | ||
| private removeOrphanedToolMessages(messages: Message[]): Message[] { |
Contributor
There was a problem hiding this comment.
style: removeOrphanedToolMessages() is defined but never called - appears to be dead code (functionality is now in sanitizeMessagesForProvider() from utils.ts)
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/executor/handlers/agent/memory.ts
Line: 254:254
Comment:
**style:** `removeOrphanedToolMessages()` is defined but never called - appears to be dead code (functionality is now in `sanitizeMessagesForProvider()` from utils.ts)
How can I resolve this? If you propose a fix, please make it concise.
Collaborator
|
Done in separate PR. #2515 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Save tool calls in messages array correctly.
Type of Change
Testing
Tested manually.
Checklist