Skip to content

feat: enhance message handling and checkpoint management in LangGraphAdapter - #82

Merged
Emiyaaaaa merged 1 commit into
Emiyaaaaa:mainfrom
LE0-Lin:feat/memory-0831
Sep 1, 2026
Merged

Emiyaaaaa merged 1 commit into
Emiyaaaaa:mainfrom
LE0-Lin:feat/memory-0831

Conversation

@LE0-Lin

@LE0-Lin LE0-Lin commented Sep 1, 2026

Copy link
Copy Markdown
Contributor
  • 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.

…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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.created events → messages table) and load them on retry/resume.
  • Emit tool-call-related message metadata (tool_call_id, tool_calls) and omit messages from checkpoint graph_state via _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
@Emiyaaaaa
Emiyaaaaa merged commit f1e0bcd into Emiyaaaaa:main Sep 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants