Skip to main content

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",
        project_id="travel-app", # Optional: Routes traces to a specific project (creates it if new)
        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
  • LangGraph Node Boundaries (on_chain_start, on_chain_end with langgraph_node metadata) $\rightarrow$ NoteEvent (automatically captures state_before inputs, state_update outputs, step, triggers, path, and checkpoint_ns)

Replay Support

Replay support is inherited automatically — no replay-specific code is required in your adapter.

When executing an agent workflow under AeroGraph record mode (aerorepl record <cmd> or Orchestrator POST /v1/runs {mode: "record"}), HTTP traffic is intercepted and cached in a deterministic cassette. Replaying or forking that workflow transparently serves cached responses to the adapter without requiring any changes or replay imports in your adapter code. See Quickstart Scenario 1 for details.

Span Correlation

When outbound HTTP clients permit custom header injection, X-AeroGraph-Span-Id: <spanId> is attached to correlate network interactions with specific trace spans. When client libraries do not expose header hooks, the proxy seamlessly employs a deterministic timestamp-window fallback to correlate cassette entries.

License

Apache-2.0

Metadata

Release files for aerograph-langchain 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aerograph-langchain 0.5.0
File Size Uploaded Provenance Actions
aerograph_langchain-0.5.0.tar.gz 12.8 kB With provenance Details for aerograph_langchain-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aerograph-langchain 0.5.0
File Interpreter ABI Platform Actions
aerograph_langchain-0.5.0-py3-none-any.whl Python 3 none any Details for aerograph_langchain-0.5.0-py3-none-any.whl

Total release size: 24.2 kB

Release files / aerograph_langchain-0.5.0.tar.gz

Download URL aerograph_langchain-0.5.0.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0a34058a5c52a9fd40ae5faa01f7d2e50970155eb91f346cd6111794bed55154
BLAKE2b-256 checksum
How to use checksums
3d07430fa26c7d1a7f1fae9a132daf23f0f8421e639535011a3f2202379fec66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / aerograph_langchain-0.5.0-py3-none-any.whl

Download URL aerograph_langchain-0.5.0-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96b4bf44f796b69573f34b422211f13b3cdc5fa8a790bebffa04854253b452d5
BLAKE2b-256 checksum
How to use checksums
821b048f23bdac931c68825d3d5f919d30742b6e45b33b73da1c8639768c3edd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for aerograph-langchain 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for aerograph_langchain-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page