Skip to main content

launchdarkly-ai-openai-agents

OpenAI handler for launchdarkly-ai-server using the OpenAI Agents SDK (openai-agents). Delegates the full agentic loop — tool calls, retries, and orchestration — to the Agents SDK.

provides_for: ['OpenAI', 'agent'] — matches flag variations where provider.name is "OpenAI" and meta.mode is "agent".

Installation

pip install "launchdarkly-ai-server[ld]" launchdarkly-ai-openai-agents

Set OPENAI_API_KEY in your environment (the OpenAI SDK reads it automatically).

Usage

With config()

import asyncio
from launchdarkly_ai_server import config, shutdown
from launchdarkly_ai_openai_agents import create_openai_agents_handler

async def main():
    result = await config(
        key="my-ai-config-flag",
        handler=create_openai_agents_handler(),
        tool_handlers={"search": lambda q: "..."},
    ).invoke("Summarize today's changelog", {"kind": "user", "key": "user-123"})

    print(result.response)
    await shutdown()

asyncio.run(main())

Tool handlers may be sync or async. Sync handlers run on the event-loop thread, so blocking I/O stalls the agent. Keep graph __handoff_* handlers synchronous: routing records the selected edge on the call itself, and moving them onto asyncio.to_thread would break that.

Convenience wrapper

import asyncio
from launchdarkly_ai_openai_agents import openai_agents

async def main():
    user_input = "Summarize today's changelog"
    result = await openai_agents(
        user_input,
        {"kind": "user", "key": "user-123"},
        {"key": "my-ai-config-flag"},
        variables={"user_input": user_input},
    )
    print(result.response)

asyncio.run(main())

Agent graphs — openai_graph()

Runs a LaunchDarkly agent graph with the OpenAI agent handler pre-bound. Equivalent to calling the base graph() with handlers=[create_openai_agents_handler()]. See the core client docs for the full graph() API.

import asyncio
from launchdarkly_ai_openai_agents import openai_graph

async def main():
    result = await openai_graph("support-graph").invoke(
        "I was double charged",
        {"kind": "user", "key": "user-123"},
    )
    print(result["response"])

asyncio.run(main())

Native graph adapter — to_openai_agents()

Converts a resolve_graph() result into a framework-native OpenAI Agents swarm (post-order traversal: leaves → root). Children are wired as handoffs; the root is run with Runner.run.

import asyncio
from launchdarkly_ai_server import resolve_graph
from launchdarkly_ai_openai_agents import to_openai_agents

async def main():
    ctx = {"kind": "user", "key": "user-123"}
    result = await to_openai_agents(
        resolve_graph("support-graph", context=ctx),
        {"tool_handlers": registry.tools, "context": ctx},
    ).call("I was double charged")
    print(result["response"])

asyncio.run(main())

How It Works

  • Uses the system prompt and tools defined in your LaunchDarkly flag config.
  • Template placeholders ({{variable}}) in the prompt are substituted using variables before the call.
  • The OpenAI Agents SDK manages the full agentic loop — tool dispatch, re-prompting, and termination — automatically.
  • Emits an OTel span and LaunchDarkly telemetry for every call.

Choosing Between openai-agents and openai-messages

openai-agents openai-messages
Underlying SDK openai-agents openai (Responses API)
Tool loop Managed by Agents SDK Executed and fed back manually
Complexity Lower (SDK manages loop) More explicit control

Environment Variables

Variable Description
OPENAI_API_KEY OpenAI API key (read automatically by the OpenAI SDK)
LD_SDK_KEY LaunchDarkly server-side SDK key
LD_SERVICE_NAME OTel service.name resource attribute (default: python-sdk)
LD_ENVIRONMENT deployment.environment attribute attached to telemetry
OTEL_EXPORTER_OTLP_ENDPOINT OTLP endpoint override (default: LaunchDarkly Observability backend)

Metadata

Release files for launchdarkly-ai-openai-agents 1.0.1

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-openai-agents 1.0.1
File Size Uploaded Provenance Actions
launchdarkly_ai_openai_agents-1.0.1.tar.gz 62.3 kB Without provenance Details for launchdarkly_ai_openai_agents-1.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 89.9 kB

Release files / launchdarkly_ai_openai_agents-1.0.1.tar.gz

Download URL launchdarkly_ai_openai_agents-1.0.1.tar.gz
Size 62.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b14a6b9b04dd1ea863c22e7122a147ff3b5b246addfc3cc5dd5a0e726fbf857d
BLAKE2b-256 checksum
How to use checksums
ff55c4ceb3f7418114ddd130b947b2afbf3a88f49583699952554d8f1dbdfde9
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_openai_agents-1.0.1-py3-none-any.whl

Download URL launchdarkly_ai_openai_agents-1.0.1-py3-none-any.whl
Size 27.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
203e0acff962d07090f7a2055029891138def56a673b9432a0fb9f55bf27b236
BLAKE2b-256 checksum
How to use checksums
42dac6ee3e2b7194e6c40e665873c01998db1efab9a3c3f39d1a09e8f15ebed2
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-openai-agents 1.0.1

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