openenv/coding_env
21
1# Copyright (c) Meta Platforms, Inc. and affiliates.2# All rights reserved.3#4# This source code is licensed under the BSD-style license found in the5# LICENSE file in the root directory of this source tree.6 7"""Core components for agentic environments."""8 9from __future__ import annotations10 11from importlib import import_module12from typing import TYPE_CHECKING13 14from . import env_server15from .env_server import * # noqa: F40316 17if TYPE_CHECKING:18 from .env_client import EnvClient19 from .generic_client import GenericAction, GenericEnvClient20 from .llm_client import (21 AnthropicClient,22 create_llm_client,23 LLMClient,24 LLMResponse,25 OpenAIClient,26 ToolCall,27 )28 from .mcp_client import MCPClientBase, MCPToolClient29 from .sync_client import SyncEnvClient30 31__all__ = [32 "EnvClient",33 "SyncEnvClient",34 "GenericEnvClient",35 "GenericAction",36 "MCPClientBase",37 "MCPToolClient",38 "AnthropicClient",39 "LLMClient",40 "LLMResponse",41 "OpenAIClient",42 "ToolCall",43 "create_llm_client",44] + env_server.__all__ # type: ignore45 46 47_LAZY_ATTRS = {48 "EnvClient": (".env_client", "EnvClient"),49 "SyncEnvClient": (".sync_client", "SyncEnvClient"),50 "GenericEnvClient": (".generic_client", "GenericEnvClient"),51 "GenericAction": (".generic_client", "GenericAction"),52 "MCPClientBase": (".mcp_client", "MCPClientBase"),53 "MCPToolClient": (".mcp_client", "MCPToolClient"),54 "AnthropicClient": (".llm_client", "AnthropicClient"),55 "LLMClient": (".llm_client", "LLMClient"),56 "LLMResponse": (".llm_client", "LLMResponse"),57 "OpenAIClient": (".llm_client", "OpenAIClient"),58 "ToolCall": (".llm_client", "ToolCall"),59 "create_llm_client": (".llm_client", "create_llm_client"),60}61 62 63def __getattr__(name: str):64 if name in _LAZY_ATTRS:65 module_path, attr_name = _LAZY_ATTRS[name]66 module = import_module(module_path, __name__)67 value = getattr(module, attr_name)68 globals()[name] = value69 return value70 71 try:72 value = getattr(env_server, name)73 except AttributeError as exc:74 raise AttributeError(f"module {__name__!r} has no attribute {name!r}") from exc75 76 globals()[name] = value77 return value78 79 80def __dir__() -> list[str]:81 return sorted(set(globals().keys()) | set(__all__))82 