Skip to main content

LangChain callback adapter for AeroGraph — automatically record LangChain traces.

Project description

aerograph-langchain

LangChain callback adapter for AeroGraph.

Automatically records LangChain chain, LLM, tool, and retriever events as AeroGraph trace events.

Installation

When published, you can install the adapter via pip:

pip install aerograph-langchain

For local testing or development, install the packages in editable mode from the repository root:

# Install the core SDK first
pip install -e python/aerograph-sdk

# Install the LangChain adapter
pip install -e python/aerograph-langchain

Usage

Integrating AeroGraphCallbackHandler into your existing LangChain codebase is simple. Setup a FlightRecorder, initialize the handler, and pass it to your chain or model invocations.

Basic Example

import asyncio
from langchain_core.messages import HumanMessage
from langchain_openai import ChatOpenAI
from aerograph_sdk.recorder import FlightRecorder
from aerograph_langchain.handler import AeroGraphCallbackHandler

async def main():
    # 1. Initialize the FlightRecorder pointing to your collector
    recorder = FlightRecorder(
        endpoint="http://localhost:4317",
        actor={"id": "my-agent", "name": "TravelPlanner"}
    )

    # 2. Initialize the AeroGraph callback handler
    handler = AeroGraphCallbackHandler(recorder)

    # 3. Create your LangChain chat model
    model = ChatOpenAI(model="gpt-4o")

    # 4. Invoke the model and pass the handler in callbacks
    response = await model.ainvoke(
        [HumanMessage(content="What are 3 fun things to do in San Francisco?")],
        config={"callbacks": [handler]}
    )
    print(response.content)

if __name__ == "__main__":
    asyncio.run(main())

Advanced Usage with Chains and RAG

You can attach the callback handler at the chain execution level. LangChain automatically propagates the callbacks down to all sub-chains, LLMs, retrievers, and tool invocations.

# Pass the handler to the chain invoke call
result = rag_chain.invoke(
    "How do I configure the server?",
    config={"callbacks": [handler]}
)

Features and Event Mapping

The callback adapter automatically intercepts LangChain execution signals and translates them to canonical AeroGraph TraceEvent types:

  • LLM/Chat Starts (on_llm_start, on_chat_model_start) $\rightarrow$ PromptEvent
  • LLM Ends (on_llm_end) $\rightarrow$ ResponseEvent (includes streaming telemetry completion metrics: TTFT and tokens/sec when tokens are streamed)
  • Tool Starts (on_tool_start) $\rightarrow$ ToolCallEvent
  • Tool Ends (on_tool_end) $\rightarrow$ ToolResultEvent
  • Retriever Runs (on_retriever_start, on_retriever_end) $\rightarrow$ RetrieverEvent (captures source documents, queries, and metadata)
  • Errors (on_llm_error, on_tool_error, on_chain_error) $\rightarrow$ ErrorEvent
  • Custom Events (on_custom_event) $\rightarrow$ StateSnapshotEvent and CheckpointEvent for LangGraph nodes

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aerograph_langchain-0.2.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aerograph_langchain-0.2.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file aerograph_langchain-0.2.1.tar.gz.

File metadata

  • Download URL: aerograph_langchain-0.2.1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aerograph_langchain-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7f2527b087204f79279cc617e1c4bc9642e03b6999fe3cf979213ae80e428b7c
MD5 a3efbe51a1a23cc168d4f01750909ed6
BLAKE2b-256 6650939558b9e174a2f5e69972aa289529d2bdf729b000204e0e28d1a984c9d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for aerograph_langchain-0.2.1.tar.gz:

Publisher: release-python.yml on SGcpu/AeroGraph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aerograph_langchain-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aerograph_langchain-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f25cddb5eb5ab0cbdfd1ee32d4741c77c03221948bfa5be1037cf8973d1151d0
MD5 817b9ade5aaf5a3387b264ee7ceea15b
BLAKE2b-256 fad751bbca70ce8f693afe4c01157edc5451f57e20252ccb2a788e934c25cb8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for aerograph_langchain-0.2.1-py3-none-any.whl:

Publisher: release-python.yml on SGcpu/AeroGraph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page