-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add LiteLLM messages and agents integrations #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andrewklatzke
wants to merge
6
commits into
main
Choose a base branch
from
aklatzke/AIC-3410/add-lite-llm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
78d8b9e
feat(AIC-3410): add LiteLLM integrations
andrewklatzke 0bfd96b
fix(AIC-3410): address LiteLLM Bugbot findings
andrewklatzke 9328171
fix(AIC-3410): close LiteLLM graph spans reliably
andrewklatzke 0e598ee
fix(AIC-3410): bind Agents SDK RunHooks before subclassing
andrewklatzke d5d8faa
Merge remote-tracking branch 'origin/main' into aklatzke/AIC-3410/add…
apucacao 3683c97
refactor(litellm-agents): rename the graph span to launchdarkly.graph
apucacao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| """ | ||
| Example: litellm_agents() — LiteLLM agents handler (wildcard provider). | ||
|
|
||
| Usage (via main.py): | ||
| python main.py litellm-agents <flag-key> "<user input>" | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
|
|
||
| from examples.tools import ( | ||
| fetch_launchdarkly_documentation, | ||
| get_preferences, | ||
| search_ld_documentation, | ||
| web_search, | ||
| ) | ||
| from examples.utils import new_context, write_output | ||
| from launchdarkly_ai_litellm_agents import litellm_agents | ||
|
|
||
|
|
||
| async def run(key: str, user_input: str) -> None: | ||
| response = await litellm_agents( | ||
| key, | ||
| user_input, | ||
| new_context(), | ||
| tool_handlers={ | ||
| "get-user-preferences": get_preferences, | ||
| "search-ld-documentation": search_ld_documentation, | ||
| "fetch-ld-documentation": fetch_launchdarkly_documentation, | ||
| "fetch-launchdarkly-documentation": fetch_launchdarkly_documentation, | ||
| "web-search": web_search, | ||
| }, | ||
| ) | ||
|
|
||
| print(json.dumps(response, indent=2, default=str)) | ||
| write_output(response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """ | ||
| Example: config() with LiteLLM handlers for messages and agents. | ||
|
|
||
| Python calls LiteLLM in-process, so provider-qualified models and aliases from | ||
| the evaluated AI Config are routed using the installed LiteLLM configuration. | ||
|
|
||
| Usage (via main.py): | ||
| python main.py litellm <flag-key> "<user input>" | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from examples.tools import ( | ||
| fetch_launchdarkly_documentation, | ||
| get_preferences, | ||
| search_ld_documentation, | ||
| web_search, | ||
| ) | ||
| from examples.utils import new_context, write_output | ||
| from launchdarkly_ai_litellm_agents import create_litellm_agents_handler | ||
| from launchdarkly_ai_litellm_messages import create_litellm_messages_handler | ||
| from launchdarkly_ai_server import config | ||
|
|
||
|
|
||
| async def run(key: str, user_input: str) -> None: | ||
| response = await config( | ||
| key=key, | ||
| handler=[ | ||
| create_litellm_messages_handler(), | ||
| create_litellm_agents_handler(), | ||
| ], | ||
| tool_handlers={ | ||
| "get-user-preferences": get_preferences, | ||
| "search-ld-documentation": search_ld_documentation, | ||
| "fetch-ld-documentation": fetch_launchdarkly_documentation, | ||
| "fetch-launchdarkly-documentation": fetch_launchdarkly_documentation, | ||
| "web-search": web_search, | ||
| }, | ||
| ).invoke(user_input, new_context(), variables={"user_input": user_input}) | ||
|
|
||
| write_output(response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| """ | ||
| Example: litellm_messages() — LiteLLM messages handler. | ||
|
|
||
| Usage (via main.py): | ||
| python main.py litellm-messages <flag-key> "<user input>" | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
|
|
||
| from examples.tools import ( | ||
| fetch_launchdarkly_documentation, | ||
| get_preferences, | ||
| search_ld_documentation, | ||
| web_search, | ||
| ) | ||
| from examples.utils import new_context, write_output | ||
| from launchdarkly_ai_litellm_messages import litellm_messages | ||
|
|
||
|
|
||
| async def run(key: str, user_input: str) -> None: | ||
| response = await litellm_messages( | ||
| key, | ||
| user_input, | ||
| new_context(), | ||
| tool_handlers={ | ||
| "get-user-preferences": get_preferences, | ||
| "search-ld-documentation": search_ld_documentation, | ||
| "fetch-ld-documentation": fetch_launchdarkly_documentation, | ||
| "fetch-launchdarkly-documentation": fetch_launchdarkly_documentation, | ||
| "web-search": web_search, | ||
| }, | ||
| variables={"user_input": user_input}, | ||
| ) | ||
|
|
||
| print(json.dumps(response, indent=2, default=str)) | ||
| write_output(response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # `launchdarkly-ai-litellm-agents` | ||
|
|
||
| Provider-agnostic LaunchDarkly AI Config and graph handlers built on the OpenAI | ||
| Agents SDK's `LitellmModel`. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pip install launchdarkly-ai-server launchdarkly-server-sdk launchdarkly-ai-litellm-agents | ||
| ``` | ||
|
|
||
| Python uses LiteLLM in-process; no proxy endpoint is required. Set the provider | ||
| credentials required by the models in your AI Config, such as | ||
| `OPENAI_API_KEY` or `ANTHROPIC_API_KEY`. Standard LiteLLM configuration, | ||
| gateways, and model aliases are supported. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```python | ||
| from launchdarkly_ai_litellm_agents import create_litellm_agents_handler | ||
| from launchdarkly_ai_server import config | ||
|
|
||
| result = await config( | ||
| key="assistant", | ||
| handler=create_litellm_agents_handler(), | ||
| ).invoke("Hello", {"kind": "user", "key": "user-123"}) | ||
| ``` | ||
|
|
||
| Each evaluated config model is authoritative and creates its own `LitellmModel`. | ||
| The package supports callable tools, structured output, streaming, the | ||
| `litellm_graph` convenience wrapper, and `to_litellm_agents` for native Agents | ||
| SDK handoffs. | ||
|
|
||
| Because this is a wildcard agent handler, do not register it together with | ||
| another `["*", "agent"]` handler such as LangChain in the same registry. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| [project] | ||
| name = "launchdarkly-ai-litellm-agents" | ||
| version = "0.1.0" | ||
| requires-python = ">=3.12" | ||
| dependencies = [ | ||
| "launchdarkly-ai-server", | ||
| "openai-agents[litellm]>=0.2.11", | ||
| "opentelemetry-api>=1.25", | ||
| ] | ||
| description = "LiteLLM-backed OpenAI Agents handler for LaunchDarkly AI SDK" | ||
| readme = "README.md" | ||
| license = "Apache-2.0" | ||
| authors = [{name = "LaunchDarkly", email = "team@launchdarkly.com"}] | ||
| keywords = ["launchdarkly", "ai", "litellm", "agents"] | ||
| classifiers = [ | ||
| "Development Status :: 3 - Alpha", | ||
| "Intended Audience :: Developers", | ||
| "License :: OSI Approved :: Apache Software License", | ||
| "Programming Language :: Python :: 3", | ||
| "Programming Language :: Python :: 3.12", | ||
| "Topic :: Software Development :: Libraries", | ||
| ] | ||
|
|
||
| [project.urls] | ||
| Homepage = "https://github.com/launchdarkly/python-ai-sdk" | ||
| Repository = "https://github.com/launchdarkly/python-ai-sdk" | ||
| "Bug Tracker" = "https://github.com/launchdarkly/python-ai-sdk/issues" | ||
|
|
||
| [build-system] | ||
| requires = ["hatchling>=1.32,<2"] | ||
| build-backend = "hatchling.build" | ||
|
|
||
| [tool.hatch.build.targets.wheel] | ||
| packages = ["src/launchdarkly_ai_litellm_agents"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.