From 465aaae89b6a28a0993a295c2923503c6ea08c38 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 27 Apr 2026 22:09:58 +0000 Subject: [PATCH 1/8] docs: add per-example READMEs with .env support - Create individual README files for each example (openai, bedrock, gemini, langchain, langgraph-agent, langgraph-multi-agent, judge, chat-observability) - Add python-dotenv dependency and load_dotenv() to all examples - Add .env to .gitignore - Update main README to link to example READMEs via table Co-Authored-By: traci@launchdarkly.com --- .gitignore | 1 + README.md | 105 ++++------------------ examples/bedrock/README.md | 43 +++++++++ examples/bedrock_example.py | 3 + examples/chat-observability/README.md | 48 ++++++++++ examples/chat_judge_example.py | 3 + examples/chat_observability_example.py | 3 + examples/direct_judge_example.py | 3 + examples/gemini/README.md | 34 +++++++ examples/gemini_example.py | 3 + examples/judge/README.md | 54 +++++++++++ examples/langchain/README.md | 42 +++++++++ examples/langchain_example.py | 3 + examples/langgraph-agent/README.md | 42 +++++++++ examples/langgraph-multi-agent/README.md | 44 +++++++++ examples/langgraph_agent_example.py | 3 + examples/langgraph_multi_agent_example.py | 3 + examples/openai/README.md | 34 +++++++ examples/openai_example.py | 3 + pyproject.toml | 1 + 20 files changed, 385 insertions(+), 90 deletions(-) create mode 100644 examples/bedrock/README.md create mode 100644 examples/chat-observability/README.md create mode 100644 examples/gemini/README.md create mode 100644 examples/judge/README.md create mode 100644 examples/langchain/README.md create mode 100644 examples/langgraph-agent/README.md create mode 100644 examples/langgraph-multi-agent/README.md create mode 100644 examples/openai/README.md diff --git a/.gitignore b/.gitignore index 36c1b23..1daee47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .python-version poetry.lock __pycache__/ +.env diff --git a/README.md b/README.md index 490c7d9..66a07f7 100644 --- a/README.md +++ b/README.md @@ -8,106 +8,31 @@ This demo requires Python 3.10 or higher. ## Build Instructions -This repository includes examples for `OpenAI`, `Bedrock`, and `LangChain` for multi-provider support. Depending on your preferred provider, you may have to take some additional steps. +This repository includes examples for `OpenAI`, `Bedrock`, `Gemini`, `LangChain`, `LangGraph`, `Judge`, and `Observability`. Depending on your preferred provider, you may have to take some additional steps. ### General setup 1. [Create an AI Config](https://launchdarkly.com/docs/home/ai-configs/create) using the key specified in each example, or copy the key of existing AI Config in your LaunchDarkly project that you want to evaluate. -1. Set the environment variable `LAUNCHDARKLY_SDK_KEY` to your LaunchDarkly SDK key and `LAUNCHDARKLY_AI_CONFIG_KEY` to the AI Config key; otherwise, an AI Config of `sample-ai-config` or `sample-ai-agent-config` will be assumed for most examples. - - ```bash - export LAUNCHDARKLY_SDK_KEY="1234567890abcdef" - export LAUNCHDARKLY_AI_CONFIG_KEY="sample-ai-config" - ``` 1. Ensure you have [Poetry](https://python-poetry.org/) installed. -### Provider-Specific Setup - -#### OpenAI setup (single provider) - -1. Install the required dependencies with `poetry install -E openai` or `poetry install --all-extras`. -1. Set the environment variable `OPENAI_API_KEY` to your OpenAI key. -1. On the command line, run `poetry run openai-example`. - -#### Chat with observability (observability plugin example) - -This example demonstrates how to use the LaunchDarkly observability SDK plugin to monitor AI chat operations. For more details, see the [Python SDK observability reference](https://launchdarkly.com/docs/sdk/observability/python). +1. Create a `.env` file in the repository root with at least your LaunchDarkly SDK key: -1. Install the required dependencies with `poetry install -E observability` or `poetry install --all-extras`. -1. Set the environment variable for your AI provider (e.g., `OPENAI_API_KEY`), or configure your AI Config to use a different provider. -1. Optionally, set service identification: - ```bash - export SERVICE_NAME="my-ai-service" - export SERVICE_VERSION="1.0.0" ``` -1. On the command line, run `poetry run chat-observability-example`. - -The observability plugin automatically captures and sends data to LaunchDarkly: -- **Observability tab**: SDK operations, flag evaluations, error monitoring, logging, and distributed tracing -- **AI Config Monitoring tab**: Token usage, duration, success/error rates, and custom metadata for filtering and analysis - -View your data in the LaunchDarkly dashboard under **Observability** tabs. - -#### Bedrock setup (single provider) - -1. Install the required dependencies with `poetry install -E bedrock` or `poetry install --all-extras`. -1. Ensure the required AWS credentials can be [auto-detected by the `boto3` library](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html). Examples might include environment variables, role providers, or shared credential files. -1. On the command line, run `poetry run bedrock-example`. - -#### Gemini setup (single provider) - -1. Install the required dependencies with `poetry install -E gemini` or `poetry install --all-extras`. -1. Set the environment variable `GOOGLE_API_KEY` to your Google API key. -1. On the command line, run `poetry run gemini-example`. - -#### LangChain setup (multiple providers) - -This example uses `OpenAI`, `Bedrock`, and `Gemini` LangChain provider packages. You can add additional LangChain providers using the `poetry add` command. - -1. Install all dependencies with `poetry install -E langchain` or `poetry install --all-extras`. -1. Set up API keys for the providers you want to use. -1. On the command line, run `poetry run langchain-example` - -#### LangGraph setup (multiple providers, single agent) - -1. Install all dependencies with `poetry install -E langgraph` or `poetry install --all-extras`. -1. Set up API keys for the providers you want to use. -1. Optionally set this environment variable to use a different agent config: - ```bash - export LAUNCHDARKLY_AGENT_CONFIG_KEY="sample-ai-agent-config" + LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key ``` -1. On the command line, run `poetry run langgraph-agent-example`. - -#### LangGraph setup (multiple providers, multiple agents) -1. Install all dependencies with `poetry install -E langgraph` or `poetry install --all-extras`. -1. Set up API keys for the providers you want to use. -1. [Create an AI Config (Agent-based)](https://launchdarkly.com/docs/home/ai-configs/agents) using the keys below. Write a goal for each config and enable it with targeting rules. -1. Optionally set these environment variables to use different agent configs: - ```bash - export LAUNCHDARKLY_ANALYZER_CONFIG_KEY="code-review-analyzer" - export LAUNCHDARKLY_DOCUMENTATION_CONFIG_KEY="code-review-documentation" - ``` -1. On the command line, run `poetry run langgraph-multi-agent-example`. - -#### Judge setup (judge evaluation) - -These examples demonstrate how to use LaunchDarkly's judge functionality to evaluate AI responses for accuracy, relevance, and other metrics. - -1. Install dependencies with `poetry install -E langchain` or `poetry install --all-extras`. -1. Set up API keys for the provider you want to use (OpenAI, Bedrock, or Gemini). -1. [Create an AI Config](https://launchdarkly.com/docs/home/ai-configs/create) for chat functionality. -1. [Create a Judge Config](https://launchdarkly.com/docs/home/ai-configs/judges) for evaluation. -1. Set the required environment variables: - ```bash - export LAUNCHDARKLY_SDK_KEY="your-sdk-key" - export LAUNCHDARKLY_AI_CONFIG_KEY="sample-ai-config" - export LAUNCHDARKLY_AI_JUDGE_KEY="sample-ai-judge-accuracy" - ``` - Note: The default values are `sample-ai-config` for AI Config and `sample-ai-judge-accuracy` for Judge Config if not specified. + Each example README describes the full set of environment variables needed. The `.env` file is loaded automatically when running any example. -##### Available judge examples: +### Examples -- **Chat with automatic judge evaluation** (`poetry run chat-judge-example`): Uses the chat functionality which automatically evaluates responses with any judges defined in the AI config. -- **Direct judge evaluation** (`poetry run direct-judge-example`): Evaluates specific input/output pairs using a judge configuration directly. +| Example | Description | README | +| --- | --- | --- | +| **OpenAI** | Single provider using OpenAI | [examples/openai](examples/openai/README.md) | +| **Bedrock** | Single provider using AWS Bedrock | [examples/bedrock](examples/bedrock/README.md) | +| **Gemini** | Single provider using Google Gemini | [examples/gemini](examples/gemini/README.md) | +| **LangChain** | Multiple providers via LangChain | [examples/langchain](examples/langchain/README.md) | +| **LangGraph Agent** | Single agent using LangGraph | [examples/langgraph-agent](examples/langgraph-agent/README.md) | +| **LangGraph Multi-Agent** | Multiple agents using LangGraph | [examples/langgraph-multi-agent](examples/langgraph-multi-agent/README.md) | +| **Judge** | Judge evaluation of AI responses | [examples/judge](examples/judge/README.md) | +| **Chat with Observability** | Observability plugin for AI chat monitoring | [examples/chat-observability](examples/chat-observability/README.md) | diff --git a/examples/bedrock/README.md b/examples/bedrock/README.md new file mode 100644 index 0000000..0965194 --- /dev/null +++ b/examples/bedrock/README.md @@ -0,0 +1,43 @@ +# Bedrock Example (Single Provider) + +This example demonstrates how to use LaunchDarkly's AI Config with the AWS Bedrock provider. + +## Prerequisites + +- Python 3.10 or higher +- [Poetry](https://python-poetry.org/) installed +- A LaunchDarkly account with an [AI Config](https://launchdarkly.com/docs/home/ai-configs/create) created +- AWS credentials configured for Bedrock access + +## Setup + +1. Create a `.env` file in the repository root with the following variables: + + ``` + LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key + LAUNCHDARKLY_AI_CONFIG_KEY=sample-ai-config + ``` + + > `LAUNCHDARKLY_AI_CONFIG_KEY` defaults to `sample-ai-config` if not set. + +2. Ensure your AWS credentials can be [auto-detected by the `boto3` library](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html). You can set them in your `.env` file: + + ``` + AWS_ACCESS_KEY_ID=your-access-key-id + AWS_SECRET_ACCESS_KEY=your-secret-access-key + AWS_DEFAULT_REGION=us-east-1 + ``` + + Other options include role providers or shared credential files. + +3. Install the required dependencies: + + ```bash + poetry install -E bedrock + ``` + +## Run + +```bash +poetry run bedrock-example +``` diff --git a/examples/bedrock_example.py b/examples/bedrock_example.py index ad87994..eafdaa1 100755 --- a/examples/bedrock_example.py +++ b/examples/bedrock_example.py @@ -1,10 +1,13 @@ import os +from dotenv import load_dotenv import ldclient from ldclient import Context from ldclient.config import Config from ldai import LDAIClient import boto3 +load_dotenv() + client = boto3.client("bedrock-runtime", region_name="us-east-1") # Set sdk_key to your LaunchDarkly SDK key. diff --git a/examples/chat-observability/README.md b/examples/chat-observability/README.md new file mode 100644 index 0000000..732f481 --- /dev/null +++ b/examples/chat-observability/README.md @@ -0,0 +1,48 @@ +# Chat with Observability (Observability Plugin Example) + +This example demonstrates how to use the LaunchDarkly observability SDK plugin to monitor AI chat operations. For more details, see the [Python SDK observability reference](https://launchdarkly.com/docs/sdk/observability/python). + +The observability plugin automatically captures and sends data to LaunchDarkly: + +- **Observability tab**: SDK operations, flag evaluations, error monitoring, logging, and distributed tracing +- **AI Config Monitoring tab**: Token usage, duration, success/error rates, and custom metadata for filtering and analysis + +View your data in the LaunchDarkly dashboard under **Observability** tabs. + +## Prerequisites + +- Python 3.10 or higher +- [Poetry](https://python-poetry.org/) installed +- A LaunchDarkly account with an [AI Config](https://launchdarkly.com/docs/home/ai-configs/create) created +- An API key for your AI provider (e.g., OpenAI) + +## Setup + +1. Create a `.env` file in the repository root with the following variables: + + ``` + LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key + LAUNCHDARKLY_AI_CONFIG_KEY=sample-ai-config + OPENAI_API_KEY=your-openai-api-key + ``` + + > `LAUNCHDARKLY_AI_CONFIG_KEY` defaults to `sample-ai-config` if not set. + + Optionally, set service identification: + + ``` + SERVICE_NAME=my-ai-service + SERVICE_VERSION=1.0.0 + ``` + +2. Install the required dependencies: + + ```bash + poetry install -E observability + ``` + +## Run + +```bash +poetry run chat-observability-example +``` diff --git a/examples/chat_judge_example.py b/examples/chat_judge_example.py index 57094f8..ca99daa 100644 --- a/examples/chat_judge_example.py +++ b/examples/chat_judge_example.py @@ -1,4 +1,5 @@ import os +from dotenv import load_dotenv import json import asyncio import ldclient @@ -6,6 +7,8 @@ from ldclient.config import Config from ldai import LDAIClient, AICompletionConfigDefault +load_dotenv() + # Set sdk_key to your LaunchDarkly SDK key. sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') diff --git a/examples/chat_observability_example.py b/examples/chat_observability_example.py index 296ec4d..1ecc7f7 100644 --- a/examples/chat_observability_example.py +++ b/examples/chat_observability_example.py @@ -1,4 +1,5 @@ import os +from dotenv import load_dotenv import asyncio import logging import ldclient @@ -7,6 +8,8 @@ from ldai import LDAIClient, AICompletionConfigDefault from ldobserve import ObservabilityConfig, ObservabilityPlugin +load_dotenv() + logging.getLogger('ldclient').setLevel(logging.WARNING) # Set sdk_key to your LaunchDarkly SDK key. diff --git a/examples/direct_judge_example.py b/examples/direct_judge_example.py index 7d2faa6..f8126d4 100644 --- a/examples/direct_judge_example.py +++ b/examples/direct_judge_example.py @@ -1,4 +1,5 @@ import os +from dotenv import load_dotenv import json import asyncio import ldclient @@ -6,6 +7,8 @@ from ldclient.config import Config from ldai import LDAIClient, AIJudgeConfigDefault +load_dotenv() + # Set sdk_key to your LaunchDarkly SDK key. sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') diff --git a/examples/gemini/README.md b/examples/gemini/README.md new file mode 100644 index 0000000..157dac3 --- /dev/null +++ b/examples/gemini/README.md @@ -0,0 +1,34 @@ +# Gemini Example (Single Provider) + +This example demonstrates how to use LaunchDarkly's AI Config with the Google Gemini provider. + +## Prerequisites + +- Python 3.10 or higher +- [Poetry](https://python-poetry.org/) installed +- A LaunchDarkly account with an [AI Config](https://launchdarkly.com/docs/home/ai-configs/create) created +- A [Google API key](https://aistudio.google.com/apikey) + +## Setup + +1. Create a `.env` file in the repository root with the following variables: + + ``` + LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key + LAUNCHDARKLY_AI_CONFIG_KEY=sample-ai-config + GOOGLE_API_KEY=your-google-api-key + ``` + + > `LAUNCHDARKLY_AI_CONFIG_KEY` defaults to `sample-ai-config` if not set. + +2. Install the required dependencies: + + ```bash + poetry install -E gemini + ``` + +## Run + +```bash +poetry run gemini-example +``` diff --git a/examples/gemini_example.py b/examples/gemini_example.py index d53735e..ac2bcd3 100644 --- a/examples/gemini_example.py +++ b/examples/gemini_example.py @@ -1,4 +1,5 @@ import os +from dotenv import load_dotenv import ldclient from ldclient import Context from ldclient.config import Config @@ -8,6 +9,8 @@ from google.genai import types from typing import List, Optional, Tuple +load_dotenv() + # Set sdk_key to your LaunchDarkly SDK key. sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') diff --git a/examples/judge/README.md b/examples/judge/README.md new file mode 100644 index 0000000..bb9e4da --- /dev/null +++ b/examples/judge/README.md @@ -0,0 +1,54 @@ +# Judge Examples (Judge Evaluation) + +These examples demonstrate how to use LaunchDarkly's judge functionality to evaluate AI responses for accuracy, relevance, and other metrics. + +## Prerequisites + +- Python 3.10 or higher +- [Poetry](https://python-poetry.org/) installed +- A LaunchDarkly account with an [AI Config](https://launchdarkly.com/docs/home/ai-configs/create) created for chat functionality +- A [Judge Config](https://launchdarkly.com/docs/home/ai-configs/judges) created for evaluation +- API keys for the provider you want to use (OpenAI, Bedrock, or Gemini) + +## Setup + +1. Create a `.env` file in the repository root with the following variables: + + ``` + LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key + LAUNCHDARKLY_AI_CONFIG_KEY=sample-ai-config + LAUNCHDARKLY_AI_JUDGE_KEY=sample-ai-judge-accuracy + ``` + + > `LAUNCHDARKLY_AI_CONFIG_KEY` defaults to `sample-ai-config` if not set. + > `LAUNCHDARKLY_AI_JUDGE_KEY` defaults to `sample-ai-judge-accuracy` if not set. + + Add the API key for your chosen provider: + + ``` + OPENAI_API_KEY=your-openai-api-key + ``` + +2. Install the required dependencies: + + ```bash + poetry install -E langchain + ``` + +## Run + +### Chat with automatic judge evaluation + +Uses the chat functionality which automatically evaluates responses with any judges defined in the AI config. + +```bash +poetry run chat-judge-example +``` + +### Direct judge evaluation + +Evaluates specific input/output pairs using a judge configuration directly. + +```bash +poetry run direct-judge-example +``` diff --git a/examples/langchain/README.md b/examples/langchain/README.md new file mode 100644 index 0000000..715955a --- /dev/null +++ b/examples/langchain/README.md @@ -0,0 +1,42 @@ +# LangChain Example (Multiple Providers) + +This example demonstrates how to use LaunchDarkly's AI Config with LangChain, supporting multiple providers including OpenAI, Bedrock, and Gemini. You can add additional LangChain providers using the `poetry add` command. + +## Prerequisites + +- Python 3.10 or higher +- [Poetry](https://python-poetry.org/) installed +- A LaunchDarkly account with an [AI Config](https://launchdarkly.com/docs/home/ai-configs/create) created +- API keys for the providers you want to use + +## Setup + +1. Create a `.env` file in the repository root with the following variables: + + ``` + LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key + LAUNCHDARKLY_AI_CONFIG_KEY=sample-ai-config + ``` + + > `LAUNCHDARKLY_AI_CONFIG_KEY` defaults to `sample-ai-config` if not set. + + Add the API keys for the providers you want to use: + + ``` + OPENAI_API_KEY=your-openai-api-key + GOOGLE_API_KEY=your-google-api-key + AWS_ACCESS_KEY_ID=your-access-key-id + AWS_SECRET_ACCESS_KEY=your-secret-access-key + ``` + +2. Install the required dependencies: + + ```bash + poetry install -E langchain + ``` + +## Run + +```bash +poetry run langchain-example +``` diff --git a/examples/langchain_example.py b/examples/langchain_example.py index 60e604f..836e1eb 100644 --- a/examples/langchain_example.py +++ b/examples/langchain_example.py @@ -1,4 +1,5 @@ import os +from dotenv import load_dotenv import asyncio import ldclient from ldclient import Context @@ -7,6 +8,8 @@ from ldai_langchain import get_ai_metrics_from_response from langchain.chat_models import init_chat_model +load_dotenv() + # Set sdk_key to your LaunchDarkly SDK key. sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') diff --git a/examples/langgraph-agent/README.md b/examples/langgraph-agent/README.md new file mode 100644 index 0000000..877a488 --- /dev/null +++ b/examples/langgraph-agent/README.md @@ -0,0 +1,42 @@ +# LangGraph Agent Example (Single Agent) + +This example demonstrates how to use LaunchDarkly's AI Config with LangGraph to create a single ReAct agent with tool support. + +## Prerequisites + +- Python 3.10 or higher +- [Poetry](https://python-poetry.org/) installed +- A LaunchDarkly account with an [AI Config (Agent-based)](https://launchdarkly.com/docs/home/ai-configs/agents) created +- API keys for the providers you want to use + +## Setup + +1. Create a `.env` file in the repository root with the following variables: + + ``` + LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key + LAUNCHDARKLY_AGENT_CONFIG_KEY=sample-ai-agent-config + ``` + + > `LAUNCHDARKLY_AGENT_CONFIG_KEY` defaults to `sample-ai-agent-config` if not set. + + Add the API keys for the providers you want to use: + + ``` + OPENAI_API_KEY=your-openai-api-key + GOOGLE_API_KEY=your-google-api-key + AWS_ACCESS_KEY_ID=your-access-key-id + AWS_SECRET_ACCESS_KEY=your-secret-access-key + ``` + +2. Install the required dependencies: + + ```bash + poetry install -E langgraph + ``` + +## Run + +```bash +poetry run langgraph-agent-example +``` diff --git a/examples/langgraph-multi-agent/README.md b/examples/langgraph-multi-agent/README.md new file mode 100644 index 0000000..1589479 --- /dev/null +++ b/examples/langgraph-multi-agent/README.md @@ -0,0 +1,44 @@ +# LangGraph Multi-Agent Example (Multiple Agents) + +This example demonstrates how to use LaunchDarkly's AI Config with LangGraph to orchestrate multiple agents in a code review workflow. + +## Prerequisites + +- Python 3.10 or higher +- [Poetry](https://python-poetry.org/) installed +- A LaunchDarkly account with [AI Configs (Agent-based)](https://launchdarkly.com/docs/home/ai-configs/agents) created using the keys below. Write a goal for each config and enable it with targeting rules. +- API keys for the providers you want to use + +## Setup + +1. Create a `.env` file in the repository root with the following variables: + + ``` + LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key + LAUNCHDARKLY_ANALYZER_CONFIG_KEY=code-review-analyzer + LAUNCHDARKLY_DOCUMENTATION_CONFIG_KEY=code-review-documentation + ``` + + > `LAUNCHDARKLY_ANALYZER_CONFIG_KEY` defaults to `code-review-analyzer` if not set. + > `LAUNCHDARKLY_DOCUMENTATION_CONFIG_KEY` defaults to `code-review-documentation` if not set. + + Add the API keys for the providers you want to use: + + ``` + OPENAI_API_KEY=your-openai-api-key + GOOGLE_API_KEY=your-google-api-key + AWS_ACCESS_KEY_ID=your-access-key-id + AWS_SECRET_ACCESS_KEY=your-secret-access-key + ``` + +2. Install the required dependencies: + + ```bash + poetry install -E langgraph + ``` + +## Run + +```bash +poetry run langgraph-multi-agent-example +``` diff --git a/examples/langgraph_agent_example.py b/examples/langgraph_agent_example.py index 37f5212..f65b0d7 100644 --- a/examples/langgraph_agent_example.py +++ b/examples/langgraph_agent_example.py @@ -1,4 +1,5 @@ import os +from dotenv import load_dotenv import ldclient from pprint import pprint from ldclient import Context @@ -9,6 +10,8 @@ from langchain.chat_models import init_chat_model from langgraph.prebuilt import create_react_agent +load_dotenv() + # Set sdk_key to your LaunchDarkly SDK key. sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') diff --git a/examples/langgraph_multi_agent_example.py b/examples/langgraph_multi_agent_example.py index 424b30f..8325074 100644 --- a/examples/langgraph_multi_agent_example.py +++ b/examples/langgraph_multi_agent_example.py @@ -1,4 +1,5 @@ import os +from dotenv import load_dotenv import ldclient from ldclient import Context from ldclient.config import Config @@ -11,6 +12,8 @@ from langgraph.types import Command from typing_extensions import TypedDict +load_dotenv() + # Set sdk_key to your LaunchDarkly SDK key. sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') diff --git a/examples/openai/README.md b/examples/openai/README.md new file mode 100644 index 0000000..ede5e59 --- /dev/null +++ b/examples/openai/README.md @@ -0,0 +1,34 @@ +# OpenAI Example (Single Provider) + +This example demonstrates how to use LaunchDarkly's AI Config with the OpenAI provider. + +## Prerequisites + +- Python 3.10 or higher +- [Poetry](https://python-poetry.org/) installed +- A LaunchDarkly account with an [AI Config](https://launchdarkly.com/docs/home/ai-configs/create) created +- An [OpenAI API key](https://platform.openai.com/api-keys) + +## Setup + +1. Create a `.env` file in the repository root with the following variables: + + ``` + LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key + LAUNCHDARKLY_AI_CONFIG_KEY=sample-ai-config + OPENAI_API_KEY=your-openai-api-key + ``` + + > `LAUNCHDARKLY_AI_CONFIG_KEY` defaults to `sample-ai-config` if not set. + +2. Install the required dependencies: + + ```bash + poetry install -E openai + ``` + +## Run + +```bash +poetry run openai-example +``` diff --git a/examples/openai_example.py b/examples/openai_example.py index 168d8e8..0a11e5c 100755 --- a/examples/openai_example.py +++ b/examples/openai_example.py @@ -1,4 +1,5 @@ import os +from dotenv import load_dotenv import ldclient from ldclient import Context from ldclient.config import Config @@ -6,6 +7,8 @@ from ldai_openai import get_ai_metrics_from_response from openai import OpenAI +load_dotenv() + openai_client = OpenAI() # Set sdk_key to your LaunchDarkly SDK key. diff --git a/pyproject.toml b/pyproject.toml index a6b3c4f..c72a9d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ direct-judge-example = 'examples.direct_judge_example:main' [tool.poetry.dependencies] python = "^3.10" +python-dotenv = ">=1.0.0" launchdarkly-server-sdk-ai = "^0.17.0" launchdarkly-server-sdk-ai-langchain = "^0.4.0" launchdarkly-server-sdk-ai-openai = "^0.3.0" From 5fc3b0d70fe13c898bec503a17162139f34d49e6 Mon Sep 17 00:00:00 2001 From: Traci Siebel Date: Tue, 28 Apr 2026 09:52:40 -0700 Subject: [PATCH 2/8] chore: move example files into their respective subdirectories Co-Authored-By: Claude Sonnet 4.6 --- examples/{ => bedrock}/bedrock_example.py | 0 examples/{ => chat-observability}/chat_observability_example.py | 0 examples/{ => gemini}/gemini_example.py | 0 examples/{ => judge}/chat_judge_example.py | 0 examples/{ => judge}/direct_judge_example.py | 0 examples/{ => langchain}/langchain_example.py | 0 examples/{ => langgraph-agent}/langgraph_agent_example.py | 0 .../{ => langgraph-multi-agent}/langgraph_multi_agent_example.py | 0 examples/{ => openai}/openai_example.py | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename examples/{ => bedrock}/bedrock_example.py (100%) rename examples/{ => chat-observability}/chat_observability_example.py (100%) rename examples/{ => gemini}/gemini_example.py (100%) rename examples/{ => judge}/chat_judge_example.py (100%) rename examples/{ => judge}/direct_judge_example.py (100%) rename examples/{ => langchain}/langchain_example.py (100%) rename examples/{ => langgraph-agent}/langgraph_agent_example.py (100%) rename examples/{ => langgraph-multi-agent}/langgraph_multi_agent_example.py (100%) rename examples/{ => openai}/openai_example.py (100%) diff --git a/examples/bedrock_example.py b/examples/bedrock/bedrock_example.py similarity index 100% rename from examples/bedrock_example.py rename to examples/bedrock/bedrock_example.py diff --git a/examples/chat_observability_example.py b/examples/chat-observability/chat_observability_example.py similarity index 100% rename from examples/chat_observability_example.py rename to examples/chat-observability/chat_observability_example.py diff --git a/examples/gemini_example.py b/examples/gemini/gemini_example.py similarity index 100% rename from examples/gemini_example.py rename to examples/gemini/gemini_example.py diff --git a/examples/chat_judge_example.py b/examples/judge/chat_judge_example.py similarity index 100% rename from examples/chat_judge_example.py rename to examples/judge/chat_judge_example.py diff --git a/examples/direct_judge_example.py b/examples/judge/direct_judge_example.py similarity index 100% rename from examples/direct_judge_example.py rename to examples/judge/direct_judge_example.py diff --git a/examples/langchain_example.py b/examples/langchain/langchain_example.py similarity index 100% rename from examples/langchain_example.py rename to examples/langchain/langchain_example.py diff --git a/examples/langgraph_agent_example.py b/examples/langgraph-agent/langgraph_agent_example.py similarity index 100% rename from examples/langgraph_agent_example.py rename to examples/langgraph-agent/langgraph_agent_example.py diff --git a/examples/langgraph_multi_agent_example.py b/examples/langgraph-multi-agent/langgraph_multi_agent_example.py similarity index 100% rename from examples/langgraph_multi_agent_example.py rename to examples/langgraph-multi-agent/langgraph_multi_agent_example.py diff --git a/examples/openai_example.py b/examples/openai/openai_example.py similarity index 100% rename from examples/openai_example.py rename to examples/openai/openai_example.py From 6b331e748c2cc9c91a603fe83599e5fa2c3a6bee Mon Sep 17 00:00:00 2001 From: Traci Siebel Date: Tue, 28 Apr 2026 09:58:42 -0700 Subject: [PATCH 3/8] chore: fix pyproject.toml script paths and rename hyphenated folders - Rename langgraph-agent, langgraph-multi-agent, chat-observability to use underscores so they are valid Python packages - Add __init__.py to each example subfolder - Update pyproject.toml script paths to reflect new module locations Co-Authored-By: Claude Sonnet 4.6 --- examples/bedrock/__init__.py | 0 .../README.md | 0 examples/chat_observability/__init__.py | 0 .../chat_observability_example.py | 0 examples/gemini/__init__.py | 0 examples/judge/__init__.py | 0 examples/langchain/__init__.py | 0 .../README.md | 0 examples/langgraph_agent/__init__.py | 0 .../langgraph_agent_example.py | 0 .../README.md | 0 examples/langgraph_multi_agent/__init__.py | 0 .../langgraph_multi_agent_example.py | 0 examples/openai/__init__.py | 0 pyproject.toml | 18 +++++++++--------- 15 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 examples/bedrock/__init__.py rename examples/{chat-observability => chat_observability}/README.md (100%) create mode 100644 examples/chat_observability/__init__.py rename examples/{chat-observability => chat_observability}/chat_observability_example.py (100%) create mode 100644 examples/gemini/__init__.py create mode 100644 examples/judge/__init__.py create mode 100644 examples/langchain/__init__.py rename examples/{langgraph-agent => langgraph_agent}/README.md (100%) create mode 100644 examples/langgraph_agent/__init__.py rename examples/{langgraph-agent => langgraph_agent}/langgraph_agent_example.py (100%) rename examples/{langgraph-multi-agent => langgraph_multi_agent}/README.md (100%) create mode 100644 examples/langgraph_multi_agent/__init__.py rename examples/{langgraph-multi-agent => langgraph_multi_agent}/langgraph_multi_agent_example.py (100%) create mode 100644 examples/openai/__init__.py diff --git a/examples/bedrock/__init__.py b/examples/bedrock/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/examples/chat-observability/README.md b/examples/chat_observability/README.md similarity index 100% rename from examples/chat-observability/README.md rename to examples/chat_observability/README.md diff --git a/examples/chat_observability/__init__.py b/examples/chat_observability/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/examples/chat-observability/chat_observability_example.py b/examples/chat_observability/chat_observability_example.py similarity index 100% rename from examples/chat-observability/chat_observability_example.py rename to examples/chat_observability/chat_observability_example.py diff --git a/examples/gemini/__init__.py b/examples/gemini/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/examples/judge/__init__.py b/examples/judge/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/examples/langchain/__init__.py b/examples/langchain/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/examples/langgraph-agent/README.md b/examples/langgraph_agent/README.md similarity index 100% rename from examples/langgraph-agent/README.md rename to examples/langgraph_agent/README.md diff --git a/examples/langgraph_agent/__init__.py b/examples/langgraph_agent/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/examples/langgraph-agent/langgraph_agent_example.py b/examples/langgraph_agent/langgraph_agent_example.py similarity index 100% rename from examples/langgraph-agent/langgraph_agent_example.py rename to examples/langgraph_agent/langgraph_agent_example.py diff --git a/examples/langgraph-multi-agent/README.md b/examples/langgraph_multi_agent/README.md similarity index 100% rename from examples/langgraph-multi-agent/README.md rename to examples/langgraph_multi_agent/README.md diff --git a/examples/langgraph_multi_agent/__init__.py b/examples/langgraph_multi_agent/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/examples/langgraph-multi-agent/langgraph_multi_agent_example.py b/examples/langgraph_multi_agent/langgraph_multi_agent_example.py similarity index 100% rename from examples/langgraph-multi-agent/langgraph_multi_agent_example.py rename to examples/langgraph_multi_agent/langgraph_multi_agent_example.py diff --git a/examples/openai/__init__.py b/examples/openai/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml index c72a9d0..953d082 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,15 +8,15 @@ readme = "README.md" packages = [ { include = "examples" } ] [tool.poetry.scripts] -bedrock-example = 'examples.bedrock_example:main' -openai-example = 'examples.openai_example:main' -gemini-example = 'examples.gemini_example:main' -langchain-example = 'examples.langchain_example:main' -langgraph-agent-example = 'examples.langgraph_agent_example:main' -langgraph-multi-agent-example = 'examples.langgraph_multi_agent_example:main' -chat-judge-example = 'examples.chat_judge_example:main' -chat-observability-example = 'examples.chat_observability_example:main' -direct-judge-example = 'examples.direct_judge_example:main' +bedrock-example = 'examples.bedrock.bedrock_example:main' +openai-example = 'examples.openai.openai_example:main' +gemini-example = 'examples.gemini.gemini_example:main' +langchain-example = 'examples.langchain.langchain_example:main' +langgraph-agent-example = 'examples.langgraph_agent.langgraph_agent_example:main' +langgraph-multi-agent-example = 'examples.langgraph_multi_agent.langgraph_multi_agent_example:main' +chat-judge-example = 'examples.judge.chat_judge_example:main' +chat-observability-example = 'examples.chat_observability.chat_observability_example:main' +direct-judge-example = 'examples.judge.direct_judge_example:main' [tool.poetry.dependencies] python = "^3.10" From 675765f36e4199d8ef54c900048e7a9d5b706dd8 Mon Sep 17 00:00:00 2001 From: Traci Siebel Date: Tue, 28 Apr 2026 11:28:28 -0700 Subject: [PATCH 4/8] chore: make each example self-contained with its own pyproject.toml - Add per-example pyproject.toml with only the dependencies that example needs; no extras flags required, just `poetry install` - Remove __init__.py files (no longer needed as Python packages) - Simplify root pyproject.toml, removing scripts/extras/packages - Update READMEs to reflect local .env and plain `poetry install` Co-Authored-By: Claude Sonnet 4.6 --- examples/bedrock/README.md | 4 +- examples/bedrock/__init__.py | 0 examples/bedrock/pyproject.toml | 21 +++++++++++ examples/chat_observability/README.md | 4 +- examples/chat_observability/__init__.py | 0 examples/chat_observability/pyproject.toml | 22 +++++++++++ examples/gemini/README.md | 4 +- examples/gemini/__init__.py | 0 examples/gemini/pyproject.toml | 21 +++++++++++ examples/judge/README.md | 4 +- examples/judge/__init__.py | 0 examples/judge/pyproject.toml | 24 ++++++++++++ examples/langchain/README.md | 4 +- examples/langchain/__init__.py | 0 examples/langchain/pyproject.toml | 26 +++++++++++++ examples/langgraph_agent/README.md | 4 +- examples/langgraph_agent/__init__.py | 0 examples/langgraph_agent/pyproject.toml | 27 ++++++++++++++ examples/langgraph_multi_agent/README.md | 4 +- examples/langgraph_multi_agent/__init__.py | 0 examples/langgraph_multi_agent/pyproject.toml | 28 ++++++++++++++ examples/openai/README.md | 4 +- examples/openai/__init__.py | 0 examples/openai/pyproject.toml | 22 +++++++++++ pyproject.toml | 37 +------------------ 25 files changed, 208 insertions(+), 52 deletions(-) delete mode 100644 examples/bedrock/__init__.py create mode 100644 examples/bedrock/pyproject.toml delete mode 100644 examples/chat_observability/__init__.py create mode 100644 examples/chat_observability/pyproject.toml delete mode 100644 examples/gemini/__init__.py create mode 100644 examples/gemini/pyproject.toml delete mode 100644 examples/judge/__init__.py create mode 100644 examples/judge/pyproject.toml delete mode 100644 examples/langchain/__init__.py create mode 100644 examples/langchain/pyproject.toml delete mode 100644 examples/langgraph_agent/__init__.py create mode 100644 examples/langgraph_agent/pyproject.toml delete mode 100644 examples/langgraph_multi_agent/__init__.py create mode 100644 examples/langgraph_multi_agent/pyproject.toml delete mode 100644 examples/openai/__init__.py create mode 100644 examples/openai/pyproject.toml diff --git a/examples/bedrock/README.md b/examples/bedrock/README.md index 0965194..af7a6a2 100644 --- a/examples/bedrock/README.md +++ b/examples/bedrock/README.md @@ -11,7 +11,7 @@ This example demonstrates how to use LaunchDarkly's AI Config with the AWS Bedro ## Setup -1. Create a `.env` file in the repository root with the following variables: +1. Create a `.env` file in this directory with the following variables: ``` LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key @@ -33,7 +33,7 @@ This example demonstrates how to use LaunchDarkly's AI Config with the AWS Bedro 3. Install the required dependencies: ```bash - poetry install -E bedrock + poetry install ``` ## Run diff --git a/examples/bedrock/__init__.py b/examples/bedrock/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/bedrock/pyproject.toml b/examples/bedrock/pyproject.toml new file mode 100644 index 0000000..323cab0 --- /dev/null +++ b/examples/bedrock/pyproject.toml @@ -0,0 +1,21 @@ +[tool.poetry] +name = "hello-python-ai-bedrock" +version = "0.1.0" +description = "Hello LaunchDarkly for Python AI - Bedrock" +authors = ["LaunchDarkly "] +license = "Apache-2.0" +readme = "README.md" +packages = [{include = "bedrock_example.py"}] + +[tool.poetry.scripts] +bedrock-example = "bedrock_example:main" + +[tool.poetry.dependencies] +python = "^3.10" +python-dotenv = ">=1.0.0" +launchdarkly-server-sdk-ai = "^0.17.0" +boto3 = ">=0.2.0" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/examples/chat_observability/README.md b/examples/chat_observability/README.md index 732f481..6af7b83 100644 --- a/examples/chat_observability/README.md +++ b/examples/chat_observability/README.md @@ -18,7 +18,7 @@ View your data in the LaunchDarkly dashboard under **Observability** tabs. ## Setup -1. Create a `.env` file in the repository root with the following variables: +1. Create a `.env` file in this directory with the following variables: ``` LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key @@ -38,7 +38,7 @@ View your data in the LaunchDarkly dashboard under **Observability** tabs. 2. Install the required dependencies: ```bash - poetry install -E observability + poetry install ``` ## Run diff --git a/examples/chat_observability/__init__.py b/examples/chat_observability/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/chat_observability/pyproject.toml b/examples/chat_observability/pyproject.toml new file mode 100644 index 0000000..2860356 --- /dev/null +++ b/examples/chat_observability/pyproject.toml @@ -0,0 +1,22 @@ +[tool.poetry] +name = "hello-python-ai-chat-observability" +version = "0.1.0" +description = "Hello LaunchDarkly for Python AI - Chat with Observability" +authors = ["LaunchDarkly "] +license = "Apache-2.0" +readme = "README.md" +packages = [{include = "chat_observability_example.py"}] + +[tool.poetry.scripts] +chat-observability-example = "chat_observability_example:main" + +[tool.poetry.dependencies] +python = "^3.10" +python-dotenv = ">=1.0.0" +launchdarkly-server-sdk-ai = "^0.17.0" +launchdarkly-observability = ">=0.1.0" +openai = ">=0.2.0" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/examples/gemini/README.md b/examples/gemini/README.md index 157dac3..5b7422d 100644 --- a/examples/gemini/README.md +++ b/examples/gemini/README.md @@ -11,7 +11,7 @@ This example demonstrates how to use LaunchDarkly's AI Config with the Google Ge ## Setup -1. Create a `.env` file in the repository root with the following variables: +1. Create a `.env` file in this directory with the following variables: ``` LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key @@ -24,7 +24,7 @@ This example demonstrates how to use LaunchDarkly's AI Config with the Google Ge 2. Install the required dependencies: ```bash - poetry install -E gemini + poetry install ``` ## Run diff --git a/examples/gemini/__init__.py b/examples/gemini/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/gemini/pyproject.toml b/examples/gemini/pyproject.toml new file mode 100644 index 0000000..df28938 --- /dev/null +++ b/examples/gemini/pyproject.toml @@ -0,0 +1,21 @@ +[tool.poetry] +name = "hello-python-ai-gemini" +version = "0.1.0" +description = "Hello LaunchDarkly for Python AI - Gemini" +authors = ["LaunchDarkly "] +license = "Apache-2.0" +readme = "README.md" +packages = [{include = "gemini_example.py"}] + +[tool.poetry.scripts] +gemini-example = "gemini_example:main" + +[tool.poetry.dependencies] +python = "^3.10" +python-dotenv = ">=1.0.0" +launchdarkly-server-sdk-ai = "^0.17.0" +google-genai = "^1.30.0" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/examples/judge/README.md b/examples/judge/README.md index bb9e4da..1f0ccf6 100644 --- a/examples/judge/README.md +++ b/examples/judge/README.md @@ -12,7 +12,7 @@ These examples demonstrate how to use LaunchDarkly's judge functionality to eval ## Setup -1. Create a `.env` file in the repository root with the following variables: +1. Create a `.env` file in this directory with the following variables: ``` LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key @@ -32,7 +32,7 @@ These examples demonstrate how to use LaunchDarkly's judge functionality to eval 2. Install the required dependencies: ```bash - poetry install -E langchain + poetry install ``` ## Run diff --git a/examples/judge/__init__.py b/examples/judge/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/judge/pyproject.toml b/examples/judge/pyproject.toml new file mode 100644 index 0000000..3c6ad90 --- /dev/null +++ b/examples/judge/pyproject.toml @@ -0,0 +1,24 @@ +[tool.poetry] +name = "hello-python-ai-judge" +version = "0.1.0" +description = "Hello LaunchDarkly for Python AI - Judge" +authors = ["LaunchDarkly "] +license = "Apache-2.0" +readme = "README.md" +packages = [ + {include = "chat_judge_example.py"}, + {include = "direct_judge_example.py"}, +] + +[tool.poetry.scripts] +chat-judge-example = "chat_judge_example:main" +direct-judge-example = "direct_judge_example:main" + +[tool.poetry.dependencies] +python = "^3.10" +python-dotenv = ">=1.0.0" +launchdarkly-server-sdk-ai = "^0.17.0" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/examples/langchain/README.md b/examples/langchain/README.md index 715955a..a4827df 100644 --- a/examples/langchain/README.md +++ b/examples/langchain/README.md @@ -11,7 +11,7 @@ This example demonstrates how to use LaunchDarkly's AI Config with LangChain, su ## Setup -1. Create a `.env` file in the repository root with the following variables: +1. Create a `.env` file in this directory with the following variables: ``` LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key @@ -32,7 +32,7 @@ This example demonstrates how to use LaunchDarkly's AI Config with LangChain, su 2. Install the required dependencies: ```bash - poetry install -E langchain + poetry install ``` ## Run diff --git a/examples/langchain/__init__.py b/examples/langchain/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/langchain/pyproject.toml b/examples/langchain/pyproject.toml new file mode 100644 index 0000000..4fe9151 --- /dev/null +++ b/examples/langchain/pyproject.toml @@ -0,0 +1,26 @@ +[tool.poetry] +name = "hello-python-ai-langchain" +version = "0.1.0" +description = "Hello LaunchDarkly for Python AI - LangChain" +authors = ["LaunchDarkly "] +license = "Apache-2.0" +readme = "README.md" +packages = [{include = "langchain_example.py"}] + +[tool.poetry.scripts] +langchain-example = "langchain_example:main" + +[tool.poetry.dependencies] +python = "^3.10" +python-dotenv = ">=1.0.0" +launchdarkly-server-sdk-ai = "^0.17.0" +launchdarkly-server-sdk-ai-langchain = "^0.4.0" +langchain = "^1.0.0" +langchain-core = "^1.0.0" +langchain-openai = "^1.0.0" +langchain-google-genai = "^4.0.0" +langchain-aws = "^1.0.0" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/examples/langgraph_agent/README.md b/examples/langgraph_agent/README.md index 877a488..a5be720 100644 --- a/examples/langgraph_agent/README.md +++ b/examples/langgraph_agent/README.md @@ -11,7 +11,7 @@ This example demonstrates how to use LaunchDarkly's AI Config with LangGraph to ## Setup -1. Create a `.env` file in the repository root with the following variables: +1. Create a `.env` file in this directory with the following variables: ``` LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key @@ -32,7 +32,7 @@ This example demonstrates how to use LaunchDarkly's AI Config with LangGraph to 2. Install the required dependencies: ```bash - poetry install -E langgraph + poetry install ``` ## Run diff --git a/examples/langgraph_agent/__init__.py b/examples/langgraph_agent/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/langgraph_agent/pyproject.toml b/examples/langgraph_agent/pyproject.toml new file mode 100644 index 0000000..b69c805 --- /dev/null +++ b/examples/langgraph_agent/pyproject.toml @@ -0,0 +1,27 @@ +[tool.poetry] +name = "hello-python-ai-langgraph-agent" +version = "0.1.0" +description = "Hello LaunchDarkly for Python AI - LangGraph Agent" +authors = ["LaunchDarkly "] +license = "Apache-2.0" +readme = "README.md" +packages = [{include = "langgraph_agent_example.py"}] + +[tool.poetry.scripts] +langgraph-agent-example = "langgraph_agent_example:main" + +[tool.poetry.dependencies] +python = "^3.10" +python-dotenv = ">=1.0.0" +launchdarkly-server-sdk-ai = "^0.17.0" +launchdarkly-server-sdk-ai-langchain = "^0.4.0" +langchain = "^1.0.0" +langchain-core = "^1.0.0" +langchain-openai = "^1.0.0" +langchain-google-genai = "^4.0.0" +langchain-aws = "^1.0.0" +langgraph = "^1.0.0" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/examples/langgraph_multi_agent/README.md b/examples/langgraph_multi_agent/README.md index 1589479..00e3566 100644 --- a/examples/langgraph_multi_agent/README.md +++ b/examples/langgraph_multi_agent/README.md @@ -11,7 +11,7 @@ This example demonstrates how to use LaunchDarkly's AI Config with LangGraph to ## Setup -1. Create a `.env` file in the repository root with the following variables: +1. Create a `.env` file in this directory with the following variables: ``` LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key @@ -34,7 +34,7 @@ This example demonstrates how to use LaunchDarkly's AI Config with LangGraph to 2. Install the required dependencies: ```bash - poetry install -E langgraph + poetry install ``` ## Run diff --git a/examples/langgraph_multi_agent/__init__.py b/examples/langgraph_multi_agent/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/langgraph_multi_agent/pyproject.toml b/examples/langgraph_multi_agent/pyproject.toml new file mode 100644 index 0000000..4d6a176 --- /dev/null +++ b/examples/langgraph_multi_agent/pyproject.toml @@ -0,0 +1,28 @@ +[tool.poetry] +name = "hello-python-ai-langgraph-multi-agent" +version = "0.1.0" +description = "Hello LaunchDarkly for Python AI - LangGraph Multi-Agent" +authors = ["LaunchDarkly "] +license = "Apache-2.0" +readme = "README.md" +packages = [{include = "langgraph_multi_agent_example.py"}] + +[tool.poetry.scripts] +langgraph-multi-agent-example = "langgraph_multi_agent_example:main" + +[tool.poetry.dependencies] +python = "^3.10" +python-dotenv = ">=1.0.0" +launchdarkly-server-sdk-ai = "^0.17.0" +launchdarkly-server-sdk-ai-langchain = "^0.4.0" +langchain = "^1.0.0" +langchain-core = "^1.0.0" +langchain-openai = "^1.0.0" +langchain-google-genai = "^4.0.0" +langchain-aws = "^1.0.0" +langgraph = "^1.0.0" +typing-extensions = ">=4.0.0" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/examples/openai/README.md b/examples/openai/README.md index ede5e59..87c94dc 100644 --- a/examples/openai/README.md +++ b/examples/openai/README.md @@ -11,7 +11,7 @@ This example demonstrates how to use LaunchDarkly's AI Config with the OpenAI pr ## Setup -1. Create a `.env` file in the repository root with the following variables: +1. Create a `.env` file in this directory with the following variables: ``` LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key @@ -24,7 +24,7 @@ This example demonstrates how to use LaunchDarkly's AI Config with the OpenAI pr 2. Install the required dependencies: ```bash - poetry install -E openai + poetry install ``` ## Run diff --git a/examples/openai/__init__.py b/examples/openai/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/openai/pyproject.toml b/examples/openai/pyproject.toml new file mode 100644 index 0000000..eac3493 --- /dev/null +++ b/examples/openai/pyproject.toml @@ -0,0 +1,22 @@ +[tool.poetry] +name = "hello-python-ai-openai" +version = "0.1.0" +description = "Hello LaunchDarkly for Python AI - OpenAI" +authors = ["LaunchDarkly "] +license = "Apache-2.0" +readme = "README.md" +packages = [{include = "openai_example.py"}] + +[tool.poetry.scripts] +openai-example = "openai_example:main" + +[tool.poetry.dependencies] +python = "^3.10" +python-dotenv = ">=1.0.0" +launchdarkly-server-sdk-ai = "^0.17.0" +launchdarkly-server-sdk-ai-openai = "^0.3.0" +openai = ">=0.2.0" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/pyproject.toml b/pyproject.toml index 953d082..f050b5e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,48 +1,13 @@ [tool.poetry] name = "hello-python-ai" version = "0.1.0" -description = "Hello LaunchDarkly for Python AI - OpenAI" +description = "Hello LaunchDarkly for Python AI" authors = ["LaunchDarkly "] license = "Apache-2.0" readme = "README.md" -packages = [ { include = "examples" } ] - -[tool.poetry.scripts] -bedrock-example = 'examples.bedrock.bedrock_example:main' -openai-example = 'examples.openai.openai_example:main' -gemini-example = 'examples.gemini.gemini_example:main' -langchain-example = 'examples.langchain.langchain_example:main' -langgraph-agent-example = 'examples.langgraph_agent.langgraph_agent_example:main' -langgraph-multi-agent-example = 'examples.langgraph_multi_agent.langgraph_multi_agent_example:main' -chat-judge-example = 'examples.judge.chat_judge_example:main' -chat-observability-example = 'examples.chat_observability.chat_observability_example:main' -direct-judge-example = 'examples.judge.direct_judge_example:main' [tool.poetry.dependencies] python = "^3.10" -python-dotenv = ">=1.0.0" -launchdarkly-server-sdk-ai = "^0.17.0" -launchdarkly-server-sdk-ai-langchain = "^0.4.0" -launchdarkly-server-sdk-ai-openai = "^0.3.0" -launchdarkly-observability = { version = ">=0.1.0", optional = true } - -boto3 = { version = ">=0.2.0", optional = true } -openai = { version = ">=0.2.0", optional = true } -google-genai = { version = "^1.30.0", optional = true } -langchain = {version = "^1.0.0", optional = true} -langchain-aws = {version = "^1.0.0", optional = true} -langchain-core = {version = "^1.0.0", optional = true} -langchain-google-genai = {version = "^4.0.0", optional = true} -langchain-openai = {version = "^1.0.0", optional = true} -langgraph = {version = "^1.0.0", optional = true} - -[tool.poetry.extras] -bedrock = ["boto3"] -openai = ["openai"] -gemini = ["google-genai"] -langchain = ["langchain", "langchain-core", "langchain-openai", "langchain-google-genai", "langchain-aws"] -langgraph = ["langgraph", "typing-extensions"] -observability = ["launchdarkly-observability", "openai"] [build-system] requires = ["poetry-core"] From 1f4722264e7b4e3093066c228ab969dbd3446ff2 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 28 Apr 2026 18:50:36 +0000 Subject: [PATCH 5/8] fix: address review feedback on example structure - Fix README table links to use underscores matching actual directory names - Add comment to root pyproject.toml directing users to example subdirectories - Add missing langchain and openai deps to judge pyproject.toml - Read AWS_DEFAULT_REGION from env in bedrock example instead of hardcoding - Fix openai version constraint from >=0.2.0 to >=1.0.0 Co-Authored-By: traci@launchdarkly.com --- README.md | 6 +++--- examples/bedrock/bedrock_example.py | 2 +- examples/judge/pyproject.toml | 2 ++ examples/openai/pyproject.toml | 2 +- pyproject.toml | 5 +++++ 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 66a07f7..ea1d587 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ This repository includes examples for `OpenAI`, `Bedrock`, `Gemini`, `LangChain` | **Bedrock** | Single provider using AWS Bedrock | [examples/bedrock](examples/bedrock/README.md) | | **Gemini** | Single provider using Google Gemini | [examples/gemini](examples/gemini/README.md) | | **LangChain** | Multiple providers via LangChain | [examples/langchain](examples/langchain/README.md) | -| **LangGraph Agent** | Single agent using LangGraph | [examples/langgraph-agent](examples/langgraph-agent/README.md) | -| **LangGraph Multi-Agent** | Multiple agents using LangGraph | [examples/langgraph-multi-agent](examples/langgraph-multi-agent/README.md) | +| **LangGraph Agent** | Single agent using LangGraph | [examples/langgraph_agent](examples/langgraph_agent/README.md) | +| **LangGraph Multi-Agent** | Multiple agents using LangGraph | [examples/langgraph_multi_agent](examples/langgraph_multi_agent/README.md) | | **Judge** | Judge evaluation of AI responses | [examples/judge](examples/judge/README.md) | -| **Chat with Observability** | Observability plugin for AI chat monitoring | [examples/chat-observability](examples/chat-observability/README.md) | +| **Chat with Observability** | Observability plugin for AI chat monitoring | [examples/chat_observability](examples/chat_observability/README.md) | diff --git a/examples/bedrock/bedrock_example.py b/examples/bedrock/bedrock_example.py index eafdaa1..b7e8a32 100755 --- a/examples/bedrock/bedrock_example.py +++ b/examples/bedrock/bedrock_example.py @@ -8,7 +8,7 @@ load_dotenv() -client = boto3.client("bedrock-runtime", region_name="us-east-1") +client = boto3.client("bedrock-runtime", region_name=os.getenv('AWS_DEFAULT_REGION', 'us-east-1')) # Set sdk_key to your LaunchDarkly SDK key. sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') diff --git a/examples/judge/pyproject.toml b/examples/judge/pyproject.toml index 3c6ad90..5ed3d74 100644 --- a/examples/judge/pyproject.toml +++ b/examples/judge/pyproject.toml @@ -18,6 +18,8 @@ direct-judge-example = "direct_judge_example:main" python = "^3.10" python-dotenv = ">=1.0.0" launchdarkly-server-sdk-ai = "^0.17.0" +launchdarkly-server-sdk-ai-langchain = "^0.4.0" +openai = ">=1.0.0" [build-system] requires = ["poetry-core"] diff --git a/examples/openai/pyproject.toml b/examples/openai/pyproject.toml index eac3493..9cc7f27 100644 --- a/examples/openai/pyproject.toml +++ b/examples/openai/pyproject.toml @@ -15,7 +15,7 @@ python = "^3.10" python-dotenv = ">=1.0.0" launchdarkly-server-sdk-ai = "^0.17.0" launchdarkly-server-sdk-ai-openai = "^0.3.0" -openai = ">=0.2.0" +openai = ">=1.0.0" [build-system] requires = ["poetry-core"] diff --git a/pyproject.toml b/pyproject.toml index f050b5e..03b0923 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,11 @@ authors = ["LaunchDarkly "] license = "Apache-2.0" readme = "README.md" +# Each example is self-contained with its own pyproject.toml. +# To run an example, cd into its directory under examples/ and run: +# poetry install && poetry run +# See each example's README for details. + [tool.poetry.dependencies] python = "^3.10" From 240e516bb6f6316a54fbdecc4f5148b311f9dd4f Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 28 Apr 2026 18:51:56 +0000 Subject: [PATCH 6/8] fix: add package-mode=false to root pyproject.toml for CI compatibility Co-Authored-By: traci@launchdarkly.com --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 03b0923..2359a42 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ description = "Hello LaunchDarkly for Python AI" authors = ["LaunchDarkly "] license = "Apache-2.0" readme = "README.md" +package-mode = false # Each example is self-contained with its own pyproject.toml. # To run an example, cd into its directory under examples/ and run: From b30d479818b647c63f6a4016dcd76af386096be5 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 28 Apr 2026 18:54:07 +0000 Subject: [PATCH 7/8] fix: add launchdarkly-server-sdk-ai-openai to judge dependencies Co-Authored-By: traci@launchdarkly.com --- examples/judge/pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/judge/pyproject.toml b/examples/judge/pyproject.toml index 5ed3d74..8305d36 100644 --- a/examples/judge/pyproject.toml +++ b/examples/judge/pyproject.toml @@ -18,6 +18,7 @@ direct-judge-example = "direct_judge_example:main" python = "^3.10" python-dotenv = ">=1.0.0" launchdarkly-server-sdk-ai = "^0.17.0" +launchdarkly-server-sdk-ai-openai = "^0.3.0" launchdarkly-server-sdk-ai-langchain = "^0.4.0" openai = ">=1.0.0" From 4cf10dbfa0a881d3213e6ad1bcd662d3ace2e06e Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 28 Apr 2026 19:25:42 +0000 Subject: [PATCH 8/8] chore: delete root pyproject.toml and update CI to install per-example Co-Authored-By: traci@launchdarkly.com --- .github/workflows/ci.yml | 6 +++++- pyproject.toml | 20 -------------------- 2 files changed, 5 insertions(+), 21 deletions(-) delete mode 100644 pyproject.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73e8bc1..45b57a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,4 +31,8 @@ jobs: uses: abatilo/actions-poetry@7b6d33e44b4f08d7021a1dee3c044e9c253d6439 - name: Install dependencies - run: poetry install --all-extras + run: | + for dir in examples/*/; do + echo "Installing $dir" + poetry -C "$dir" install + done diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index 2359a42..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,20 +0,0 @@ -[tool.poetry] -name = "hello-python-ai" -version = "0.1.0" -description = "Hello LaunchDarkly for Python AI" -authors = ["LaunchDarkly "] -license = "Apache-2.0" -readme = "README.md" -package-mode = false - -# Each example is self-contained with its own pyproject.toml. -# To run an example, cd into its directory under examples/ and run: -# poetry install && poetry run -# See each example's README for details. - -[tool.poetry.dependencies] -python = "^3.10" - -[build-system] -requires = ["poetry-core"] -build-backend = "poetry.core.masonry.api"