Skip to main content

launchdarkly-ai-opencode-agents

OpenCode handler for launchdarkly-ai-server. async with handler starts opencode serve and waits until it is healthy. The process stops when that context exits. It does not depend on an OpenCode SDK.

provides_for: ['*', 'agent'] — matches an agent-mode variation for any provider.

pip install "launchdarkly-ai-server[ld]" launchdarkly-ai-opencode-agents
import asyncio
import os

from launchdarkly_ai_opencode_agents import create_opencode_handler
from launchdarkly_ai_server import config, init_client, shutdown


async def main() -> None:
    await init_client()
    handler = create_opencode_handler(
        cwd="/work",
        config="/home/app/.vega/opencode.json",
        env=os.environ.copy(),
    )
    async with handler:
        async for event in config(key="my-agent", handler=handler).stream(
            "Hello", {"kind": "user", "key": "user-1"}
        ):
            print(event)
    await shutdown()


asyncio.run(main())

cwd is the working directory, config is the OpenCode config file, and env is the child environment. The handler sets OPENCODE_CONFIG from config, replaces any OPENCODE_SERVER_USERNAME in env with opencode, replaces any OPENCODE_SERVER_PASSWORD with a generated secret, and binds opencode serve to loopback. Requests to that server use that username and secret as basic auth. A caller does not pass a URL, an HTTP client, or a transport. command overrides the opencode executable; a test passes a fake executable there.

Entering the handler starts opencode serve and returns once it is healthy. The process stops when the context exits, after config().stream() returns. Put a wall-clock limit around config().stream(), not around the context. The handler yields AG-UI text and tool events. config().stream() yields chunk then done.

Tools

The AI Config's tools, filtered to the keys also present in tool_handlers, is the only catalog the model sees for one call — every other tool on the running opencode serve, including every built-in, is denied. A variation with no tools (and every judge, which always calls with tool_handlers=None) gets a model with no tools at all.

from launchdarkly_ai_opencode_agents import OpenCodeBash, OpenCodeRead

response = await config(
    key="my-agent",
    handler=handler,
    tool_handlers={
        "run-shell": OpenCodeBash,       # an OpenCode built-in, allowed by name
        "read-file": OpenCodeRead,
        "get-weather": get_weather,      # a plain callable, served from a per-call bridge
    },
).invoke(user_input, context)

A NativeTool (see OpenCodeBash, OpenCodeRead, and the rest of this package's sentinels) names an OpenCode built-in or a server-configured MCP tool directly — OpenCode already has it, so the handler only allows it for this call's session. The sentinels match the tool ids at OpenCode v1.18.4. That tag has no list tool. OpenCodeWrite and OpenCodeApplyPatch are the same grant as OpenCodeEdit: OpenCode remaps write and apply_patch onto the edit permission, and the session ruleset sends edit. A plain callable has no route into OpenCode otherwise: POST /session/{id}/message's own tools field is a deprecated boolean permission map, not a place to describe one. Each call with at least one callable starts its own loopback MCP server, registers it on the running opencode serve with POST /mcp, and disconnects it when the call ends. HTTP 200 is not success: the response body is a status map, and the call fails unless that server's status is connected. This is unit-tested directly (test_tool_bridge.py) and through the handler against a fake opencode serve (test_tool_contract.py); it has not been exercised against a real OpenCode MCP client.

chat and execute_tool spans are opened and closed from the same bus events the AG-UI stream is derived from, named after the AI Config key (not OpenCode's own tool id or the bridge's composed MCP name).

Metadata

Release files for launchdarkly-ai-opencode-agents 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for launchdarkly-ai-opencode-agents 1.0.2
File Size Uploaded Provenance Actions
launchdarkly_ai_opencode_agents-1.0.2.tar.gz 54.7 kB Without provenance Details for launchdarkly_ai_opencode_agents-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for launchdarkly-ai-opencode-agents 1.0.2
File Interpreter ABI Platform Actions
launchdarkly_ai_opencode_agents-1.0.2-py3-none-any.whl Python 3 none any Details for launchdarkly_ai_opencode_agents-1.0.2-py3-none-any.whl

Total release size: 86.3 kB

Release files / launchdarkly_ai_opencode_agents-1.0.2.tar.gz

Download URL launchdarkly_ai_opencode_agents-1.0.2.tar.gz
Size 54.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1fa9e095c0e9fa19784d8cbf5f6b4ba6a03651e36571b4506ba8c9e6977e0ff5
BLAKE2b-256 checksum
How to use checksums
e6fd1d62dd1f6e6f180df9b61a4a3e49b147395abac5edde56bd0eae55e7404e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / launchdarkly_ai_opencode_agents-1.0.2-py3-none-any.whl

Download URL launchdarkly_ai_opencode_agents-1.0.2-py3-none-any.whl
Size 31.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d32df4dbcd28f5a43648574021b16591cf8cf05e5d170960c83503cff20fac38
BLAKE2b-256 checksum
How to use checksums
8a25a080f6c918b8aa23e5fb4e0cb278475578a383bfd379bdb3982ff3613415
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for launchdarkly-ai-opencode-agents 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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