-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
122 lines (105 loc) · 3.63 KB
/
Copy path__init__.py
File metadata and controls
122 lines (105 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""Agent Assembly Python SDK."""
from __future__ import annotations
import contextlib
import importlib
import importlib.util
import sys
from typing import TYPE_CHECKING, Any
__version__ = "0.0.1a2"
# AAASM-1696: top-level exports are resolved lazily so that lightweight
# submodules (e.g. `agent_assembly.runtime`, which is stdlib-only) can be
# imported without dragging in the SDK's third-party dependency surface
# (`httpx`, `pydantic`, …). See PEP 562.
_LAZY_EXPORTS: dict[str, str] = {
"init_assembly": "agent_assembly.core",
"AssemblyContext": "agent_assembly.core",
"GovernanceInterceptor": "agent_assembly.adapters",
"FrameworkAdapter": "agent_assembly.adapters",
"AssemblyError": "agent_assembly.exceptions",
"AgentError": "agent_assembly.exceptions",
"PolicyError": "agent_assembly.exceptions",
"GatewayError": "agent_assembly.exceptions",
"ConfigurationError": "agent_assembly.exceptions",
"AdapterValidationError": "agent_assembly.exceptions",
"ToolExecutionBlockedError": "agent_assembly.exceptions",
"MCPToolBlockedError": "agent_assembly.exceptions",
"AuditEvent": "agent_assembly.types",
"CallStackNode": "agent_assembly.types",
"CallStackNodeKind": "agent_assembly.types",
"GovernanceEvent": "agent_assembly._core",
"PolicyResult": "agent_assembly._core",
"PolicyTimeoutError": "agent_assembly._core",
"RuntimeClient": "agent_assembly._core",
}
_ALWAYS_EXPORTED: list[str] = [
"__version__",
"init_assembly",
"AssemblyContext",
"GovernanceInterceptor",
"FrameworkAdapter",
"AssemblyError",
"AgentError",
"PolicyError",
"GatewayError",
"ConfigurationError",
"AdapterValidationError",
"ToolExecutionBlockedError",
"MCPToolBlockedError",
"AuditEvent",
"CallStackNode",
"CallStackNodeKind",
]
_OPTIONAL_CORE: list[str] = [
"RuntimeClient",
"GovernanceEvent",
"PolicyResult",
"PolicyTimeoutError",
]
def _core_available() -> bool:
if "agent_assembly._core" in sys.modules:
return True
try:
return importlib.util.find_spec("agent_assembly._core") is not None
except (ModuleNotFoundError, ValueError):
return False
__all__: list[str] = list(_ALWAYS_EXPORTED)
if _core_available():
__all__.extend(_OPTIONAL_CORE)
def __getattr__(name: str) -> Any:
module_name = _LAZY_EXPORTS.get(name)
if module_name is None:
raise AttributeError(f"module 'agent_assembly' has no attribute {name!r}")
try:
module = importlib.import_module(module_name)
except ImportError:
if module_name == "agent_assembly._core":
raise AttributeError(
f"module 'agent_assembly' has no attribute {name!r}: the native '_core' extension is not built"
) from None
raise
value = getattr(module, name)
globals()[name] = value
return value
def __dir__() -> list[str]:
return sorted(set(__all__) | set(globals()))
if TYPE_CHECKING:
from agent_assembly.adapters import FrameworkAdapter, GovernanceInterceptor
from agent_assembly.core import AssemblyContext, init_assembly
from agent_assembly.exceptions import (
AdapterValidationError,
AgentError,
AssemblyError,
ConfigurationError,
GatewayError,
MCPToolBlockedError,
PolicyError,
ToolExecutionBlockedError,
)
from agent_assembly.types import AuditEvent, CallStackNode, CallStackNodeKind
with contextlib.suppress(ImportError):
from agent_assembly._core import (
GovernanceEvent,
PolicyResult,
PolicyTimeoutError,
RuntimeClient,
)