A programming framework for agentic AI
Replace create_completion_client_from_env with component config (#4928)
Jack Gerrits538f39497b5e
diff --git a/python/packages/agbench/benchmarks/AssistantBench/Templates/MagenticOne/scenario.py b/python/packages/agbench/benchmarks/AssistantBench/Templates/MagenticOne/scenario.pyindex 9a6ecc9b6..dda79bd8d 100644--- a/python/packages/agbench/benchmarks/AssistantBench/Templates/MagenticOne/scenario.py+++ b/python/packages/agbench/benchmarks/AssistantBench/Templates/MagenticOne/scenario.py@@ -1,4 +1,5 @@import asyncio+import jsonimport loggingimport osimport re@@ -10,7 +11,7 @@ from typing import Listfrom autogen_core import AgentId, AgentProxy, TopicIdfrom autogen_core import SingleThreadedAgentRuntime-from autogen_core.logging import EVENT_LOGGER_NAME+from autogen_core import EVENT_LOGGER_NAMEfrom autogen_core.models import (ChatCompletionClient,UserMessage,@@ -26,7 +27,7 @@ from autogen_magentic_one.agents.orchestrator import LedgerOrchestratorfrom autogen_magentic_one.messages import BroadcastMessagefrom autogen_magentic_one.agents.multimodal_web_surfer import MultimodalWebSurferfrom autogen_magentic_one.agents.file_surfer import FileSurfer-from autogen_magentic_one.utils import LogHandler, message_content_to_str, create_completion_client_from_env+from autogen_magentic_one.utils import LogHandler, message_content_to_strencoding = Nonedef count_token(value: str) -> int:@@ -123,10 +124,8 @@ async def main() -> None:runtime = SingleThreadedAgentRuntime()# Create the AzureOpenAI client from the environment file- client = create_completion_client_from_env()--- mlm_client = create_completion_client_from_env()+ client = ChatCompletionClient.load_component(json.loads(os.environ["CHAT_COMPLETION_CLIENT_CONFIG"]))+ mlm_client = ChatCompletionClient.load_component(json.loads(os.environ["MLM_CHAT_COMPLETION_CLIENT_CONFIG"]))# Register agents.diff --git a/python/packages/agbench/benchmarks/GAIA/Templates/MagenticOne/scenario.py b/python/packages/agbench/benchmarks/GAIA/Templates/MagenticOne/scenario.pyindex 5e5b677e4..32e0a11d3 100644--- a/python/packages/agbench/benchmarks/GAIA/Templates/MagenticOne/scenario.py+++ b/python/packages/agbench/benchmarks/GAIA/Templates/MagenticOne/scenario.py@@ -1,4 +1,5 @@import asyncio+import jsonimport loggingimport osimport re@@ -27,7 +28,7 @@ from autogen_magentic_one.agents.orchestrator import LedgerOrchestratorfrom autogen_magentic_one.messages import BroadcastMessagefrom autogen_magentic_one.agents.multimodal_web_surfer import MultimodalWebSurferfrom autogen_magentic_one.agents.file_surfer import FileSurfer-from autogen_magentic_one.utils import LogHandler, message_content_to_str, create_completion_client_from_env+from autogen_magentic_one.utils import LogHandler, message_content_to_strencoding = Nonedef count_token(value: str) -> int:@@ -124,11 +125,10 @@ async def main() -> None:runtime = SingleThreadedAgentRuntime()# Create the AzureOpenAI client, with AAD auth, from environment- client = create_completion_client_from_env()+ client = ChatCompletionClient.load_component(json.loads(os.environ["CHAT_COMPLETION_CLIENT_CONFIG"]))+ mlm_client = ChatCompletionClient.load_component(json.loads(os.environ["MLM_CHAT_COMPLETION_CLIENT_CONFIG"]))- mlm_client = create_completion_client_from_env()-# Register agents.await runtime.register("Assistant",diff --git a/python/packages/agbench/benchmarks/HumanEval/Templates/MagenticOne/scenario.py b/python/packages/agbench/benchmarks/HumanEval/Templates/MagenticOne/scenario.pyindex c57971ea6..7059ac82c 100644--- a/python/packages/agbench/benchmarks/HumanEval/Templates/MagenticOne/scenario.py+++ b/python/packages/agbench/benchmarks/HumanEval/Templates/MagenticOne/scenario.py@@ -13,7 +13,6 @@ from autogen_core.models import (from autogen_magentic_one.agents.coder import Coder, Executorfrom autogen_magentic_one.agents.orchestrator import RoundRobinOrchestratorfrom autogen_magentic_one.messages import BroadcastMessage, OrchestrationEvent-from autogen_magentic_one.utils import create_completion_client_from_envasync def main() -> None:@@ -21,7 +20,8 @@ async def main() -> None:runtime = SingleThreadedAgentRuntime()# Create the AzureOpenAI client- client = create_completion_client_from_env()+ client = ChatCompletionClient.load_component(json.loads(os.environ["CHAT_COMPLETION_CLIENT_CONFIG"]))+# Register agents.await runtime.register(diff --git a/python/packages/agbench/benchmarks/WebArena/Templates/MagenticOne/scenario.py b/python/packages/agbench/benchmarks/WebArena/Templates/MagenticOne/scenario.pyindex ab387ce59..08f158ac9 100644--- a/python/packages/agbench/benchmarks/WebArena/Templates/MagenticOne/scenario.py+++ b/python/packages/agbench/benchmarks/WebArena/Templates/MagenticOne/scenario.py@@ -24,7 +24,7 @@ from autogen_magentic_one.agents.orchestrator import RoundRobinOrchestrator, Ledfrom autogen_magentic_one.messages import BroadcastMessage, OrchestrationEvent, RequestReplyMessage, ResetMessage, DeactivateMessagefrom autogen_magentic_one.agents.multimodal_web_surfer import MultimodalWebSurferfrom autogen_magentic_one.agents.file_surfer import FileSurfer-from autogen_magentic_one.utils import LogHandler, message_content_to_str, create_completion_client_from_env+from autogen_magentic_one.utils import LogHandler, message_content_to_strimport evaluation_harness@@ -120,7 +120,8 @@ async def main() -> None:runtime = SingleThreadedAgentRuntime()# Create the AzureOpenAI client, with AAD auth- client = create_completion_client_from_env()+ client = ChatCompletionClient.load_component(json.loads(os.environ["CHAT_COMPLETION_CLIENT_CONFIG"]))+# Login assistantawait runtime.register("LoginAssistant",diff --git a/python/packages/autogen-magentic-one/README.md b/python/packages/autogen-magentic-one/README.mdindex 8d81ad7ce..a0573df8c 100644--- a/python/packages/autogen-magentic-one/README.md+++ b/python/packages/autogen-magentic-one/README.md@@ -119,28 +119,39 @@ playwright install --with-deps chromium## Environment Configuration for Chat Completion Client-This guide outlines how to configure your environment to use the `create_completion_client_from_env` function, which reads environment variables to return an appropriate `ChatCompletionClient`.+This guide outlines how to structure the config to load a ChatCompletionClient for Magentic-One.++```python+from autogen_core.models import ChatCompletionClient++config = {}+client = ChatCompletionClient.load_component(config)+```Currently, Magentic-One only supports OpenAI's GPT-4o as the underlying LLM.### Azure OpenAI service-To configure for Azure OpenAI service, set the following environment variables:--- `CHAT_COMPLETION_PROVIDER='azure'`-- `CHAT_COMPLETION_KWARGS_JSON` with the following JSON structure:+To configure for Azure OpenAI service, use the following config:```json{- "api_version": "2024-02-15-preview",- "azure_endpoint": "REPLACE_WITH_YOUR_ENDPOINT",- "model_capabilities": {- "function_calling": true,- "json_output": true,- "vision": true- },- "azure_ad_token_provider": "DEFAULT",- "model": "gpt-4o-2024-05-13"+ "provider": "AzureOpenAIChatCompletionClient",+ "config": {+ "model": "gpt-4o-2024-05-13",+ "azure_endpoint": "https://{your-custom-endpoint}.openai.azure.com/",+ "azure_deployment": "{your-azure-deployment}",+ "api_version": "2024-06-01",+ "azure_ad_token_provider": {+ "provider": "autogen_ext.models.openai.AzureTokenProvider",+ "config": {+ "provider_kind": "DefaultAzureCredential",+ "scopes": [+ "https://cognitiveservices.azure.com/.default"+ ]+ }+ }+ }}```@@ -150,19 +161,34 @@ Log in to Azure using `az login`, and then run the examples. The account used muNote that even if you are the owner of the subscription, you still need to grant the necessary Azure Cognitive Services OpenAI permissions to call the API.-### With OpenAI+Or, to use an API key:+```json+{+ "provider": "AzureOpenAIChatCompletionClient",+ "config": {+ "model": "gpt-4o-2024-05-13",+ "azure_endpoint": "https://{your-custom-endpoint}.openai.azure.com/",+ "azure_deployment": "{your-azure-deployment}",+ "api_version": "2024-06-01",+ "api_key": "REPLACE_WITH_YOUR_API_KEY"+ }+}+```-To configure for OpenAI, set the following environment variables:+### With OpenAI-- `CHAT_COMPLETION_PROVIDER='openai'`-- `CHAT_COMPLETION_KWARGS_JSON` with the following JSON structure:+To configure for OpenAI, use the following config:```json{- "api_key": "REPLACE_WITH_YOUR_API",- "model": "gpt-4o-2024-05-13"+ "provider": "OpenAIChatCompletionClient",+ "config": {+ "model": "gpt-4o-2024-05-13",+ "api_key": "REPLACE_WITH_YOUR_API_KEY"+ }}```+Feel free to replace the model with newer versions of gpt-4o if needed.### Other Keys (Optional)diff --git a/python/packages/autogen-magentic-one/examples/example.py b/python/packages/autogen-magentic-one/examples/example.pyindex 5e975d175..048e6c060 100644--- a/python/packages/autogen-magentic-one/examples/example.py+++ b/python/packages/autogen-magentic-one/examples/example.py@@ -2,11 +2,13 @@import argparseimport asyncio+import jsonimport loggingimport osfrom autogen_core import EVENT_LOGGER_NAME, AgentId, AgentProxy, SingleThreadedAgentRuntimefrom autogen_core.code_executor import CodeBlock+from autogen_core.models._model_client import ChatCompletionClientfrom autogen_ext.code_executors.docker import DockerCommandLineCodeExecutorfrom autogen_magentic_one.agents.coder import Coder, Executorfrom autogen_magentic_one.agents.file_surfer import FileSurfer@@ -14,7 +16,7 @@ from autogen_magentic_one.agents.multimodal_web_surfer import MultimodalWebSurfefrom autogen_magentic_one.agents.orchestrator import LedgerOrchestratorfrom autogen_magentic_one.agents.user_proxy import UserProxyfrom autogen_magentic_one.messages import RequestReplyMessage-from autogen_magentic_one.utils import LogHandler, create_completion_client_from_env+from autogen_magentic_one.utils import LogHandler# NOTE: Don't forget to 'playwright install --with-deps chromium'@@ -32,7 +34,8 @@ async def main(logs_dir: str, hil_mode: bool, save_screenshots: bool) -> None:runtime = SingleThreadedAgentRuntime()# Create an appropriate client- client = create_completion_client_from_env(model="gpt-4o")+ client = ChatCompletionClient.load_component(json.loads(os.environ["CHAT_COMPLETION_CLIENT_CONFIG"]))+ assert client.model_info["family"] == "gpt-4o", "This example requires the gpt-4o model"async with DockerCommandLineCodeExecutor(work_dir=logs_dir) as code_executor:# Register agents.diff --git a/python/packages/autogen-magentic-one/examples/example_coder.py b/python/packages/autogen-magentic-one/examples/example_coder.pyindex 3815c1806..2071c78ce 100644--- a/python/packages/autogen-magentic-one/examples/example_coder.py+++ b/python/packages/autogen-magentic-one/examples/example_coder.py@@ -5,16 +5,19 @@ round-robin orchestrator agent. The code snippets are executed inside a docker c"""import asyncio+import jsonimport logging+import osfrom autogen_core import EVENT_LOGGER_NAME, AgentId, AgentProxy, SingleThreadedAgentRuntimefrom autogen_core.code_executor import CodeBlock+from autogen_core.models._model_client import ChatCompletionClientfrom autogen_ext.code_executors.docker import DockerCommandLineCodeExecutorfrom autogen_magentic_one.agents.coder import Coder, Executorfrom autogen_magentic_one.agents.orchestrator import RoundRobinOrchestratorfrom autogen_magentic_one.agents.user_proxy import UserProxyfrom autogen_magentic_one.messages import RequestReplyMessage-from autogen_magentic_one.utils import LogHandler, create_completion_client_from_env+from autogen_magentic_one.utils import LogHandlerasync def confirm_code(code: CodeBlock) -> bool:@@ -29,9 +32,10 @@ async def main() -> None:# Create the runtime.runtime = SingleThreadedAgentRuntime()+ model_client = ChatCompletionClient.load_component(json.loads(os.environ["CHAT_COMPLETION_CLIENT_CONFIG"]))async with DockerCommandLineCodeExecutor() as code_executor:# Register agents.- await Coder.register(runtime, "Coder", lambda: Coder(model_client=create_completion_client_from_env()))+ await Coder.register(runtime, "Coder", lambda: Coder(model_client=model_client))coder = AgentProxy(AgentId("Coder", "default"), runtime)await Executor.register(diff --git a/python/packages/autogen-magentic-one/examples/example_file_surfer.py b/python/packages/autogen-magentic-one/examples/example_file_surfer.pyindex 4303d039f..e718eb115 100644--- a/python/packages/autogen-magentic-one/examples/example_file_surfer.py+++ b/python/packages/autogen-magentic-one/examples/example_file_surfer.py@@ -3,14 +3,17 @@ to navigate the file system. The human user and the file surfer agent takes turnto write input or perform actions, orchestrated by an round-robin orchestrator agent."""import asyncio+import jsonimport logging+import osfrom autogen_core import EVENT_LOGGER_NAME, AgentId, AgentProxy, SingleThreadedAgentRuntime+from autogen_core.models._model_client import ChatCompletionClientfrom autogen_magentic_one.agents.file_surfer import FileSurferfrom autogen_magentic_one.agents.orchestrator import RoundRobinOrchestratorfrom autogen_magentic_one.agents.user_proxy import UserProxyfrom autogen_magentic_one.messages import RequestReplyMessage-from autogen_magentic_one.utils import LogHandler, create_completion_client_from_env+from autogen_magentic_one.utils import LogHandlerasync def main() -> None:@@ -18,7 +21,7 @@ async def main() -> None:runtime = SingleThreadedAgentRuntime()# Get an appropriate client- client = create_completion_client_from_env()+ client = ChatCompletionClient.load_component(json.loads(os.environ["CHAT_COMPLETION_CLIENT_CONFIG"]))# Register agents.await FileSurfer.register(runtime, "file_surfer", lambda: FileSurfer(model_client=client))diff --git a/python/packages/autogen-magentic-one/examples/example_userproxy.py b/python/packages/autogen-magentic-one/examples/example_userproxy.pyindex 7096630f6..32561a27c 100644--- a/python/packages/autogen-magentic-one/examples/example_userproxy.py+++ b/python/packages/autogen-magentic-one/examples/example_userproxy.py@@ -5,16 +5,19 @@ round-robin orchestrator agent.The code snippets are not executed in this example."""import asyncio+import jsonimport logging+import osfrom autogen_core import EVENT_LOGGER_NAME, AgentId, AgentProxy, SingleThreadedAgentRuntime# from typing import Any, Dict, List, Tuple, Union+from autogen_core.models._model_client import ChatCompletionClientfrom autogen_magentic_one.agents.coder import Coderfrom autogen_magentic_one.agents.orchestrator import RoundRobinOrchestratorfrom autogen_magentic_one.agents.user_proxy import UserProxyfrom autogen_magentic_one.messages import RequestReplyMessage-from autogen_magentic_one.utils import LogHandler, create_completion_client_from_env+from autogen_magentic_one.utils import LogHandlerasync def main() -> None:@@ -22,7 +25,7 @@ async def main() -> None:runtime = SingleThreadedAgentRuntime()# Get an appropriate client- client = create_completion_client_from_env()+ client = ChatCompletionClient.load_component(json.loads(os.environ["CHAT_COMPLETION_CLIENT_CONFIG"]))# Register agents.await Coder.register(runtime, "Coder", lambda: Coder(model_client=client))diff --git a/python/packages/autogen-magentic-one/examples/example_websurfer.py b/python/packages/autogen-magentic-one/examples/example_websurfer.pyindex 16b806f33..825492a62 100644--- a/python/packages/autogen-magentic-one/examples/example_websurfer.py+++ b/python/packages/autogen-magentic-one/examples/example_websurfer.py@@ -4,15 +4,17 @@ The human user and the web surfer agent takes turn to write input or perform actorchestrated by an round-robin orchestrator agent."""import asyncio+import jsonimport loggingimport osfrom autogen_core import EVENT_LOGGER_NAME, AgentId, AgentProxy, SingleThreadedAgentRuntime+from autogen_core.models import ChatCompletionClientfrom autogen_magentic_one.agents.multimodal_web_surfer import MultimodalWebSurferfrom autogen_magentic_one.agents.orchestrator import RoundRobinOrchestratorfrom autogen_magentic_one.agents.user_proxy import UserProxyfrom autogen_magentic_one.messages import RequestReplyMessage-from autogen_magentic_one.utils import LogHandler, create_completion_client_from_env+from autogen_magentic_one.utils import LogHandler# NOTE: Don't forget to 'playwright install --with-deps chromium'@@ -22,7 +24,8 @@ async def main() -> None:runtime = SingleThreadedAgentRuntime()# Create an appropriate client- client = create_completion_client_from_env(model="gpt-4o")+ client = ChatCompletionClient.load_component(json.loads(os.environ["CHAT_COMPLETION_CLIENT_CONFIG"]))+ assert client.model_info["family"] == "gpt-4o", "This example requires the gpt-4o model"# Register agents.await MultimodalWebSurfer.register(runtime, "WebSurfer", MultimodalWebSurfer)diff --git a/python/packages/autogen-magentic-one/interface/magentic_one_helper.py b/python/packages/autogen-magentic-one/interface/magentic_one_helper.pyindex 94de71406..e082853f6 100644--- a/python/packages/autogen-magentic-one/interface/magentic_one_helper.py+++ b/python/packages/autogen-magentic-one/interface/magentic_one_helper.py@@ -10,6 +10,7 @@ from autogen_core import SingleThreadedAgentRuntimefrom autogen_core import EVENT_LOGGER_NAMEfrom autogen_core import AgentId, AgentProxyfrom autogen_core import DefaultTopicId+from autogen_core.models._model_client import ChatCompletionClientfrom autogen_ext.code_executors.local import LocalCommandLineCodeExecutorfrom autogen_ext.code_executors.docker import DockerCommandLineCodeExecutorfrom autogen_core.code_executor import CodeBlock@@ -19,7 +20,7 @@ from autogen_magentic_one.agents.multimodal_web_surfer import MultimodalWebSurfefrom autogen_magentic_one.agents.orchestrator import LedgerOrchestratorfrom autogen_magentic_one.agents.user_proxy import UserProxyfrom autogen_magentic_one.messages import BroadcastMessage-from autogen_magentic_one.utils import LogHandler, create_completion_client_from_env+from autogen_magentic_one.utils import LogHandlerfrom autogen_core.models import UserMessagefrom threading import Lock@@ -60,7 +61,9 @@ class MagenticOneHelper:logger.handlers = [self.log_handler]# Create client- client = create_completion_client_from_env(model="gpt-4o")+ client = ChatCompletionClient.load_component(json.loads(os.environ["CHAT_COMPLETION_CLIENT_CONFIG"]))+ assert client.model_info["family"] == "gpt-4o", "This example requires the gpt-4o model"+# Set up code executorself.code_executor = DockerCommandLineCodeExecutor(work_dir=self.logs_dir)diff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/utils.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/utils.pyindex 0537142f0..1f9c07525 100644--- a/python/packages/autogen-magentic-one/src/autogen_magentic_one/utils.py+++ b/python/packages/autogen-magentic-one/src/autogen_magentic_one/utils.py@@ -1,17 +1,11 @@import jsonimport logging-import osfrom dataclasses import asdictfrom datetime import datetimefrom typing import Any, Dict, List, Literalfrom autogen_core import Imagefrom autogen_core.logging import LLMCallEvent-from autogen_core.models import (- ChatCompletionClient,- ModelCapabilities, # type: ignore-)-from autogen_ext.models.openai import AzureOpenAIChatCompletionClient, OpenAIChatCompletionClientfrom .messages import (AgentEvent,@@ -23,62 +17,6 @@ from .messages import (WebSurferEvent,)-ENVIRON_KEY_CHAT_COMPLETION_PROVIDER = "CHAT_COMPLETION_PROVIDER"-ENVIRON_KEY_CHAT_COMPLETION_KWARGS_JSON = "CHAT_COMPLETION_KWARGS_JSON"--# The singleton _default_azure_ad_token_provider, which will be created if needed-_default_azure_ad_token_provider = None---# Create a model client based on information provided in environment variables.-def create_completion_client_from_env(env: Dict[str, str] | None = None, **kwargs: Any) -> ChatCompletionClient:- global _default_azure_ad_token_provider-- """- Create a model client based on information provided in environment variables.- env (Optional): When provied, read from this dictionary rather than os.environ- kwargs**: ChatClient arguments to override (e.g., model)-- NOTE: If 'azure_ad_token_provider' is included, and euquals the string 'DEFAULT' then replace it with- azure.identity.get_bearer_token_provider(DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default")- """-- # If a dictionary was not provided, load it from the environment- if env is None:- env = dict()- env.update(os.environ)-- # Load the kwargs, and override with provided kwargs- _kwargs = json.loads(env.get(ENVIRON_KEY_CHAT_COMPLETION_KWARGS_JSON, "{}"))- _kwargs.update(kwargs)-- # If model capabilities were provided, deserialize them as well- if "model_capabilities" in _kwargs:- _kwargs["model_capabilities"] = ModelCapabilities( # type: ignore- vision=_kwargs["model_capabilities"].get("vision"),- function_calling=_kwargs["model_capabilities"].get("function_calling"),- json_output=_kwargs["model_capabilities"].get("json_output"),- )-- # Figure out what provider we are using. Default to OpenAI- _provider = env.get(ENVIRON_KEY_CHAT_COMPLETION_PROVIDER, "openai").lower().strip()-- # Instantiate the correct client- if _provider == "openai":- return OpenAIChatCompletionClient(**_kwargs) # type: ignore- elif _provider == "azure":- if _kwargs.get("azure_ad_token_provider", "").lower() == "default":- if _default_azure_ad_token_provider is None:- from azure.identity import DefaultAzureCredential, get_bearer_token_provider-- _default_azure_ad_token_provider = get_bearer_token_provider(- DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"- )- _kwargs["azure_ad_token_provider"] = _default_azure_ad_token_provider- return AzureOpenAIChatCompletionClient(**_kwargs) # type: ignore- else:- raise ValueError(f"Unknown OAI provider '{_provider}'")-# Convert UserContent to a stringdef message_content_to_str(diff --git a/python/packages/autogen-magentic-one/tests/headless_web_surfer/test_web_surfer.py b/python/packages/autogen-magentic-one/tests/headless_web_surfer/test_web_surfer.pyindex b9a7d4cee..140bc82f2 100644--- a/python/packages/autogen-magentic-one/tests/headless_web_surfer/test_web_surfer.py+++ b/python/packages/autogen-magentic-one/tests/headless_web_surfer/test_web_surfer.py@@ -1,6 +1,7 @@#!/usr/bin/env python3 -m pytestimport asyncio+import jsonimport osimport refrom json import dumps@@ -12,6 +13,7 @@ from autogen_core import AgentId, AgentProxy, FunctionCall, SingleThreadedAgentRfrom autogen_core.models import (UserMessage,)+from autogen_core.models._model_client import ChatCompletionClientfrom autogen_core.tools._base import ToolSchemafrom autogen_magentic_one.agents.multimodal_web_surfer import MultimodalWebSurferfrom autogen_magentic_one.agents.multimodal_web_surfer.tool_definitions import (@@ -25,11 +27,6 @@ from autogen_magentic_one.agents.multimodal_web_surfer.tool_definitions import (from autogen_magentic_one.agents.orchestrator import RoundRobinOrchestratorfrom autogen_magentic_one.agents.user_proxy import UserProxyfrom autogen_magentic_one.messages import BroadcastMessage-from autogen_magentic_one.utils import (- ENVIRON_KEY_CHAT_COMPLETION_KWARGS_JSON,- ENVIRON_KEY_CHAT_COMPLETION_PROVIDER,- create_completion_client_from_env,-)from conftest import MOCK_CHAT_COMPLETION_KWARGS, reasonfrom openai import AuthenticationError@@ -57,7 +54,7 @@ skip_all = False# Search currently does not require an API keyskip_bing = False-if os.getenv(ENVIRON_KEY_CHAT_COMPLETION_KWARGS_JSON):+if os.getenv("CHAT_COMPLETION_CLIENT_CONFIG"):skip_openai = Falseelse:skip_openai = True@@ -99,14 +96,10 @@ async def make_browser_request(browser: MultimodalWebSurfer, tool: ToolSchema, a@pytest.mark.skip(reason="Need to fix this test to use a local website instead of a public one.")@pytest.mark.asyncioasync def test_web_surfer() -> None:- env = {- ENVIRON_KEY_CHAT_COMPLETION_PROVIDER: "openai",- ENVIRON_KEY_CHAT_COMPLETION_KWARGS_JSON: MOCK_CHAT_COMPLETION_KWARGS,- }-runtime = SingleThreadedAgentRuntime()# Create an appropriate client- client = create_completion_client_from_env(env)+ config = {"provider": "OpenAIChatCompletionClient", "config": json.loads(MOCK_CHAT_COMPLETION_KWARGS)}+ client = ChatCompletionClient.load_component(config)# Register agents.@@ -183,7 +176,7 @@ async def test_web_surfer_oai() -> None:runtime = SingleThreadedAgentRuntime()# Create an appropriate client- client = create_completion_client_from_env()+ client = ChatCompletionClient.load_component(json.loads(os.environ["CHAT_COMPLETION_CLIENT_CONFIG"]))# Register agents.await MultimodalWebSurfer.register(@@ -247,14 +240,10 @@ async def test_web_surfer_oai() -> None:)@pytest.mark.asyncioasync def test_web_surfer_bing() -> None:- env = {- ENVIRON_KEY_CHAT_COMPLETION_PROVIDER: "openai",- ENVIRON_KEY_CHAT_COMPLETION_KWARGS_JSON: MOCK_CHAT_COMPLETION_KWARGS,- }-runtime = SingleThreadedAgentRuntime()# Create an appropriate client- client = create_completion_client_from_env(env)+ config = {"provider": "OpenAIChatCompletionClient", "config": json.loads(MOCK_CHAT_COMPLETION_KWARGS)}+ client = ChatCompletionClient.load_component(config)# Register agents.await MultimodalWebSurfer.register(