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.0.tar.gz (9.7 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.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aerograph_langchain-0.2.0.tar.gz
  • Upload date:
  • Size: 9.7 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.0.tar.gz
Algorithm Hash digest
SHA256 169f40f4be9a18cf97fdd78f356647edc3492f6e9c5ecf1d299c4e2309170fa5
MD5 bd6fe359c70a12bb845b6ccae2caf64f
BLAKE2b-256 50093f17363313cacc318a52314545fdb9816f7dec0c7716dcb02d18480cb5f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for aerograph_langchain-0.2.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aerograph_langchain-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9fc784272707dc7edf566974b8594a98955977fc769509770fa0789b57e62265
MD5 9d6f5ddf9b13f4f756607b8d4eb36cb5
BLAKE2b-256 3e171b1e3a70cee275cdfce89a4dc4998ab81e666cd42a65f078fb6d93e7da14

See more details on using hashes here.

Provenance

The following attestation bundles were made for aerograph_langchain-0.2.0-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