Repository navigation
feat: enhance message handling and checkpoint management in LangGraphAdapter - #82
Merged
Merged
Conversation
…Adapter - Added `run_messages` to `AdapterContext` to store ordered chat history for retries and resumes. - Updated `emit_message` method to include `tool_call_id` in the emitted message payload. - Introduced `_checkpoint_payload` function to structure checkpoint state without including messages. - Implemented `load_run_messages` in `RunService` to retrieve messages associated with a run. - Enhanced `RunExecutor` to load messages during run resumption. - Updated tests to verify message handling and checkpoint behavior. These changes improve the management of message history and checkpoint states, enhancing the robustness of the LangGraphAdapter's functionality.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Resumed/retried runs may send a different OpenAI message shape for tool-call assistant messages (empty string vs null content), risking behavioral divergence between fresh and resumed executions.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR decouples LangGraph checkpoint state from message history by persisting messages separately (and reloading them on retry/resume), while improving tool-call message fidelity (including tool_call_id) and adding checkpoint retention pruning logic to keep only the most relevant checkpoints.
Changes:
- Persist ordered run messages separately (via
message.createdevents →messagestable) and load them on retry/resume. - Emit tool-call-related message metadata (
tool_call_id,tool_calls) and omitmessagesfrom checkpointgraph_statevia_checkpoint_payload. - Add checkpoint retention/pruning logic in
RunService, plus new/updated tests to validate behavior.
File summaries
| File | Description |
|---|---|
| backend/app/adapters/base.py | Extends AdapterContext.emit_message payload to include tool_call_id. |
| backend/app/adapters/langgraph_adapter.py | Emits messages for tool-call rounds, and checkpoints only a “control-state” payload (no messages). |
| backend/app/runtime/messages.py | New helper to rebuild OpenAI-style messages from persisted Message rows. |
| backend/app/services/run_service.py | Persists tool_call_id, adds load_run_messages, and implements checkpoint retain/prune utilities. |
| backend/app/worker/executor.py | Loads persisted messages on resume/retry and passes them into AdapterContext. |
| backend/tests/test_langgraph_adapter.py | Updates resume tests to pass run_messages and asserts checkpoints omit messages; adds _checkpoint_payload test. |
| backend/tests/test_tool_failure_recovery.py | Reconstructs run messages from events (not checkpoints) and asserts checkpoints omit messages. |
| backend/tests/test_checkpoint_retention.py | New test verifying checkpoint pruning keeps latest + human/preserved checkpoints. |
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+12
to
+21
| payload: dict[str, Any] = {"role": msg.role, "content": msg.content} | ||
| if msg.name: | ||
| payload["name"] = msg.name | ||
| if msg.tool_call_id: | ||
| payload["tool_call_id"] = msg.tool_call_id | ||
| extra = msg.extra or {} | ||
| tool_calls = extra.get("tool_calls") | ||
| if tool_calls: | ||
| payload["tool_calls"] = tool_calls | ||
| return payload |
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.
run_messagestoAdapterContextto store ordered chat history for retries and resumes.emit_messagemethod to includetool_call_idin the emitted message payload._checkpoint_payloadfunction to structure checkpoint state without including messages.load_run_messagesinRunServiceto retrieve messages associated with a run.RunExecutorto load messages during run resumption.These changes improve the management of message history and checkpoint states, enhancing the robustness of the LangGraphAdapter's functionality.