Skip to main content

AuthSec identity and delegation for LangGraph stateful agent workflows

Project description

authsec-langgraph-sdk

AuthSec identity and delegation for LangGraph stateful agent workflows.

Give every node in your LangGraph state machine a scoped, short-lived, audited identity — without any node having to fetch credentials manually.

PyPI Python

Built on top of authsec-langchain-sdk. Same HTTP client; LangGraph-native bindings on top.


Install

pip install authsec-langgraph-sdk

Pulls in authsec-langchain-sdk and langgraph automatically.


What you get

Three integration shapes, pick whichever matches your graph:

Helper When to use it
inject_authsec_state(state, client) Fine-grained: call from any node to refresh the JWT in state
with_authsec_auth(node_fn, client) Decorator: wrap any node so it always sees a fresh authsec_token in state
AuthsecNode(client) Standalone graph node: add it as the entry point or before any subgraph that needs auth

Plus AuthsecState — a TypedDict you can compose into your graph's state schema so authsec_token is typed.


Quick start

from langgraph.graph import END, START, StateGraph
from authsec_langgraph import (
    AuthsecClient, AuthsecConfig, AuthsecNode, AuthsecState,
)

class MyState(AuthsecState):
    input: str
    result: str

authsec = AuthsecClient(AuthsecConfig(
    base_url="https://auth.example.com",
    client_id="a594430b-2bd4-4792-9666-63162ee858c5",
))

def call_downstream(state: MyState) -> dict:
    jwt = state["authsec_token"]    # populated by AuthsecNode
    # ... use jwt to call your API ...
    return {"result": "ok"}

graph = StateGraph(MyState)
graph.add_node("auth", AuthsecNode(client=authsec))
graph.add_node("work", call_downstream)
graph.add_edge(START, "auth")
graph.add_edge("auth", "work")
graph.add_edge("work", END)

app = graph.compile()
app.invoke({"input": "do the thing"})

AuthsecNode runs first, pulls a fresh delegation JWT, puts it in state. Every downstream node reads it from state["authsec_token"]. No node needs to know about HTTP, caching, or auth refresh.


Why this exists

LangChain agents are mostly stateless — one prompt, one decision, one tool. LangGraph adds explicit state and routing for multi-step workflows. That means auth becomes a state-management problem too:

  • Multiple nodes might need the same JWT — don't fetch N times
  • Some subgraphs need elevated auth; others don't
  • State persists across nodes; tokens have to be visible without leaking through unrelated nodes

This SDK gives you the primitives to handle that cleanly inside LangGraph's idioms.


Examples in this repo

File What it does
examples/billing_lookup_graph.py 3-node graph: auth → classify → call downstream API. Mocked API so no cloud setup needed.

Run:

$env:AUTHSEC_BASE_URL = "https://auth.example.com"
$env:AUTHSEC_AGENT_CLIENT_ID = "<agent UUID>"
python examples/billing_lookup_graph.py

Relationship to authsec-langchain-sdk

This package depends on authsec-langchain-sdk and re-exports its core types:

# These are all imported from authsec_langchain via authsec_langgraph:
AuthsecClient, AuthsecConfig
AuthsecError, DelegationError
CIBARequiredError, CIBADeniedError, CIBATimeoutError

So you don't need both packages installed separately. Install authsec-langgraph-sdk and you get the full surface.

If you have a LangChain agent that also uses LangGraph for some flows, install both — they coexist cleanly because the HTTP client is shared.


What's in v0.1

Feature Status
AuthsecNode (callable graph node)
with_authsec_auth (decorator wrapper)
inject_authsec_state (pure function)
AuthsecState typed dict
Async node variants ⏳ v0.2
Conditional CIBA approval routing ⏳ v0.2
LangGraph checkpoint-aware token cache ⏳ v0.3

Development

git clone https://github.com/authsec-ai/authsec-langgraph
cd authsec-langgraph
pip install -e ".[dev]"
pytest

Tests are mocked; no live AuthSec needed for pytest.


License

Apache 2.0

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

authsec_langgraph_sdk-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

authsec_langgraph_sdk-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file authsec_langgraph_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: authsec_langgraph_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for authsec_langgraph_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ca5123bc0d4b5782e282f33747855e98038736148127544feb5bc831d7a484f1
MD5 a8f48a5872a28f1f7f555a5f0c035a86
BLAKE2b-256 a0453f6b26bf7033c3e738fd0c77749afa39b6a676b4dfc11a5f3e8e473d4066

See more details on using hashes here.

File details

Details for the file authsec_langgraph_sdk-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for authsec_langgraph_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d19acacb1cfb6a3b87310a08d1aa371f1b974d44aea1aa02fc429fca31af64cd
MD5 0576adb11a4921057d82534ec6e0aa8d
BLAKE2b-256 3d25020d9b9696644857e78fb7dce4df61cc833e99f849166ec673dfd832abea

See more details on using hashes here.

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