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[ld]" 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())
Handler options
create_claude_agents_handler() takes keyword arguments:
| Option | Default | Description |
|---|---|---|
capture_content |
None |
Put prompts, model output, and tool arguments and results on the emitted spans. None follows configure(), which is on by default. An explicit False leaves them off. |
cwd |
the process's working directory | Working directory for the Claude Code process the Agent SDK starts. A str or path-like. |
setting_sources |
[] (none) |
Which Claude Code settings sources to load: "user" (~/.claude/settings.json), "project" (.claude/settings.json, and CLAUDE.md), "local" (.claude/settings.local.json). |
These configure the host process, not the model, so only your application can set them. A flag's model parameters can't set or override either one. claude_agents(), claude_graph() and to_claude_agents() take cwd and setting_sources too, with the same defaults.
A run loads none of the host's Claude Code settings unless you opt in. The Claude Agent SDK's own default loads the user, project and local settings of the machine it runs on, including their plugins, skills, hooks, permission rules and
CLAUDE.md. This handler sendssetting_sources=[]instead, so an agent runs from its LaunchDarkly config alone. To load host settings, name the sources:create_claude_agents_handler(setting_sources=["user", "project", "local"])The Agent SDK still reads the managed-settings policy tier (managed settings files and MDM) whatever you pass.
Migrating from a version that loaded host settings
Earlier versions left setting_sources unset, so the Agent SDK loaded every settings source on the host. A run now loads none of them. Anything a deployment configured through those files stops applying, including:
- plugins, skills, hooks, permission rules and
CLAUDE.md - the
envblock, for exampleANTHROPIC_BASE_URL,CLAUDE_CODE_USE_BEDROCKorCLAUDE_CODE_USE_VERTEX, and proxy variables apiKeyHelperandmodel
A deployment that reaches Bedrock, Vertex or a gateway through ~/.claude/settings.json fails to authenticate after the upgrade. To fix it, either set those variables in the process environment, or load the source that holds them:
create_claude_agents_handler(setting_sources=["user"])
claude_agents("my-ai-config-flag", user_input, context, setting_sources=["user"])
claude_graph("support-graph", setting_sources=["user"])
to_claude_agents(
resolve_graph("support-graph", context=context),
{"context": context, "setting_sources": ["user"]},
)
Output limit and thinking
max_tokensin the config's model parameters sets the output-token limit for each model request. The Agent SDK has no option for it, so the handler setsCLAUDE_CODE_MAX_OUTPUT_TOKENSin the environment of the Claude Code process. Withoutmax_tokens, Claude Code uses its own default. ACLAUDE_CODE_MAX_OUTPUT_TOKENSin theenvof a Claude Code settings file, including~/.claude.json, wins overmax_tokens.- Thinking is off unless the config sets
thinkingormax_thinking_tokens. Models that reject disabled thinking, such asclaude-fable-5, still use their own default. Claude Code lowers a thinking budget to one less thanmax_tokens, so when a config sets both, keepmax_tokensabove the budget.
Migrating from a version that used Claude Code's thinking default
Earlier versions passed no thinking setting when the config had none, so Claude Code chose one: adaptive thinking on models that support it, and a 31,999-token budget on others such as claude-haiku-4-5. A run now thinks only when its config asks. To keep thinking, set it in the config's model parameters, for example {"thinking": {"type": "adaptive"}}.
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())
Agent Skills
create_claude_agents_handler() doesn't give the model a variation's skills. create_claude_agents_skills_handler() does. It takes the same options, plus skills_temp_dir.
import os
from launchdarkly_ai_server import LaunchDarklySkillStore, config, set_skill_store
from launchdarkly_ai_claude_agents import create_claude_agents_skills_handler
store = LaunchDarklySkillStore(os.environ["LD_SDK_KEY"]).start()
store.wait_for_skills(timeout=10)
set_skill_store(store)
triage = config(
key="triage-agent",
handler=create_claude_agents_skills_handler(setting_sources=[]),
)
On every invoke and stream it:
- Writes the variation's
skillsinto a new directory underskills_temp_dir(default:tempfile.gettempdir()), through the store you configured withset_skill_store. Pinned versions are honored. - Hands that directory to the Claude Agent SDK as a local plugin named
launchdarkly, enables only those skills (launchdarkly:<key>), and turns on theSkilltool. - Removes the directory when the run ends, whether it succeeded, failed, or a stream was abandoned.
Each run has its own directory, so concurrent runs and different variations never share files, and nothing needs to watch for changes. Detaching a skill from a variation takes effect on the next run.
setting_sources behaves as on the core factory and is always sent, [] unless you give sources. Without it, claude-agent-sdk would load the user and project settings sources whenever skills are enabled.
A run whose skills can't be written doesn't start. The handler raises before the model is called if no store is configured, the store hasn't received its first payload, a skill fails integrity verification, or a pinned version isn't in the store. The error names each skill. A variation with no skills runs exactly as it would with create_claude_agents_handler(), and needs no store.
A Skill call shows up in traces as an execute_tool Skill span.
Not covered yet: claude_agents(), claude_graph() and to_claude_agents() use the core handler, so a variation run through them doesn't get its skills.
How It Works
- Uses the system prompt and conversation history defined in your LaunchDarkly flag config.
- Template placeholders (
{{variable}}) in the prompt are substituted usingvariablesbefore 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
A run has no Claude Code built-in tools (Read, Bash, and the rest) unless its config attaches them. Tools you define in the flag config are always available to the model through the handler's MCP server, whatever built-ins are attached.
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) |
Metadata
Release files for launchdarkly-ai-claude-agents 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| launchdarkly_ai_claude_agents-1.0.0.tar.gz | 83.4 kB | Without provenance | Details for launchdarkly_ai_claude_agents-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| launchdarkly_ai_claude_agents-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for launchdarkly_ai_claude_agents-1.0.0-py3-none-any.whl |
Total release size: 122.0 kB
Release files / launchdarkly_ai_claude_agents-1.0.0.tar.gz
| Download URL | launchdarkly_ai_claude_agents-1.0.0.tar.gz |
|---|---|
| Size | 83.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
06cc0c37c8f4dd984447284b48d1e5180f2ef9bbb4c4716cc785fe2007637b9b
|
|
BLAKE2b-256 checksum How to use checksums |
eebc29f05d0c316630285b0ef823e7d424aa950b3b665ab75fefc3599ab14f8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / launchdarkly_ai_claude_agents-1.0.0-py3-none-any.whl
| Download URL | launchdarkly_ai_claude_agents-1.0.0-py3-none-any.whl |
|---|---|
| Size | 38.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
48e1b8f3d9f72ade97cda4b60e9016faa88dabd6f7a7fdb39ceedafc79fd1d94
|
|
BLAKE2b-256 checksum How to use checksums |
9cfcca93d216a125a614cd61c4a48cf5b434f371cb348b4450b622b4cb598889
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for launchdarkly-ai-claude-agents 1.0.0
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.