Skip to content

Commit 9c233a3

Browse files
author
jhkwapisz
committed
feat: refactored the kernel
1 parent d59b273 commit 9c233a3

31 files changed

+1811
-692
lines changed

.check_core_imports.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ check_directory: hexdag/kernel
1111

1212
# Forbidden import patterns (regex)
1313
forbidden_patterns:
14+
- '^from\s+hexdag\.api'
1415
- '^from\s+hexdag\.drivers'
1516
- '^from\s+hexdag\.stdlib'
17+
- '^from\s+hexdag\.cli'
18+
- '^import\s+hexdag\.api'
1619
- '^import\s+hexdag\.drivers'
1720
- '^import\s+hexdag\.stdlib'
21+
- '^import\s+hexdag\.cli'
1822
# Legacy paths (catch any leftovers from pre-rename)
1923
- '^from\s+hexdag\.adapters'
2024
- '^from\s+hexdag\.builtin'
@@ -46,12 +50,6 @@ allowed_exceptions:
4650
hexdag/kernel/orchestration/components/execution_coordinator.py:
4751
- "from hexdag.stdlib.nodes.mapped_input import FieldExtractor"
4852

49-
# Prompt __init__ re-exports advanced prompts for backward compatibility
50-
# These were moved to stdlib but are still part of kernel API surface.
51-
# Rationale: Maintains public API while allowing modular organization.
52-
hexdag/kernel/orchestration/prompt/__init__.py:
53-
- "from hexdag.stdlib.prompts.base import ("
54-
5553
# Models.py has doctest examples that import adapters for demonstration
5654
# These are documentation/test imports, not runtime dependencies.
5755
# Rationale: Doctests need concrete examples to be runnable.
@@ -60,6 +58,12 @@ allowed_exceptions:
6058
- "from hexdag.stdlib.adapters.openai import OpenAIAdapter"
6159
- "from hexdag.stdlib.adapters.anthropic import AnthropicAdapter"
6260

61+
# lib_base.py is a backward-compat re-export shim.
62+
# The canonical location is hexdag.stdlib.lib_base.
63+
# Rationale: Maintains import compatibility while lib contract lives in stdlib.
64+
hexdag/kernel/lib_base.py:
65+
- "from hexdag.stdlib.lib_base import HexDAGLib, get_lib_tool_schemas # noqa: F401"
66+
6367
# Resolver imports stdlib.nodes to trigger auto-discovery and alias registration
6468
# Also imports adapter/macro discovery for the unified alias system.
6569
# These are lazy imports inside _ensure_builtin_bootstrapped(), not module-level dependencies.

docs/generated/mcp/node_guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ Multi-step reasoning agent.
180180
| Parameter | Type | Required | Description |
181181
|-----------|------|----------|-------------|
182182
| `name` | `str` | Yes | Agent name |
183-
| `main_prompt` | `str | hexdag.kernel.orchestration.prompt.template.PromptTemplate | hexdag.stdlib.prompts.base.ChatPromptTemplate | hexdag.stdlib.prompts.base.ChatFewShotTemplate | hexdag.stdlib.prompts.base.FewShotPromptTemplate` | Yes | Initial reasoning prompt |
184-
| `continuation_prompts` | `dict[str, str | hexdag.kernel.orchestration.prompt.template.PromptTemplate | hexdag.stdlib.prompts.base.ChatPromptTemplate | hexdag.stdlib.prompts.base.ChatFewShotTemplate | hexdag.stdlib.prompts.base.FewShotPromptTemplate] | None` | No | Phase-specific prompts |
183+
| `main_prompt` | `str | hexdag.kernel.orchestration.prompt.template.PromptTemplate | hexdag.kernel.orchestration.prompt.template.ChatPromptTemplate | hexdag.kernel.orchestration.prompt.template.ChatFewShotTemplate | hexdag.kernel.orchestration.prompt.template.FewShotPromptTemplate` | Yes | Initial reasoning prompt |
184+
| `continuation_prompts` | `dict[str, str | hexdag.kernel.orchestration.prompt.template.PromptTemplate | hexdag.kernel.orchestration.prompt.template.ChatPromptTemplate | hexdag.kernel.orchestration.prompt.template.ChatFewShotTemplate | hexdag.kernel.orchestration.prompt.template.FewShotPromptTemplate] | None` | No | Phase-specific prompts |
185185
| `output_schema` | `dict[str, type] | type[pydantic.main.BaseModel] | None` | No | Custom output schema for tool_end results |
186186
| `config` | `hexdag.stdlib.nodes.agent_node.AgentConfig | None` | No | Agent configuration |
187187
| `deps` | `list[str] | None` | No | Dependencies |

hexdag/api/components.py

Lines changed: 1 addition & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from typing import Any
1616

1717
from hexdag.kernel.pipeline_builder.tag_discovery import discover_tags, get_tag_schema
18+
from hexdag.kernel.ports.detection import detect_port_type as detect_port_type
1819
from hexdag.kernel.resolver import get_builtin_aliases, resolve
1920
from hexdag.kernel.schema import SchemaGenerator
2021

@@ -266,89 +267,6 @@ def list_adapters(port_type: str | None = None) -> list[dict[str, Any]]:
266267
return sorted(unique_adapters, key=lambda x: (x["port_type"], x["name"]))
267268

268269

269-
def detect_port_type(adapter_class: type) -> str:
270-
"""Detect port type from adapter class using protocol inspection.
271-
272-
Adapters MUST inherit from their port protocol to be properly detected.
273-
This is a convention enforced by hexDAG - no name-based guessing.
274-
275-
Port Protocol Convention
276-
------------------------
277-
All adapters must inherit from their corresponding port protocol:
278-
279-
- LLM adapters: inherit from `LLM`, `SupportsGeneration`, `SupportsFunctionCalling`, etc.
280-
- Memory adapters: inherit from `Memory`
281-
- Database adapters: inherit from `Database` or `SQLAdapter`
282-
- Secret adapters: inherit from `SecretStore`
283-
- Storage adapters: inherit from `FileStorage` or `VectorStorePort`
284-
- Tool adapters: inherit from `ToolRouter`
285-
286-
Example::
287-
288-
from hexdag.kernel.ports.llm import LLM
289-
290-
class MyCustomLLMAdapter(LLM):
291-
async def aresponse(self, messages):
292-
...
293-
294-
Parameters
295-
----------
296-
adapter_class : type
297-
The adapter class to inspect
298-
299-
Returns
300-
-------
301-
str
302-
Port type: "llm", "memory", "database", "secret", "storage", "tool_router", or "unknown"
303-
304-
Examples
305-
--------
306-
>>> from hexdag.stdlib.adapters.openai import OpenAIAdapter
307-
>>> detect_port_type(OpenAIAdapter)
308-
'llm'
309-
"""
310-
# Check explicit decorator metadata first (future @adapter decorator)
311-
explicit_port = getattr(adapter_class, "_hexdag_implements_port", None)
312-
if explicit_port:
313-
return str(explicit_port)
314-
315-
# Check protocol inheritance (required convention)
316-
mro_names = [c.__name__ for c in adapter_class.__mro__]
317-
318-
# LLM adapters implement LLM, SupportsGeneration, SupportsFunctionCalling, etc.
319-
llm_protocols = {"LLM", "SupportsGeneration", "SupportsFunctionCalling", "SupportsVision"}
320-
if any(name in mro_names for name in llm_protocols):
321-
return "llm"
322-
323-
# Memory adapters implement Memory protocol
324-
if "Memory" in mro_names:
325-
return "memory"
326-
327-
# Database adapters implement Database or SQLAdapter
328-
if "Database" in mro_names or "DatabasePort" in mro_names or "SQLAdapter" in mro_names:
329-
return "database"
330-
331-
# Secret adapters implement SecretStore
332-
if "SecretStore" in mro_names or "SecretPort" in mro_names:
333-
return "secret"
334-
335-
# Storage adapters implement FileStorage or VectorStorePort
336-
storage_ports = ("FileStorage", "FileStoragePort", "VectorStorePort")
337-
if any(name in mro_names for name in storage_ports):
338-
return "storage"
339-
340-
# DataStore adapters implement DataStore
341-
if "DataStore" in mro_names:
342-
return "data_store"
343-
344-
# Tool router adapters implement ToolRouter
345-
if "ToolRouter" in mro_names:
346-
return "tool_router"
347-
348-
# No fallback - adapters must follow the convention
349-
return "unknown"
350-
351-
352270
def _discover_entities(
353271
discover_fn: Any,
354272
builtin_modules: list[str],
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""HTTP client driver for the APICall port."""
2+
3+
from hexdag.drivers.http_client.http_client import HttpClientDriver
4+
5+
__all__ = ["HttpClientDriver"]

0 commit comments

Comments
 (0)