Skip to content

Comments

feat(langchain): Add comprehensive ToolMessage support with metadata preservation#10

Merged
IBJunior merged 2 commits intomainfrom
feat/tool-message
Sep 13, 2025
Merged

feat(langchain): Add comprehensive ToolMessage support with metadata preservation#10
IBJunior merged 2 commits intomainfrom
feat/tool-message

Conversation

@IBJunior
Copy link
Member

@IBJunior IBJunior commented Sep 12, 2025

Summary

This PR enhances the LangChain adapter with comprehensive ToolMessage support and a robust metadata preservation system. The changes ensure that complex message types (tool calls, function calls, etc.) and their associated metadata are correctly preserved throughout compression workflows.

Changes Made

Core Enhancements

  • Enhanced LangChain adapter with comprehensive ToolMessage support
  • Metadata preservation system for maintaining message properties during compression
  • Content preservation for complex message types (tool calls, function calls, etc.)
  • Extended SlimContextMessage interface with optional metadata field
  • Smart Compression Timing - Added shouldAllowCompression to check when to compress history
  • Improved roundtrip fidelity for LangChain BaseMessage conversions

Key Features

  • Tool message conversion properly preserves tool_call_id and other tool-specific fields
  • Complex message content (arrays, objects) correctly preserved during compression
  • Message metadata fields (id, name, additional_kwargs, response_metadata) maintained throughout workflows
  • Fallback content preservation when extractContent cannot process complex content
  • Better type safety with proper TypeScript field types for message conversions

Version

  • Bumped to version 2.1.3
  • Updated CHANGELOG.md with comprehensive release notes
  • All changes are backward compatible

Backward Compatibility

Fully backward compatible - all existing code will continue to work without changes. The new metadata field is optional and only added when there are fields to preserve.

Related Issues

Addresses the need for better tool message support and metadata preservation in LangChain workflows, particularly for complex AI agent interactions involving tool calls and function calls.

Copilot AI review requested due to automatic review settings September 12, 2025 17:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the LangChain adapter with comprehensive ToolMessage support and introduces a metadata preservation system to maintain message properties during compression workflows. The key improvement is ensuring that complex message types with tool calls, function calls, and associated metadata are correctly preserved throughout the compression process.

Key Changes

  • Extended SlimContextMessage interface with optional metadata field for preserving message properties
  • Enhanced LangChain adapter with comprehensive ToolMessage handling and metadata preservation
  • Added fallback content preservation for complex message types when extractContent returns empty

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/interfaces.ts Added optional metadata field to SlimContextMessage interface
src/adapters/langchain.ts Enhanced message conversion with metadata preservation and ToolMessage support
tests/langchain.test.ts Added comprehensive test coverage for tool messages and metadata preservation
package.json Version bump to 2.1.3
CHANGELOG.md Added release notes for version 2.1.3

@IBJunior IBJunior requested a review from Copilot September 13, 2025 11:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.

@IBJunior IBJunior merged commit f4bf98c into main Sep 13, 2025
2 checks passed
@IBJunior IBJunior deleted the feat/tool-message branch September 13, 2025 11:54
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.

1 participant