Skip to main content

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 recorder
    • on_tool_start / on_tool_end / on_tool_error -> start_tool_execution
    • on_chain_start / on_chain_end / on_chain_error -> framework chain spans
    • on_retriever_start / on_retriever_end / on_retriever_error -> framework retriever spans
    • on_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=langchain
    • sigil.framework.source=handler
    • sigil.framework.language=python
    • metadata["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

sigil_sdk_langchain-0.1.3.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sigil_sdk_langchain-0.1.3-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file sigil_sdk_langchain-0.1.3.tar.gz.

File metadata

  • Download URL: sigil_sdk_langchain-0.1.3.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sigil_sdk_langchain-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b47e6b723837626bff7f3e20d05c62ed23d861f856f4b4c1f5a07ce664fe0140
MD5 7af429599343426d7abe1e20638f1994
BLAKE2b-256 0fba5bf28daae57538eec39932b3c6ed23942200f6af23aa1727bbcf619d4591

See more details on using hashes here.

Provenance

The following attestation bundles were made for sigil_sdk_langchain-0.1.3.tar.gz:

Publisher: python-sdks-publish.yml on grafana/sigil-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sigil_sdk_langchain-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for sigil_sdk_langchain-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 100edeee7f283ce00a2f0a101acb3129a53eb758d38cd54a811e465ab388f15b
MD5 3cb784aaf952b314a36fa9fefbab806c
BLAKE2b-256 06690bd10664c37c580d2b84745849d566b57016c61daba6c195849e76423df2

See more details on using hashes here.

Provenance

The following attestation bundles were made for sigil_sdk_langchain-0.1.3-py3-none-any.whl:

Publisher: python-sdks-publish.yml on grafana/sigil-sdk

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