Skip to content

Conversation

@hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Aug 29, 2025

Important

Enhance _convert_message_to_dict in CallbackHandler.py to capture tool_calls from AIMessage for improved traceability in LangChain workflows.

  • Behavior:
    • Modify _convert_message_to_dict in CallbackHandler.py to include tool_calls from AIMessage if present.
    • Ensures tool_calls are captured in the message dictionary for better traceability.
  • Misc:
    • Minor import reordering in client.py and prompt_cache.py for consistency.
    • Adjust docstring formatting in client.py for clear_prompt_cache() function.

This description was created by Ellipsis for cba05ab. You can customize this summary. It will automatically update as commits are pushed.


Disclaimer: Experimental PR review

Greptile Summary

This PR adds support for capturing tool_calls from AIMessage objects in the Langchain callback handler. The change modifies the _convert_message_to_dict method in langfuse/langchain/CallbackHandler.py to check if an AIMessage has tool_calls and includes them in the message dictionary when present.

The implementation adds a conditional block that checks for the existence of the tool_calls attribute, ensures it's not None, and verifies it has content before adding it to the message dictionary. This follows the established pattern used throughout the method for other optional message attributes.

This enhancement integrates with Langfuse's observability capabilities by ensuring that tool/function calling information from LangChain agents and chat models is properly captured and tracked. Modern LLM workflows increasingly rely on tool calling for complex tasks, and this data is essential for understanding agent behavior, debugging workflows, and maintaining comprehensive trace records. The change fits naturally into the existing message conversion logic and maintains backward compatibility.

Confidence score: 5/5

  • This PR is safe to merge with minimal risk
  • Score reflects simple, well-tested conditional logic following established patterns
  • No files require special attention

@hassiebp hassiebp changed the title Add tool_calls in AIMessage (#1314) fix(langchain): parse tool_calls from AIMessage Aug 29, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

@hassiebp hassiebp merged commit a23a34f into main Sep 2, 2025
10 checks passed
@hassiebp hassiebp deleted the add-tool-call-parsing branch September 2, 2025 14:02
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