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$StateSnapshotEventandCheckpointEventfor LangGraph nodes
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
169f40f4be9a18cf97fdd78f356647edc3492f6e9c5ecf1d299c4e2309170fa5
|
|
| MD5 |
bd6fe359c70a12bb845b6ccae2caf64f
|
|
| BLAKE2b-256 |
50093f17363313cacc318a52314545fdb9816f7dec0c7716dcb02d18480cb5f6
|
Provenance
The following attestation bundles were made for aerograph_langchain-0.2.0.tar.gz:
Publisher:
release-python.yml on SGcpu/AeroGraph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aerograph_langchain-0.2.0.tar.gz -
Subject digest:
169f40f4be9a18cf97fdd78f356647edc3492f6e9c5ecf1d299c4e2309170fa5 - Sigstore transparency entry: 1707766669
- Sigstore integration time:
-
Permalink:
SGcpu/AeroGraph@f4f3747cd6026d768e7f6f4d1b43de22f10b0d30 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/SGcpu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-python.yml@f4f3747cd6026d768e7f6f4d1b43de22f10b0d30 -
Trigger Event:
release
-
Statement type:
File details
Details for the file aerograph_langchain-0.2.0-py3-none-any.whl.
File metadata
- Download URL: aerograph_langchain-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fc784272707dc7edf566974b8594a98955977fc769509770fa0789b57e62265
|
|
| MD5 |
9d6f5ddf9b13f4f756607b8d4eb36cb5
|
|
| BLAKE2b-256 |
3e171b1e3a70cee275cdfce89a4dc4998ab81e666cd42a65f078fb6d93e7da14
|
Provenance
The following attestation bundles were made for aerograph_langchain-0.2.0-py3-none-any.whl:
Publisher:
release-python.yml on SGcpu/AeroGraph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aerograph_langchain-0.2.0-py3-none-any.whl -
Subject digest:
9fc784272707dc7edf566974b8594a98955977fc769509770fa0789b57e62265 - Sigstore transparency entry: 1707766741
- Sigstore integration time:
-
Permalink:
SGcpu/AeroGraph@f4f3747cd6026d768e7f6f4d1b43de22f10b0d30 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/SGcpu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-python.yml@f4f3747cd6026d768e7f6f4d1b43de22f10b0d30 -
Trigger Event:
release
-
Statement type: