base-pmad-te 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- base_pmad_te-0.1.0/PKG-INFO +9 -0
- base_pmad_te-0.1.0/pyproject.toml +18 -0
- base_pmad_te-0.1.0/setup.cfg +4 -0
- base_pmad_te-0.1.0/src/base_pmad_te/__init__.py +1 -0
- base_pmad_te-0.1.0/src/base_pmad_te/_ctx.py +103 -0
- base_pmad_te-0.1.0/src/base_pmad_te/_kernel_ctx.py +106 -0
- base_pmad_te-0.1.0/src/base_pmad_te/imperator_flow.py +547 -0
- base_pmad_te-0.1.0/src/base_pmad_te/register.py +31 -0
- base_pmad_te-0.1.0/src/base_pmad_te/tools/__init__.py +6 -0
- base_pmad_te-0.1.0/src/base_pmad_te/tools/admin.py +374 -0
- base_pmad_te-0.1.0/src/base_pmad_te/tools/alerting.py +225 -0
- base_pmad_te-0.1.0/src/base_pmad_te/tools/diagnostic.py +200 -0
- base_pmad_te-0.1.0/src/base_pmad_te/tools/filesystem.py +270 -0
- base_pmad_te-0.1.0/src/base_pmad_te/tools/notify.py +136 -0
- base_pmad_te-0.1.0/src/base_pmad_te/tools/operational.py +237 -0
- base_pmad_te-0.1.0/src/base_pmad_te/tools/system.py +122 -0
- base_pmad_te-0.1.0/src/base_pmad_te/tools/web.py +125 -0
- base_pmad_te-0.1.0/src/base_pmad_te.egg-info/PKG-INFO +9 -0
- base_pmad_te-0.1.0/src/base_pmad_te.egg-info/SOURCES.txt +20 -0
- base_pmad_te-0.1.0/src/base_pmad_te.egg-info/dependency_links.txt +1 -0
- base_pmad_te-0.1.0/src/base_pmad_te.egg-info/requires.txt +4 -0
- base_pmad_te-0.1.0/src/base_pmad_te.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: base-pmad-te
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Base Thought Engine for pMADs — full Imperator with admin tools and TEContext coupling
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Requires-Dist: langgraph>=0.2.60
|
|
7
|
+
Requires-Dist: langchain-core>=0.3.28
|
|
8
|
+
Requires-Dist: langchain-openai>=0.2.14
|
|
9
|
+
Requires-Dist: httpx>=0.28.1
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "base-pmad-te"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Base Thought Engine for pMADs — full Imperator with admin tools and TEContext coupling"
|
|
9
|
+
requires-python = ">=3.12"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"langgraph>=0.2.60",
|
|
12
|
+
"langchain-core>=0.3.28",
|
|
13
|
+
"langchain-openai>=0.2.14",
|
|
14
|
+
"httpx>=0.28.1",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[tool.setuptools.packages.find]
|
|
18
|
+
where = ["src"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Context Broker TE — Imperator cognitive agent package."""
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""
|
|
2
|
+
TE/AE decoupling — TEContext protocol and singleton.
|
|
3
|
+
|
|
4
|
+
Defines the interface the TE needs from the AE kernel, without importing
|
|
5
|
+
any ``app.*`` modules. The AE bootstrap creates a concrete implementation
|
|
6
|
+
and calls ``initialize(ctx)`` before the Imperator flow is compiled.
|
|
7
|
+
|
|
8
|
+
This is the ONLY module TE files import for kernel services.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from typing import Any, Awaitable, Callable, Optional, Protocol, runtime_checkable
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@runtime_checkable
|
|
17
|
+
class TEContext(Protocol):
|
|
18
|
+
"""Surface the TE needs from the AE kernel."""
|
|
19
|
+
|
|
20
|
+
# ── Properties / fields ──────────────────────────────────────────────
|
|
21
|
+
config_path: str
|
|
22
|
+
te_config_path: str
|
|
23
|
+
effective_utilization_default: float
|
|
24
|
+
|
|
25
|
+
# ── Sync helpers ─────────────────────────────────────────────────────
|
|
26
|
+
def get_pool(self) -> Any:
|
|
27
|
+
"""Return the asyncpg connection pool."""
|
|
28
|
+
...
|
|
29
|
+
|
|
30
|
+
def load_config(self) -> dict:
|
|
31
|
+
"""Return the current AE config (sync, cached/memoized read)."""
|
|
32
|
+
...
|
|
33
|
+
|
|
34
|
+
def load_merged_config(self) -> dict:
|
|
35
|
+
"""Return config.yml merged with te.yml overrides."""
|
|
36
|
+
...
|
|
37
|
+
|
|
38
|
+
def get_chat_model(self, config: dict, role: str = "imperator") -> Any:
|
|
39
|
+
"""Return a LangChain chat model for *role*."""
|
|
40
|
+
...
|
|
41
|
+
|
|
42
|
+
def get_embeddings_model(self, config: dict, config_key: str = "embeddings") -> Any:
|
|
43
|
+
"""Return a LangChain embeddings model."""
|
|
44
|
+
...
|
|
45
|
+
|
|
46
|
+
def get_tuning(self, config: dict, key: str, default: Any = None) -> Any:
|
|
47
|
+
"""Read a tuning parameter from *config*."""
|
|
48
|
+
...
|
|
49
|
+
|
|
50
|
+
def get_api_key(self, provider_config: dict) -> str:
|
|
51
|
+
"""Resolve an API key from provider config + env vars."""
|
|
52
|
+
...
|
|
53
|
+
|
|
54
|
+
# ── Async helpers ────────────────────────────────────────────────────
|
|
55
|
+
def async_load_config(self) -> Awaitable[dict]:
|
|
56
|
+
"""Return the current AE config (async variant)."""
|
|
57
|
+
...
|
|
58
|
+
|
|
59
|
+
def async_load_prompt(self, name: str) -> Awaitable[str]:
|
|
60
|
+
"""Load a prompt template by *name*."""
|
|
61
|
+
...
|
|
62
|
+
|
|
63
|
+
def dispatch_tool(
|
|
64
|
+
self,
|
|
65
|
+
tool_name: str,
|
|
66
|
+
args: dict,
|
|
67
|
+
config: dict,
|
|
68
|
+
state: Any,
|
|
69
|
+
) -> Awaitable[dict]:
|
|
70
|
+
"""Dispatch an AE core tool by name."""
|
|
71
|
+
...
|
|
72
|
+
|
|
73
|
+
# ── Flow builders ────────────────────────────────────────────────────
|
|
74
|
+
def get_flow_builder(self, name: str) -> Optional[Callable]:
|
|
75
|
+
"""Return a registered AE flow builder by *name*, or ``None``."""
|
|
76
|
+
...
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# ── Module-level singleton ───────────────────────────────────────────────
|
|
80
|
+
|
|
81
|
+
_ctx: Optional[TEContext] = None
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def initialize(ctx: TEContext) -> None:
|
|
85
|
+
"""Set the module-level TEContext singleton.
|
|
86
|
+
|
|
87
|
+
Called once by the AE bootstrap before the Imperator flow is compiled.
|
|
88
|
+
"""
|
|
89
|
+
global _ctx
|
|
90
|
+
_ctx = ctx
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def get_ctx() -> TEContext:
|
|
94
|
+
"""Return the TEContext singleton.
|
|
95
|
+
|
|
96
|
+
Raises ``RuntimeError`` if ``initialize()`` has not been called yet.
|
|
97
|
+
"""
|
|
98
|
+
if _ctx is None:
|
|
99
|
+
raise RuntimeError(
|
|
100
|
+
"TEContext not initialized — call base_pmad_te._ctx.initialize() "
|
|
101
|
+
"before using TE components."
|
|
102
|
+
)
|
|
103
|
+
return _ctx
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""
|
|
2
|
+
KernelTEContext — concrete TEContext backed by ``app.*`` modules.
|
|
3
|
+
|
|
4
|
+
This is the ONLY file in the TE package that imports from ``app.*``.
|
|
5
|
+
It is the adapter boundary between the TE and the AE kernel.
|
|
6
|
+
|
|
7
|
+
NOTE: This file lives in the TE package for now but conceptually belongs
|
|
8
|
+
to the AE/kernel. It will be moved when the template is created.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from dataclasses import dataclass, field
|
|
14
|
+
from typing import Any, Callable, Optional
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class KernelTEContext:
|
|
19
|
+
"""Delegate every TEContext method to the corresponding ``app.*`` call."""
|
|
20
|
+
|
|
21
|
+
# ── Properties ───────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def config_path(self) -> str:
|
|
25
|
+
from app.config import CONFIG_PATH
|
|
26
|
+
|
|
27
|
+
return CONFIG_PATH
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def te_config_path(self) -> str:
|
|
31
|
+
from app.config import TE_CONFIG_PATH
|
|
32
|
+
|
|
33
|
+
return TE_CONFIG_PATH
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def effective_utilization_default(self) -> float:
|
|
37
|
+
from app.budget import EFFECTIVE_UTILIZATION_DEFAULT
|
|
38
|
+
|
|
39
|
+
return EFFECTIVE_UTILIZATION_DEFAULT
|
|
40
|
+
|
|
41
|
+
# ── Sync helpers ─────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
def get_pool(self) -> Any:
|
|
44
|
+
from app.database import get_pg_pool
|
|
45
|
+
|
|
46
|
+
return get_pg_pool()
|
|
47
|
+
|
|
48
|
+
def load_config(self) -> dict:
|
|
49
|
+
from app.config import load_config
|
|
50
|
+
|
|
51
|
+
return load_config()
|
|
52
|
+
|
|
53
|
+
def load_merged_config(self) -> dict:
|
|
54
|
+
from app.config import load_merged_config
|
|
55
|
+
|
|
56
|
+
return load_merged_config()
|
|
57
|
+
|
|
58
|
+
def get_chat_model(self, config: dict, role: str = "imperator") -> Any:
|
|
59
|
+
from app.config import get_chat_model
|
|
60
|
+
|
|
61
|
+
return get_chat_model(config, role=role)
|
|
62
|
+
|
|
63
|
+
def get_embeddings_model(self, config: dict, config_key: str = "embeddings") -> Any:
|
|
64
|
+
from app.config import get_embeddings_model
|
|
65
|
+
|
|
66
|
+
return get_embeddings_model(config, config_key=config_key)
|
|
67
|
+
|
|
68
|
+
def get_tuning(self, config: dict, key: str, default: Any = None) -> Any:
|
|
69
|
+
from app.config import get_tuning
|
|
70
|
+
|
|
71
|
+
return get_tuning(config, key, default)
|
|
72
|
+
|
|
73
|
+
def get_api_key(self, provider_config: dict) -> str:
|
|
74
|
+
from app.config import get_api_key
|
|
75
|
+
|
|
76
|
+
return get_api_key(provider_config)
|
|
77
|
+
|
|
78
|
+
# ── Async helpers ────────────────────────────────────────────────────
|
|
79
|
+
|
|
80
|
+
async def async_load_config(self) -> dict:
|
|
81
|
+
from app.config import async_load_config
|
|
82
|
+
|
|
83
|
+
return await async_load_config()
|
|
84
|
+
|
|
85
|
+
async def async_load_prompt(self, name: str) -> str:
|
|
86
|
+
from app.prompt_loader import async_load_prompt
|
|
87
|
+
|
|
88
|
+
return await async_load_prompt(name)
|
|
89
|
+
|
|
90
|
+
async def dispatch_tool(
|
|
91
|
+
self,
|
|
92
|
+
tool_name: str,
|
|
93
|
+
args: dict,
|
|
94
|
+
config: dict,
|
|
95
|
+
state: Any,
|
|
96
|
+
) -> dict:
|
|
97
|
+
from app.flows.tool_dispatch import dispatch_tool
|
|
98
|
+
|
|
99
|
+
return await dispatch_tool(tool_name, args, config, state)
|
|
100
|
+
|
|
101
|
+
# ── Flow builders ────────────────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
def get_flow_builder(self, name: str) -> Optional[Callable]:
|
|
104
|
+
from app.stategraph_registry import get_flow_builder
|
|
105
|
+
|
|
106
|
+
return get_flow_builder(name)
|