Skip to content

Conversation

@Dwij1704
Copy link
Member

@Dwij1704 Dwij1704 commented Mar 22, 2025

📥 Pull Request

📘 Description
This PR introduces the LangChain callback handlers support to Agentops

Changes Summary

  • Classified the LangChain callbacks into two classes:
    • LangchainCallbackHandler (sync version)
    • AsyncLangchainCallbackHandler (async version)
  • Fixed parent-child relationships between spans by properly passing context

Implementation Details

Trace Hierarchy

The handler properly maintains a hierarchical trace structure:

  • Session spans act as the root for all operations
  • Chain spans are children of the session or other chain spans
  • LLM spans are children of their parent chain spans
  • Tool and agent spans maintain proper parent relationships

Delegation Pattern

Instead of duplicating code, the async handler delegates to the sync handler:

  • Maintains the same functionality across sync and async callbacks
  • Simplifies maintenance as changes only need to be made in one place
  • Adds only minimal overhead while ensuring consistent behavior

🧪 Testing
Tested it with langchain example scripts, here are a few results:
Comprehensive Example
Agencyswarm Example

@codecov
Copy link

codecov bot commented Mar 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@dot-agi dot-agi self-requested a review March 24, 2025 05:12
@Dwij1704 Dwij1704 requested a review from tcdent March 24, 2025 18:45
…y functions and documentation, to streamline the AgentOps SDK. Updated semconv, excluded model provider info
@tcdent
Copy link
Contributor

tcdent commented Mar 24, 2025

Nice! Looks good to me.

@the-praxs did you get a chance to test this?

@dot-agi
Copy link
Member

dot-agi commented Mar 24, 2025

Haven't tested after the latest commit.

But since you approved it I am happy to approve and get this merged.

Copy link
Member

@dot-agi dot-agi left a comment

Choose a reason for hiding this comment

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

YOLO

@dot-agi dot-agi merged commit f978c1a into main Mar 24, 2025
8 of 10 checks passed
@dot-agi dot-agi deleted the add-langchanin-callback-handler branch March 24, 2025 23:27
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.

Update LangChain Callback Handlers for v4

4 participants