LangChain callback handlers for Sigil Python SDK
Project description
Sigil Python Framework Module: LangChain
sigil-sdk-langchain provides callback handlers that map LangChain lifecycle events into Sigil generation recorder lifecycles.
Installation
pip install sigil-sdk sigil-sdk-langchain
pip install langchain-openai
Usage
from sigil_sdk import Client
from sigil_sdk_langchain import with_sigil_langchain_callbacks
client = Client()
config = with_sigil_langchain_callbacks(None, client=client, provider_resolver="auto")
End-to-end example (invoke + stream)
from langchain_openai import ChatOpenAI
from sigil_sdk import Client
from sigil_sdk_langchain import SigilLangChainHandler, with_sigil_langchain_callbacks
client = Client()
handler = SigilLangChainHandler(
client=client,
provider_resolver="auto",
agent_name="langchain-example",
agent_version="1.0.0",
)
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
# Non-stream call -> SYNC generation mode.
result = llm.invoke(
"Summarize why retry budgets matter.",
config=with_sigil_langchain_callbacks(None, client=client, provider_resolver="auto"),
)
print(result.content)
# Stream call -> STREAM generation mode + TTFT tracking.
for chunk in llm.stream(
"Give me three short reliability tips.",
config=with_sigil_langchain_callbacks(None, client=client, provider_resolver="auto"),
):
if chunk.content:
print(chunk.content, end="", flush=True)
print()
# Advanced usage: explicit handler wiring remains supported.
_ = llm.invoke("manual handler wiring", config={"callbacks": [handler]})
client.shutdown()
Behavior
- Lifecycle mapping:
on_llm_start/on_chat_model_start-> generation recorderon_tool_start/on_tool_end/on_tool_error->start_tool_executionon_chain_start/on_chain_end/on_chain_error-> framework chain spanson_retriever_start/on_retriever_end/on_retriever_error-> framework retriever spanson_llm_new_token-> first-token timestamp for stream mode
- Mode mapping: non-stream ->
SYNC, stream ->STREAM. - Provider resolver parity:
- explicit provider metadata when available
- model-name inference (
gpt-/o1/o3/o4->openai,claude-->anthropic,gemini-->gemini) - fallback ->
custom
- Framework tags/metadata are always set:
sigil.framework.name=langchainsigil.framework.source=handlersigil.framework.language=pythonmetadata["sigil.framework.run_id"]=<run id>metadata["sigil.framework.thread_id"]=<thread id>(when present in callback metadata/config)metadata["sigil.framework.parent_run_id"](when available)metadata["sigil.framework.component_name"](serialized component identity)metadata["sigil.framework.run_type"](llm,chat,tool,chain,retriever)metadata["sigil.framework.tags"](normalized callback tags)metadata["sigil.framework.retry_attempt"](when available)- generation span attributes mirror low-cardinality framework metadata keys
Call client.shutdown() during teardown to flush buffered telemetry.
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
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 sigil_sdk_langchain-0.2.0.tar.gz.
File metadata
- Download URL: sigil_sdk_langchain-0.2.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c974d7f4dbbc652af57382cae8bd1b1ced18a7591012a361c7888b7e35ffd941
|
|
| MD5 |
133b0954795aa220c1a2b5e585657477
|
|
| BLAKE2b-256 |
12f3f32f3444ff4a1ae54ddc44468cc4cb2a86e40cd5b5aee125b340908b2d14
|
Provenance
The following attestation bundles were made for sigil_sdk_langchain-0.2.0.tar.gz:
Publisher:
python-sdks-publish.yml on grafana/sigil-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sigil_sdk_langchain-0.2.0.tar.gz -
Subject digest:
c974d7f4dbbc652af57382cae8bd1b1ced18a7591012a361c7888b7e35ffd941 - Sigstore transparency entry: 1417607326
- Sigstore integration time:
-
Permalink:
grafana/sigil-sdk@3cfc596f2d3ca631ce9fa8fe3107d71c17caf924 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/grafana
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-sdks-publish.yml@3cfc596f2d3ca631ce9fa8fe3107d71c17caf924 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file sigil_sdk_langchain-0.2.0-py3-none-any.whl.
File metadata
- Download URL: sigil_sdk_langchain-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a06a44e03bac1c5d486f9ef4dca478f027a50c25387d4fa11a18e40da60f74af
|
|
| MD5 |
a5f8769706616b3a8e23e654e5d1294d
|
|
| BLAKE2b-256 |
2900f09c03db50c4afbc6bbf2961c9743c678e57801fcbca8118a6160001a7f4
|
Provenance
The following attestation bundles were made for sigil_sdk_langchain-0.2.0-py3-none-any.whl:
Publisher:
python-sdks-publish.yml on grafana/sigil-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sigil_sdk_langchain-0.2.0-py3-none-any.whl -
Subject digest:
a06a44e03bac1c5d486f9ef4dca478f027a50c25387d4fa11a18e40da60f74af - Sigstore transparency entry: 1417607565
- Sigstore integration time:
-
Permalink:
grafana/sigil-sdk@3cfc596f2d3ca631ce9fa8fe3107d71c17caf924 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/grafana
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-sdks-publish.yml@3cfc596f2d3ca631ce9fa8fe3107d71c17caf924 -
Trigger Event:
workflow_dispatch
-
Statement type: