Skip to main content

LangGraph callback handlers for Sigil Python SDK

Project description

Sigil Python Framework Module: LangGraph

sigil-sdk-langgraph provides callback handlers that map LangGraph lifecycle events into Sigil generation recorder lifecycles.

Installation

pip install sigil-sdk sigil-sdk-langgraph
pip install langgraph langchain-openai

Usage

from sigil_sdk import Client
from sigil_sdk_langgraph import with_sigil_langgraph_callbacks

client = Client()
config = with_sigil_langgraph_callbacks(None, client=client, provider_resolver="auto")

End-to-end example (graph invoke + stream)

from typing import TypedDict

from langchain_openai import ChatOpenAI
from langgraph.graph import END, StateGraph
from sigil_sdk import Client
from sigil_sdk_langgraph import SigilLangGraphHandler, with_sigil_langgraph_callbacks


class GraphState(TypedDict):
    prompt: str
    answer: str


client = Client()
handler = SigilLangGraphHandler(
    client=client,
    provider_resolver="auto",
    agent_name="langgraph-example",
    agent_version="1.0.0",
)
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)


def run_model(state: GraphState) -> GraphState:
    response = llm.invoke(
        state["prompt"],
        config=with_sigil_langgraph_callbacks(None, client=client, provider_resolver="auto"),
    )
    return {"prompt": state["prompt"], "answer": response.content}


workflow = StateGraph(GraphState)
workflow.add_node("model", run_model)
workflow.set_entry_point("model")
workflow.add_edge("model", END)
graph = workflow.compile()

# Non-stream graph invocation.
out = graph.invoke({"prompt": "Explain SLO burn rate in one paragraph.", "answer": ""})
print(out["answer"])

# Streamed graph events.
for _event in graph.stream(
    {"prompt": "List three practical alerting tips.", "answer": ""},
):
    pass

client.shutdown()

Workflow step capture

Enable capture_workflow_steps=True to record each graph node as a Sigil workflow step. This builds a visual DAG in the Sigil UI showing node execution order, duration, input/output state, and which LLM generations ran inside each node.

Always set conversation_title to a short human-readable label — it appears as the conversation name in the Sigil UI. Without it, the title falls back to an opaque auto-generated ID.

from sigil_sdk import Client
from sigil_sdk_langgraph import SigilLangGraphHandler

client = Client()
handler = SigilLangGraphHandler(
    client=client,
    agent_name="my-pipeline",
    conversation_title="My Pipeline Run",
    capture_workflow_steps=True,
)

result = graph.invoke(input, config={"callbacks": [handler]})
client.shutdown()

The handler automatically:

  • Detects graph root and direct-child nodes
  • Creates a workflow step per node with input_state, output_state, and timestamps
  • Links LLM generation IDs to their parent step via linked_generation_ids
  • Tracks sequential parent_step_ids so the DAG edges are correct

Persistent thread example (LangGraph checkpointer)

from langgraph.checkpoint.memory import MemorySaver

checkpointer = MemorySaver()
graph = workflow.compile(checkpointer=checkpointer)

thread_config = {
    **with_sigil_langgraph_callbacks(None, client=client, provider_resolver="auto"),
    "configurable": {"thread_id": "customer-42"},
}

graph.invoke({"prompt": "Remember that my timezone is UTC+1.", "answer": ""}, config=thread_config)
graph.invoke({"prompt": "What timezone did I just give you?", "answer": ""}, config=thread_config)

# Advanced usage: explicit handler wiring remains supported.
_ = graph.invoke(
    {"prompt": "manual handler wiring", "answer": ""},
    config={"callbacks": [handler]},
)

When thread_id is present, the handler records:

  • conversation_id=<thread_id>
  • metadata["sigil.framework.run_id"]=<run id>
  • metadata["sigil.framework.thread_id"]=<thread id>
  • generation span attributes sigil.framework.run_id and sigil.framework.thread_id

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=langgraph
    • 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)
    • metadata["sigil.framework.langgraph.node"] (when callback context exposes node identity)
    • 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_langgraph-0.2.1.tar.gz (9.9 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_langgraph-0.2.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file sigil_sdk_langgraph-0.2.1.tar.gz.

File metadata

  • Download URL: sigil_sdk_langgraph-0.2.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for sigil_sdk_langgraph-0.2.1.tar.gz
Algorithm Hash digest
SHA256 053e16e8b0060821f36ac51df9300e775e54f173f51d1eb0478e5f7d81ee1482
MD5 956b55d5df92308f5460609a7f561556
BLAKE2b-256 c3cc43e6243dc1f6da6600d0bec01a20cd5cd185f29a6a01b06e2c8caebef610

See more details on using hashes here.

Provenance

The following attestation bundles were made for sigil_sdk_langgraph-0.2.1.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_langgraph-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sigil_sdk_langgraph-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d3641a1597f0c9c7b6d1383eb36a7fe3f98a7404943e0d492a50cfa9ad43cb99
MD5 213829d7a1593522c89d49ce94bc57da
BLAKE2b-256 7f5a8430e342a0d173d70749f7e8eb8fe776c5b712203b989d9e898e09231c5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for sigil_sdk_langgraph-0.2.1-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