Environment:2aronS Duel Agents Python 3 9 Plus
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, LLMs |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
Python >= 3.9 environment for the `langchain-duel` package, built on LangChain Core 0.3.x and LangChain OpenAI 0.2–0.3.x to provide the `ChatDuel` chat model.
Description
This environment runs the `langchain-duel` integration, which subclasses `langchain_openai.ChatOpenAI` to route requests through the Duel Agents proxy. The build is managed by `hatchling` and the package metadata pins `requires-python = ">=3.9"`. The class uses Python 3.9-era typing idioms: `from __future__ import annotations` for deferred annotation evaluation and `dict[str, str]` built-in generics (which only become non-string generics at runtime from 3.9+, but the `__future__` import keeps them safe on all supported versions). Runtime is network-bound and has no CPU/GPU requirements beyond standard Python.
Usage
Use this environment when installing or running the `langchain-duel` package, i.e. whenever using the ChatDuel chat model in a LangChain application. It is the mandatory prerequisite for the `ChatDuel` Implementation page.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux, macOS, or Windows | Pure Python; no compiled extensions |
| Hardware | Any modern CPU | No GPU; model inference runs on the Duel proxy |
| Runtime | Python >= 3.9 | Declared via `requires-python` in pyproject.toml |
| Network | Outbound HTTPS to duelagents.com | Required for every model call |
Dependencies
Python Packages
- `langchain-core` >= 0.3.15, < 0.4
- `langchain-openai` >= 0.2, < 0.4
Test Dependencies (optional)
- `pytest` >= 7.4
- `pytest-asyncio` >= 0.23
- `langchain-tests` >= 0.3.5, < 0.4
Build System
- `hatchling` (PEP 517 backend, declared in `[build-system]`)
Credentials
The following environment variables are read at runtime by `ChatDuel`:
- `DUEL_API_KEY`: Duel API key, format `duel_<prefix>_<secret>` (mapped to `openai_api_key` via `lc_secrets`)
- `DUEL_PROXY_URL`: optional proxy override, defaults to `https://duelagents.com/v1`
Never hardcode key values; `ChatDuel` exposes `DUEL_API_KEY` as a LangChain secret via `lc_secrets` so it is redacted from serialized output.
Quick Install
pip install -U langchain-duel
export DUEL_API_KEY="duel_<prefix>_<secret>"
Code Evidence
Python version constraint from `python/langchain-duel/pyproject.toml:11`:
requires-python = ">=3.9"
Dependency pins from `python/langchain-duel/pyproject.toml:14-17`:
dependencies = [
"langchain-core>=0.3.15,<0.4",
"langchain-openai>=0.2,<0.4",
]
Environment-variable resolution from `python/langchain-duel/langchain_duel/chat_models.py:63-82`:
@model_validator(mode="before")
@classmethod
def _set_duel_defaults(cls, values: Any) -> Any:
if not isinstance(values, dict):
return values
values.setdefault("model", DEFAULT_MODEL)
values.setdefault(
"base_url", os.getenv("DUEL_PROXY_URL", DUEL_API_BASE)
)
has_key = any(
values.get(field)
for field in ("api_key", "openai_api_key")
)
if not has_key:
env_key = os.getenv("DUEL_API_KEY")
if env_key:
values["api_key"] = env_key
return values
Secret declaration from `python/langchain-duel/langchain_duel/chat_models.py:49-51`:
@property
def lc_secrets(self) -> dict[str, str]:
return {"openai_api_key": "DUEL_API_KEY"}
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `TypeError: Cannot interpret ... as a type` | Python < 3.9 running the class with built-in generic syntax without `__future__` | Upgrade to Python >= 3.9 |
| `ImportError: cannot import name 'ChatOpenAI'` | `langchain-openai` not installed or pinned to < 0.2 | `pip install -U "langchain-openai>=0.2,<0.4"` |
| `AuthenticationError: Incorrect API key` | `DUEL_API_KEY` unset or fails the `duel_` format | Set `DUEL_API_KEY` to a key from the dashboard |
| `ValidationError: field required (api_key)` | No `api_key` argument and `DUEL_API_KEY` env unset | Pass `api_key=` or export `DUEL_API_KEY` |
Compatibility Notes
- Python 3.8: not supported — `requires-python` rejects it and built-in `dict[...]` syntax in source would error without `from __future__ import annotations` (which is present, but the version gate still blocks install).
- LangChain Core 0.2: not supported — the `<0.4` upper and `>=0.3.15` lower bound require 0.3.x; `model_validator(mode="before")` depends on Pydantic v2 shipped with Core 0.3.
- LangChain serialization: `is_lc_serializable` returns `False`, so `ChatDuel` instances cannot be round-tripped through the LangChain loader (third-party namespaces are not registered).
- No GPU: all inference is delegated to the Duel proxy; this package only constructs HTTP requests.