Skip to main content

langchain-opsen

Run LangChain deepagents on opsen — with machine, model and tool spend on one bill and a budget the runtime enforces mid-run.

pip install langchain-opsen
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 here:

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:

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_opsen-0.1.3.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_opsen-0.1.3-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file langchain_opsen-0.1.3.tar.gz.

File metadata

  • Download URL: langchain_opsen-0.1.3.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for langchain_opsen-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8e2ba2a6925a04b50947bd1d84dd3c9bc1143a71de065ac7ac0b454e81641c90
MD5 de0ecd279c7e0aa2c1707929c53856b3
BLAKE2b-256 ed609447baffbaca305c79c01270d56434a55c9304cd2ca395dcf36d4b70cea4

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_opsen-0.1.3.tar.gz:

Publisher: release.yml on md322613/opsen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_opsen-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_opsen-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 014db4a01f706b99b4f352d05585cdf0744f7b6ee3458925c893f0bd57c41bad
MD5 2f757fa0c018cb23b40fec2172ac4a23
BLAKE2b-256 189a682e01decde619b8825c6b77c3f3c3814a659ba8da15db6cd29498ec1f9a

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_opsen-0.1.3-py3-none-any.whl:

Publisher: release.yml on md322613/opsen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

This release

0.1.3 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page