Metadata-Version: 2.4
Name: langchain-verda
Version: 0.1.0
Summary: LangChain chat models for Verda Inference
Author: Verda
License-Expression: MIT
Project-URL: Homepage, https://github.com/verda-cloud/langchain-verda
Project-URL: Repository, https://github.com/verda-cloud/langchain-verda
Project-URL: Issues, https://github.com/verda-cloud/langchain-verda/issues
Keywords: langchain,verda,llm,inference,chat-model
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: langchain-openai<2,>=1.1
Requires-Dist: langchain-core<2,>=1
Requires-Dist: pydantic<3,>=2.7
Provides-Extra: agents
Requires-Dist: deepagents<1,>=0.3; extra == "agents"
Dynamic: license-file

# langchain-verda

Use Verda-hosted Kimi K3.1 Pro, DeepSeek V4.1 Flash, and GLM 5.4 models from Python with LangChain's
`ChatVerda` interface. You can call the model directly, stream an answer, or give a
[Deep Agent](https://www.langchain.com/deep-agents) tools to use during a conversation.

## Install

The package requires Python 3.11 or newer.

```bash
uv add langchain-verda
```

Or, with pip:

```bash
pip install langchain-verda
```

## Set up credentials

First, enable a model. In the [Verda console](https://console.verda.com/), open **Inference > Models** and
click **Enable** on the model you want. The Quickstart window opens with a new API key for your project.
Copy it somewhere safe; it's only shown once.

Set the key in your environment:

```bash
export VERDA_INFERENCE_API_KEY="<your-verda-inference-api-key>"
```

## Call a model

```python
from langchain_verda import ChatVerda

chat = ChatVerda(model="kimi-k3-1-pro")
print(chat.invoke("What is prefix caching?").content)
```

The adapter sends calls to `https://inference.verda.com/v1/chat/completions`. Use `ainvoke` for async calls
and `stream` or `astream` for incremental output. Reasoning text is available in
`message.additional_kwargs.get("reasoning_content")`.

## Supported models

| Model                    | Value for `ChatVerda(model=...)` |
| ------------------------ | -------------------------------- |
| Kimi K3.1 Pro            | `kimi-k3-1-pro`                  |
| DeepSeek V4.1 Flash 1017 | `deepseek-4-1-flash-1017`        |
| GLM 5.4                  | `glm-5-4`                        |

Each model has been tested with tool calling through LangChain's Deep Agents harness, sync and async
streaming, async invocation, and token usage reporting in streamed responses.

## Stream an answer

```python
from langchain_verda import ChatVerda

chat = ChatVerda(model="deepseek-4-1-flash-1017")
for chunk in chat.stream("What's the best viewpoint in Helsinki?"):
    print(chunk.text, end="", flush=True)
print()
```

For async applications, use `await chat.ainvoke(...)` or iterate over `chat.astream(...)` with `async for`.

## Deep Agents

Install the optional dependency with `uv add 'langchain-verda[agents]'` or
`pip install 'langchain-verda[agents]'`.
The following example invokes the live model and incurs inference charges.

```python
from deepagents import create_deep_agent
from langchain_verda import ChatVerda

def stock_count() -> int:
    """Return the current number of items in stock."""
    return 42

agent = create_deep_agent(model=ChatVerda(model="glm-5-4"), tools=[stock_count])
result = agent.invoke({"messages": [{"role": "user", "content": "Use stock_count to check inventory."}]})
print(result["messages"][-1].content)
```

## Saving model configuration

To restore a chat model, save its model ID and settings and create a new `ChatVerda` instance. Supply
credentials through the environment. LangChain constructor serialization (`dumpd` / `load`) is not
supported in this alpha.

## Development

Development uses [uv](https://docs.astral.sh/uv/). From the repository root, run the offline suite and the
linter:

```bash
make test
make lint
```

`uv run` creates `.venv` and installs the locked dependencies from `uv.lock` on first use.

The unit tests in `tests/unit_tests` run with network access blocked. They cover tool-call round trips,
streamed tool arguments, usage metadata, reasoning history, and LangChain's standard chat model unit tests.
Run `make check_versions` to repeat them against the declared minimum and newest compatible 1.x version of
`langchain-openai`.

### Integration tests

The integration tests in `tests/integration_tests` call Verda endpoints and are billable. They need all
three models enabled and `VERDA_INFERENCE_API_KEY` set. This runs the smoke tests, then LangChain's standard
integration suite against each model:

```bash
make integration_test
```

To test a single model, run `make integration_test MODELS=glm-5-4`.

## License

MIT. See [LICENSE](LICENSE).
