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 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_agent_handler

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

    print(result.response)
    await shutdown()

asyncio.run(main())

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_agent_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)

Download files

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

Source Distribution

launchdarkly_ai_openai_agents-0.1.4.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

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

launchdarkly_ai_openai_agents-0.1.4-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file launchdarkly_ai_openai_agents-0.1.4.tar.gz.

File metadata

File hashes

Hashes for launchdarkly_ai_openai_agents-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2cf14003c597cf152aa1da214c3620fb05a45869767f904e6f1f2079498ef38d
MD5 0bbd5e97b65638a539eddcc1781300cc
BLAKE2b-256 34653543ef6e73baee273d8de67d2b2abd2619163cf063d9d9b2381e33cfc09f

See more details on using hashes here.

File details

Details for the file launchdarkly_ai_openai_agents-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for launchdarkly_ai_openai_agents-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8c35455ca5f72623a28d3777d8eaba2a85801ddbed1d65a6fefc0d3410a58c08
MD5 604944ed88703b911b9801bc796ff6af
BLAKE2b-256 47d83870d1f516dfe7552341caa71a7c333b341dc08176daa267ebc99f869e96

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page