Metadata-Version: 2.5
Name: anlyon-langchain
Version: 0.1.0
Summary: LangChain integration for Anlyon state primitives and trace callbacks
Project-URL: Homepage, https://anlyon.com
Project-URL: Documentation, https://docs.anlyon.com
Project-URL: Repository, https://github.com/AnlyonHQ/anlyon-platform
Project-URL: Issues, https://github.com/AnlyonHQ/anlyon-platform/issues
Author-email: Anlyon <support@anlyon.com>
License-Expression: MIT
License-File: LICENSE
Keywords: agent-governance,ai-agents,anlyon,approvals,langchain,memory,sdk,tracing
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: anlyon>=0.1.0
Requires-Dist: langchain-core>=1.6.0
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: respx>=0.21; extra == 'dev'
Description-Content-Type: text/markdown

# anlyon-langchain

LangChain integration for [Anlyon](https://anlyon.com): `AnlyonVectorStore` and `AnlyonRetriever` over Anlyon Memory, `AnlyonChatMessageHistory` over Anlyon Sessions, and `AnlyonTracer` for nested run/span tracing.

## Trace a LangChain invocation

```python
from anlyon import Client
from anlyon_langchain import AnlyonTracer

client = Client(api_key="anlyon_live_...")
tracer = AnlyonTracer(client, application="support-agent")

# Pass the callback to any LangChain runnable/agent invocation.
result = chain.invoke({"question": "Where is my order?"}, config={"callbacks": [tracer]})
```

The handler creates one Anlyon run for the root callback and parent-linked
`workflow_step`, `model_call`, and `tool_call` spans for nested callbacks. It is
best-effort: Anlyon transport failures never change the application result.

## Installation

```bash
pip install anlyon-langchain
```

## Retrieval

```python
from anlyon import Client
from anlyon_langchain import AnlyonVectorStore

client = Client()  # uses ANLYON_API_KEY
store = AnlyonVectorStore(client, collection="docs")
retriever = store.as_retriever()
```

## Chat history

`AnlyonChatMessageHistory` puts a chain's conversation in an Anlyon Session  durable across processes, and summarized automatically once the thread gets long.

```python
from anlyon import Client
from anlyon_langchain import AnlyonChatMessageHistory
from langchain_core.runnables.history import RunnableWithMessageHistory

client = Client()

chain_with_history = RunnableWithMessageHistory(
    chain,
    lambda session_id: AnlyonChatMessageHistory(client, session_id),
    input_messages_key="input",
    history_messages_key="history",
)

# `session_id` is an Anlyon session id  create one with client.sessions.create()
chain_with_history.invoke(
    {"input": "Where is my order?"},
    config={"configurable": {"session_id": "ses_abc123"}},
)
```

`.messages` reads the thread back as LangChain messages, `.add_messages()` appends a turn in one round-trip, and `.clear()` truncates the thread while keeping the session id usable.

See the [Anlyon docs](https://docs.anlyon.com) for the full guide.

## License

MIT
