Metadata-Version: 2.4
Name: ory-langchain
Version: 0.11.1
Summary: Ory Agent Security for LangChain / LangGraph — per-tool authorization, tracing, and identity propagation via an AgentMiddleware. Built on ory-argus.
Author: Ory
License-Expression: Apache-2.0
Keywords: agent,ai,authorization,langchain,langgraph,ory,permissions
Requires-Python: >=3.10
Requires-Dist: langchain<2,>=1
Requires-Dist: ory-argus<1,>=0.8
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# ory-langchain

Ory Agent Security for [LangChain](https://docs.langchain.com) / LangGraph.

Adds three things to a LangChain agent with one line:

1. **Authorization** — every tool call is checked against Ory Permissions before it runs.
2. **Tracing** — every invocation is recorded as a structured span (OTLP + NDJSON).
3. **Identity propagation** — user → agent → sub-agent delegation, recorded in Ory.

## Install

```bash
pip install ory-langchain
```

## Use

```python
from langchain.agents import create_agent
from ory_langchain import OryMiddleware

agent = create_agent(
    model,
    tools=[search, send_email],
    middleware=[OryMiddleware()],   # gate every tool call through Ory
)
```

`OryMiddleware()` reads the shared Ory config at `~/.config/ory-agent-plugins/config.json`,
so a login performed by any Ory coding-agent harness — or by `ory-argus login` — is reused
transparently. Configure a project explicitly with `OryMiddleware(project_url=...)`.

### Permission mode

- `observe` (default) — denied tools still run, but a `permission.observe_deny` span is
  recorded. Use this to see what *would* be blocked before enforcing.
- `enforce` — denied tools are blocked: the model receives an error `ToolMessage` and the
  tool never executes. Set `ORY_PERMISSION_MODE=enforce` or run `ory-argus permissions enforce`.

### Tracing only

If you only want observability (no enforcement), use the callback handler instead:

```python
from ory_langchain import OryCallbackHandler

agent.invoke({"messages": [...]}, config={"callbacks": [OryCallbackHandler()]})
```

Built on [`ory-argus`](https://pypi.org/project/ory-argus/), the shared Ory Agent Security core.
