Skip to content
This repository was archived by the owner on May 21, 2026. It is now read-only.

Feat/tool history preservation - #40

Open
lightsblue wants to merge 3 commits into
mcp-use:mainfrom
lightsblue:feat/tool-history-preservation
Open

Feat/tool history preservation#40
lightsblue wants to merge 3 commits into
mcp-use:mainfrom
lightsblue:feat/tool-history-preservation

Conversation

@lightsblue

Copy link
Copy Markdown

Description

This implements comprehensive tool call history preservation for MCP agents, fixing a critical gap where tool execution information was lost between conversation turns. The root issue was that AIMessage objects were created with only text content, completely ignoring LangChain's tool_calls field and discarding all intermediateSteps data containing tool executions.

This was breaking stateful workflows - LLMs couldn't reference previous tool calls, leading to duplicate entity creation and workflow interruptions. For example, mentioning additional details about an injury would trigger creation of new assessments instead of continuing with existing ones.

The fix preserves complete tool call history in both stream() and streamEvents() methods using standard LangChain message patterns that createToolCallingAgent expects. Added comprehensive error handling, configurable output truncation, and memory safety measures for production use.

Depends on #39 (conversation memory duplication fix) as it builds upon those memory management improvements.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • The title of my pull request follows the conventional commits standard
  • Changes have been documented in the README/documentation (if applicable)

The only unchecked item is documentation since this is an internal fix that doesn't change the public API - the improvement is transparent to users but enables the LLM orchestration to work properly.

@lightsblue
lightsblue force-pushed the feat/tool-history-preservation branch from f264f85 to a59b81d Compare September 5, 2025 17:44
- Move user message addition from before to after LLM processing
- Prevents duplicate messages in conversation history
- Ensures chat_history only contains previous messages, not current
@lightsblue
lightsblue force-pushed the feat/tool-history-preservation branch from a59b81d to a814188 Compare September 5, 2025 17:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant