TypeSafeClassifier in your graph, experimental middleware for routing and Auto Mode gates, no fake chat classifiers.
What LangChain and LangGraph give you
LangChain is the provider-agnostic composition layer for agents: tools, messages, runnables, and tracing. LangGraph adds durable state machines on top when you need checkpoints and branching. Jev does not replace either stack.
It sits on the decide edges where you would otherwise prompt a chat model for YES/NO or pick-one answers.
Install langchain-typesafe
The PyPI package langchain-typesafe is maintained by LangChain. Set TYPESAFE_API_KEY before invoking. For experimental middleware (ModelRouterMiddleware, AutoModeMiddleware), install the experimental extra documented on PyPI.
uv add langchain-typesafe
# Middleware (APIs under langchain_typesafe.experimental may change):
uv add "langchain-typesafe[experimental]"
export TYPESAFE_API_KEY="tsk_..."TypeSafeClassifier and parallel questions
TypeSafeClassifier is a LangChain Runnable. Pass a ClassifierRequest with state (text, structured JSON, or LangChain messages) and a questions map built from Choice, Score, and Noul helpers. invoke and ainvoke return separate answer objects per question.
System One evaluates questions in parallel, so adding nouls costs little compared to chaining chat calls.
from langchain_typesafe import Choice, Noul, Score, TypeSafeClassifier
classifier = TypeSafeClassifier()
result = classifier.invoke({
"state": "Deploy failed twice; customers see 500s. Can someone look now?",
"questions": {
"department": Choice(
instructions="Which team should own this?",
criteria={
"billing": "Payments or subscriptions",
"technical": "Product or integration failure",
},
),
"urgent": Noul(instructions="Does this need attention right now?"),
"severity": Score(
instructions="How severe is the outage?",
criteria=["low", "medium", "high"],
),
},
})ModelRouterMiddleware (model pick once per run)
LangChain's Building a Harness with Jev post walks through ModelRouterMiddleware: define ModelChoice entries with model ids and criteria, add instructions for cost-aware routing, and attach the middleware when you create_agent.
The router classifies the latest human message once per agent run and stores the full ChoiceAnswer in agent state so probabilities remain visible in traces.
from langchain.agents import create_agent
from langchain_typesafe.experimental.middleware import (
ModelChoice,
ModelRouterMiddleware,
)
router = ModelRouterMiddleware(
choices={
"fast": ModelChoice(
model="openai:gpt-5-mini",
criteria="Simple, well-scoped tasks.",
),
"powerful": ModelChoice(
model="openai:gpt-5",
criteria="Architecture and high-stakes debugging.",
),
},
instructions="Choose the least costly model that can complete the task.",
)
agent = create_agent("openai:gpt-5-mini", middleware=[router])AutoModeMiddleware (block risky tools)
AutoModeMiddleware classifies configured tools before execution. Pass tool names or BaseTool instances, tune NoulCriteria for what counts as risky versus read-only, and let Jev return a ToolMessage error when risk crosses the threshold.
This mirrors the harness gate pattern described in LangChain's Jev post, but stays in your open Python code instead of a closed IDE plugin.
from langchain_typesafe import NoulCriteria
from langchain_typesafe.experimental.middleware import AutoModeMiddleware
auto_mode = AutoModeMiddleware(
tools=["bash"],
criteria=NoulCriteria(
true="The call writes, deletes, publishes, or changes access.",
false="The call only reads public or user-provided data.",
),
)LangGraph nodes without middleware
When you already have a LangGraph node, call TypeSafeClassifier directly inside the node. Keep state serialization explicit: BaseMessage lists are converted to role/content objects automatically, but business fields you add stay yours.
Compose final branching in Python using thresholds on nouls and choice probabilities, not by parsing model prose.
Environment keys
Create a key at https://console.typesafe.ai/ (or route through Vercel AI Gateway / OpenRouter where the integration documents it). Export TYPESAFE_API_KEY in the environment for LangChain agent processes and notebooks.
Some MCP clients accept AI_GATEWAY_API_KEY when using gateway-hosted Jev models; follow that integration's README. Never commit keys into repos or paste them into chat logs.
export TYPESAFE_API_KEY="tsk_..."
# Optional pin:
export TYPESAFE_MODEL="jev-latest"Pitfalls
Experimental middleware APIs may change without notice; pin versions in production. TypeSafeClassifier is not a text generator: do not ask it to draft user emails. Catch TypeSafeRateLimitError when you need retry metadata; LangChain model errors still apply for shared handling.
Read the LangChain blog post for product claims; this guide sticks to integration shapes from PyPI and public docs.
Related directory listings
Related agent guides
OpenClaw + Jev
Assistant OS from OpenClaw, decide layer from Jev. Routing, gates, and official decisionModel support.
Codex and OpenCode + Jev
jev-judge on the CLI, evaluate setup, and routers that treat Jev as traffic control.
Cursor, Grok, and agent skills + Jev
MCP in Cursor settings, TypeSafe skills in the agent, no imaginary Grok-only APIs.
FAQ
- Does langchain-typesafe require LangGraph?
- No. TypeSafeClassifier works in any Runnable pipeline. Middleware targets LangChain create_agent flows documented on PyPI.
- Where is the official LangChain Jev walkthrough?
- LangChain published Building a Harness with Jev at langchain.com/blog/building-a-harness-with-jev with routing and Auto Mode examples.
- Can I route models every turn instead of once per run?
- ModelRouterMiddleware documents once-per-run classification of the latest human message. For per-turn routing in other hosts, see directory routers such as jev-codex-router or OpenClaw jev-claw.
- LangChain vs MCP for the same gate?
- Middleware runs inside your Python service. MCP reflex tools (system1-mcp fast_guard, typesafe-mcp evaluate) attach to IDE agents. Pick the surface your operator actually uses.
- What model id should I pass?
- TypeSafeClassifier uses TypeSafe defaults unless you override them in client configuration. Pin jev-latest or a versioned id to match your compliance notes.