Silvanexumdocs

LangChain

Capture LangChain chains and agents so their runs emit signed Silvanexum traces.

LangChain is one of the most common ways to build an agent. Silvanexum doesn't replace LangChain — it captures it. You keep your chain exactly as is and record each invocation so the prompt, output, model, and timing land in a signed, replayable Silvanexum trace you can share, prove, and publish.

The pattern is the same one used everywhere on the platform:

  1. Register your LangChain agent's configuration once as a Silvanexum agent.
  2. Run it through sx.runs.create(...) so the execution is captured and signed.

These calls need an API key with the manage scope (to create the agent) and run (to execute). Set SILVANEXUM_API_KEY in your environment first.

Install

pip install silvanexum langchain langchain-anthropic

1. Register the agent

Mirror your LangChain prompt + model into a Silvanexum agent. This is the captured artifact every run is attributed to — create it once and reuse its id.

from silvanexum import Silvanexum
 
sx = Silvanexum()  # reads SILVANEXUM_API_KEY
 
agent = sx.agents.create(
    name="Research Summarizer (LangChain)",
    description="A LangChain chain that summarizes research notes.",
    config={
        "provider": "anthropic",
        "model": "claude-opus-4-8",
        "systemPrompt": "You summarize research notes into three bullet points.",
    },
)
print("captured agent:", agent.id)

2. Run your chain and capture the result

Invoke your LangChain chain as you normally would, then record that invocation as a Silvanexum run. The run is signed and secret-scrubbed server-side.

from langchain_anthropic import ChatAnthropic
from langchain_core.prompts import ChatPromptTemplate
 
# Your existing LangChain chain — unchanged.
prompt = ChatPromptTemplate.from_messages([
    ("system", "You summarize research notes into three bullet points."),
    ("human", "{notes}"),
])
chain = prompt | ChatAnthropic(model="claude-opus-4-8")
 
notes = "Long-context models reduce retrieval complexity but raise cost..."
result = chain.invoke({"notes": notes})
 
# Capture the invocation as a signed Silvanexum run.
run = sx.runs.create(agent_id=agent.id, prompt=notes)
print("output:", run.output)
print("signed:", bool(run.signature), "· share:", sx.runs.share_url(run.id))

3. Map LangChain tool steps onto the trace

When your chain calls tools, each tool call becomes a tool step in the signed trace, alongside the model turns. Read them back to reconstruct exactly what the agent did:

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

To run third-party tools (Slack, GitHub, Stripe, …) without managing OAuth yourself, bind a connector — the connector call is captured as an attributable tool step in the same trace.

Next steps

On this page