Skip to content

Add LangChain callback handler integration #84

Description

@crtahlin

Motivation

LangChain is the most popular framework for building LLM-powered agents. Adding a provenance callback handler would let LangChain users add audit trails to their agents with a single line of code:

from datafund_provenance.integrations.langchain import ProvenanceCallbackHandler

handler = ProvenanceCallbackHandler(gateway_url="https://provenance-gateway.datafund.io")
llm = ChatOpenAI(callbacks=[handler])

This unlocks:

  • "One-line audit trails for LangChain agents" narrative (blog post + co-marketing with LangChain team)
  • Discovery via LangChain's integrations docs and community
  • Natural entry point for developers already building agents

Part of the fellowship marketing plan (Month 2, Week 5-6).

Requirements

Callback Handler

  • Implement ProvenanceCallbackHandler extending LangChain's BaseCallbackHandler
  • Log key events to provenance gateway:
    • on_llm_start / on_llm_end — capture prompts, completions, model info, token usage
    • on_chain_start / on_chain_end — capture chain execution with inputs/outputs
    • on_tool_start / on_tool_end — capture tool calls and results
    • on_agent_action / on_agent_finish — capture agent reasoning steps
  • Each event uploads a provenance record (JSON metadata → gateway → Swarm)
  • Support session/run grouping (link related events via run_id)
  • Optional notary signing for each record
  • Configurable: which events to log, verbosity level, async vs sync

Packaging

  • Add as optional dependency group: pip install swarm-provenance-cli[langchain]
  • LangChain should be a lazy import (don't break CLI for users without langchain installed)
  • Place under swarm_provenance_uploader/integrations/langchain.py

Testing

  • Unit tests with mocked gateway (no real uploads)
  • Integration test with real gateway (marked @pytest.mark.integration)
  • Example script demonstrating usage

Documentation

  • README section on LangChain integration
  • Example in examples/ directory

Reference

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions