Skip to main content

launchdarkly-ai-claude-agents

Anthropic Claude handler for launchdarkly-ai-server using the Claude Agent SDK (claude-agent-sdk). Runs an agentic query loop with native MCP tool support.

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

Installation

pip install launchdarkly-ai-server launchdarkly-ai-claude-agents

Set ANTHROPIC_API_KEY in your environment (the Anthropic SDK reads it automatically).

Usage

With config()

import asyncio
from launchdarkly_ai_server import config, shutdown
from launchdarkly_ai_claude_agents import create_claude_agents_handler

async def main():
    result = await config(
        key="my-ai-config-flag",
        handler=create_claude_agents_handler(),
        tool_handlers={"search": lambda q: "..."},
    ).invoke("What is feature flagging?", {"kind": "user", "key": "user-123"})

    print(result.response)
    await shutdown()

asyncio.run(main())

Convenience wrapper

import asyncio
from launchdarkly_ai_claude_agents import claude_agents

async def main():
    user_input = "What is feature flagging?"
    result = await claude_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 — claude_graph()

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

import asyncio
from launchdarkly_ai_claude_agents import claude_graph

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

asyncio.run(main())

Native graph adapter — to_claude_agents()

Converts a resolve_graph() result into a framework-native Claude sub-agent tree (post-order traversal: leaves → root). Each child node is wrapped as an in-process MCP tool; the root runs a single query() with its children accessible as sub-agent tools. No cloud-registered agents required.

import asyncio
from launchdarkly_ai_server import resolve_graph
from launchdarkly_ai_claude_agents import to_claude_agents

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

asyncio.run(main())

How It Works

  • Uses the system prompt and conversation history defined in your LaunchDarkly flag config.
  • Template placeholders ({{variable}}) in the prompt are substituted using variables before the call.
  • If tools are defined in the flag config, the Claude Agent SDK handles all tool dispatch and the agentic loop automatically — no extra wiring needed.
  • Emits an OTel span and LaunchDarkly telemetry for every call.

Built-in Claude Tools

This package exports NativeTool sentinels for Claude Code built-in capabilities. Place them as values in tool_handlers to enable the corresponding native Claude tool without writing a handler function:

Export Claude SDK tool name
ClaudeBash Bash
ClaudeRead Read
ClaudeEdit Edit
ClaudeWrite Write
ClaudeGlob Glob
ClaudeGrep Grep
ClaudeWebFetch WebFetch
ClaudeWebSearch WebSearch
ClaudeTodoWrite TodoWrite
ClaudeNotebookEdit NotebookEdit
from launchdarkly_ai_claude_agents import ClaudeWebSearch, create_claude_agents_handler
from launchdarkly_ai_server import config

result = await config(
    key="my-ai-config-flag",
    tool_handlers={"web-search": ClaudeWebSearch},
    handler=[create_claude_agents_handler()],
).invoke("What are the latest LD release notes?", {"kind": "user", "key": "user-123"})

Environment Variables

Variable Description
ANTHROPIC_API_KEY Anthropic API key (read automatically by the Anthropic 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_claude_agents-0.1.4.tar.gz (23.0 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_claude_agents-0.1.4-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for launchdarkly_ai_claude_agents-0.1.4.tar.gz
Algorithm Hash digest
SHA256 c5d2ee965cb5a6aaa16709cd50a9a02e080290e977b4977d7e33bd7b21b8d4c4
MD5 f54802bc1a83c84f2ddbc20ecd45b321
BLAKE2b-256 f121fcda4d2011845de34d07e288511f0e7ebc22b8eb3ba132d8a5a75d326ff8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for launchdarkly_ai_claude_agents-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5463010d478c52b99a257330ed9744c0c0f6bb618237f5462302e8dc62e80801
MD5 864e4943f89a2d76869cd5c46385f771
BLAKE2b-256 a1b02f8f4c5f7d04d59d9538f0d369d88bc956761bc750150248c06b55a26f1b

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