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 (captures prompt text, model.name, model.provider)
  • LLM Ends (on_llm_end) $\rightarrow$ ResponseEvent (captures completion text, streaming telemetry, usage token counts, and duration_ms)
  • Tool Starts (on_tool_start) $\rightarrow$ ToolCallEvent
  • Tool Ends (on_tool_end) $\rightarrow$ ToolResultEvent (captures output and duration_ms)
  • 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.3.0.tar.gz (10.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.3.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aerograph_langchain-0.3.0.tar.gz
  • Upload date:
  • Size: 10.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.3.0.tar.gz
Algorithm Hash digest
SHA256 fcd0e73605b170725f3f9a0881e96f5472fa6812a6d0ae8c6e938325aee77c01
MD5 286cc0b1c7f80006dc1e0d0b591cc03f
BLAKE2b-256 b2fc804584a908c6dbc2002f5ec5e5cec48dcac4d4343d1ba76f24fb1baa923e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for aerograph_langchain-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce9b0d6870025bac0d21aaef3e74a09d446c5685b11da0968444ce5e874c4234
MD5 bf1e518d35b5dc4af25b6f9013b5238f
BLAKE2b-256 e65d4918ded86a404748920a6a117a079adfd30ea93db5d982cddec23741630a

See more details on using hashes here.

Provenance

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