Silvanexumdocs

LangGraph

Capture LangGraph state-machine agents so each graph run emits a signed Silvanexum trace.

LangGraph models an agent as a stateful graph of nodes and edges — ideal for loops, branching, and human-in-the-loop control. Silvanexum captures the result of compiling and invoking that graph as a signed, replayable run, so a complex control flow still produces one clean, provable artifact.

The pattern matches the rest of the platform:

  1. Register the compiled graph once as a Silvanexum agent.
  2. Record each graph.invoke(...) with sx.runs.create(...) to capture + sign it.

Needs an API key with the manage scope (to register the agent) and run (to capture executions). Set SILVANEXUM_API_KEY first.

Install

pip install silvanexum langgraph langchain-anthropic

1. Register the graph as an agent

from silvanexum import Silvanexum
 
sx = Silvanexum()  # reads SILVANEXUM_API_KEY
 
agent = sx.agents.create(
    name="Triage Graph (LangGraph)",
    description="A LangGraph state machine that classifies and routes a request.",
    config={
        "provider": "anthropic",
        "model": "claude-opus-4-8",
        "systemPrompt": "You classify a request and route it to the right handler.",
    },
)

2. Invoke the graph and capture the run

Build and compile your graph as usual, invoke it, then capture the invocation as a signed Silvanexum run.

from langgraph.graph import StateGraph, START, END
from langchain_anthropic import ChatAnthropic
from typing import TypedDict
 
class State(TypedDict):
    request: str
    answer: str
 
llm = ChatAnthropic(model="claude-opus-4-8")
 
def handle(state: State) -> State:
    msg = llm.invoke(state["request"])
    return {"request": state["request"], "answer": msg.content}
 
builder = StateGraph(State)
builder.add_node("handle", handle)
builder.add_edge(START, "handle")
builder.add_edge("handle", END)
graph = builder.compile()
 
request = "A customer's invoice was double-charged — what should happen?"
result = graph.invoke({"request": request, "answer": ""})
 
# Capture the graph invocation as a signed Silvanexum run.
run = sx.runs.create(agent_id=agent.id, prompt=request)
print("output:", run.output)
print("signed:", bool(run.signature), "· share:", sx.runs.share_url(run.id))

3. Read back the trace

Each node's model and tool calls land as ordered steps in the trace, so even a looping or branching graph reconstructs exactly:

full = sx.runs.get(run.id)
for step in full.trace:
    print(f"{step.startMs}ms  {step.kind}:{step.name}  ({step.status})")

For graphs whose nodes call third-party APIs, bind a connector so those calls are captured as attributable tool steps with the OAuth token injected by Nango — never by your code.

Next steps

On this page