Metadata-Version: 2.4
Name: langchain-opsen
Version: 0.1.1
Summary: Run LangChain deepagents on opsen — machine, model and tool spend on one bill.
Author: opsen
License: Apache-2.0
Project-URL: Homepage, https://opsen.dev
Project-URL: Source, https://github.com/md322613/opsen
Keywords: langchain,deepagents,agents,sandbox,opsen
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: opsen>=0.1.0
Provides-Extra: test
Requires-Dist: deepagents>=0.7; extra == "test"

# langchain-opsen

Run LangChain [deepagents](https://github.com/langchain-ai/deepagents) on
[opsen](https://opsen.dev) — with machine, model and tool spend on one
bill and a budget the runtime enforces mid-run.

```bash
pip install langchain-opsen
```

```python
from deepagents import create_deep_agent
from langchain_anthropic import ChatAnthropic
from langchain_opsen import OpsenSandbox

agent = create_deep_agent(
    model=ChatAnthropic(model="claude-sonnet-4-6"),
    system_prompt="You are a Python coding assistant.",
    backend=OpsenSandbox(task_id="nightly-report", budget_usd=2.00),
)
```

Set `OPSEN_API_KEY`, or pass `api_key=`. Get one at
[opsen.dev/keys](https://opsen.dev/keys).

## What this adds

Every sandbox backend bills you for the machine and leaves the model bill
with a different vendor, on a different invoice, with no shared
identifier. Two bills, reconciled by hand, and no answer to "what did that
agent cost".

opsen sits in both paths, so:

```python
agent_cost = backend.cost()
# {'total_usd': 0.41, 'compute_usd': 0.02, 'tokens_usd': 0.39,
#  'calls': 34, 'input_tokens': 84120, 'output_tokens': 9310,
#  'task_id': 'nightly-report'}
```

`budget_usd` is a ceiling the gateway enforces **during** the run. An
agent that would cross it is refused mid-flight rather than noticed
afterwards on an invoice.

## Behaviour worth knowing

**The session starts lazily.** Constructing `OpsenSandbox` starts no
machine — the first command does. An agent built and never run costs
nothing.

**File operations and the shell share one channel.** Both go through the
same exec path, so the file tools and `execute()` always agree about the
working directory.

**Ports depend on the runtime.** `host(port)` works on E2B, works on
Modal when the port was declared at sandbox creation, and raises on the
local runtime with a message naming the limitation. A provider that hands
back a URL which does not answer turns "preview my server" into a
debugging session.

## Configuration

| Argument | Default | Meaning |
| --- | --- | --- |
| `api_key` | `$OPSEN_API_KEY` | From opsen.dev/keys |
| `task_id` | `"deepagents"` | Groups this agent's spend. One id, one line on the spend page. |
| `budget_usd` | none | Hard ceiling, enforced mid-run |
| `labels` | `{}` | Arbitrary tags — customer, environment, whatever you group by |
| `base_url` | `https://opsen.dev` | For self-hosted deployments |
| `timeout` | `300` | Default seconds per command |

## Licence

Apache-2.0
