rakam-systems-core 0.1.1rc7__py3-none-any.whl

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.
Files changed (34) hide show
  1. rakam_systems_core/__init__.py +41 -0
  2. rakam_systems_core/ai_core/__init__.py +68 -0
  3. rakam_systems_core/ai_core/base.py +142 -0
  4. rakam_systems_core/ai_core/config.py +12 -0
  5. rakam_systems_core/ai_core/config_loader.py +580 -0
  6. rakam_systems_core/ai_core/config_schema.py +395 -0
  7. rakam_systems_core/ai_core/interfaces/__init__.py +30 -0
  8. rakam_systems_core/ai_core/interfaces/agent.py +83 -0
  9. rakam_systems_core/ai_core/interfaces/chat_history.py +122 -0
  10. rakam_systems_core/ai_core/interfaces/chunker.py +11 -0
  11. rakam_systems_core/ai_core/interfaces/embedding_model.py +10 -0
  12. rakam_systems_core/ai_core/interfaces/indexer.py +10 -0
  13. rakam_systems_core/ai_core/interfaces/llm_gateway.py +139 -0
  14. rakam_systems_core/ai_core/interfaces/loader.py +86 -0
  15. rakam_systems_core/ai_core/interfaces/reranker.py +10 -0
  16. rakam_systems_core/ai_core/interfaces/retriever.py +11 -0
  17. rakam_systems_core/ai_core/interfaces/tool.py +162 -0
  18. rakam_systems_core/ai_core/interfaces/tool_invoker.py +260 -0
  19. rakam_systems_core/ai_core/interfaces/tool_loader.py +374 -0
  20. rakam_systems_core/ai_core/interfaces/tool_registry.py +287 -0
  21. rakam_systems_core/ai_core/interfaces/vectorstore.py +37 -0
  22. rakam_systems_core/ai_core/mcp/README.md +545 -0
  23. rakam_systems_core/ai_core/mcp/__init__.py +0 -0
  24. rakam_systems_core/ai_core/mcp/mcp_server.py +334 -0
  25. rakam_systems_core/ai_core/tracking.py +602 -0
  26. rakam_systems_core/ai_core/vs_core.py +55 -0
  27. rakam_systems_core/ai_utils/__init__.py +16 -0
  28. rakam_systems_core/ai_utils/logging.py +126 -0
  29. rakam_systems_core/ai_utils/metrics.py +10 -0
  30. rakam_systems_core/ai_utils/s3.py +480 -0
  31. rakam_systems_core/ai_utils/tracing.py +5 -0
  32. rakam_systems_core-0.1.1rc7.dist-info/METADATA +162 -0
  33. rakam_systems_core-0.1.1rc7.dist-info/RECORD +34 -0
  34. rakam_systems_core-0.1.1rc7.dist-info/WHEEL +4 -0
@@ -0,0 +1,41 @@
1
+ """
2
+ Rakam System Core - Core abstractions and data structures for the AI system.
3
+ """
4
+
5
+ from .ai_core.vs_core import Node, NodeMetadata, VSFile
6
+ from .ai_core import (
7
+ AgentComponent,
8
+ AgentInput,
9
+ AgentOutput,
10
+ ModelSettings,
11
+ ToolComponent,
12
+ ConfigurationLoader,
13
+ TrackingManager,
14
+ TrackingMixin,
15
+ track_method,
16
+ get_tracking_manager,
17
+ )
18
+
19
+ __all__ = [
20
+ # Core data structures
21
+ "Node",
22
+ "NodeMetadata",
23
+ "VSFile",
24
+ # Core interfaces
25
+ "AgentComponent",
26
+ "AgentInput",
27
+ "AgentOutput",
28
+ "ModelSettings",
29
+ "ToolComponent",
30
+ # Configuration
31
+ "ConfigurationLoader",
32
+ # Tracking
33
+ "TrackingManager",
34
+ "TrackingMixin",
35
+ "track_method",
36
+ "get_tracking_manager",
37
+ ]
38
+
39
+
40
+ def hello() -> str:
41
+ return "Hello from rakam-system-core!"
@@ -0,0 +1,68 @@
1
+ """Core abstractions for the AI system."""
2
+
3
+ from .interfaces import (
4
+ AgentComponent,
5
+ AgentInput,
6
+ AgentOutput,
7
+ ModelSettings,
8
+ ToolComponent,
9
+ )
10
+
11
+ # Core data structures
12
+ from .vs_core import Node, NodeMetadata, VSFile
13
+
14
+ # Configuration and tracking
15
+ from .config_loader import ConfigurationLoader
16
+ from .tracking import (
17
+ TrackingManager,
18
+ TrackingMixin,
19
+ track_method,
20
+ get_tracking_manager,
21
+ )
22
+
23
+ # Configuration schemas
24
+ from .config_schema import (
25
+ AgentConfigSchema,
26
+ ToolConfigSchema,
27
+ ModelConfigSchema,
28
+ PromptConfigSchema,
29
+ ConfigFileSchema,
30
+ MethodInputSchema,
31
+ MethodOutputSchema,
32
+ MethodCallRecordSchema,
33
+ TrackingSessionSchema,
34
+ EvaluationCriteriaSchema,
35
+ EvaluationResultSchema,
36
+ )
37
+
38
+ __all__ = [
39
+ # Core interfaces
40
+ "AgentComponent",
41
+ "AgentInput",
42
+ "AgentOutput",
43
+ "ModelSettings",
44
+ "ToolComponent",
45
+ # Core data structures
46
+ "Node",
47
+ "NodeMetadata",
48
+ "VSFile",
49
+ # Configuration
50
+ "ConfigurationLoader",
51
+ "AgentConfigSchema",
52
+ "ToolConfigSchema",
53
+ "ModelConfigSchema",
54
+ "PromptConfigSchema",
55
+ "ConfigFileSchema",
56
+ # Tracking
57
+ "TrackingManager",
58
+ "TrackingMixin",
59
+ "track_method",
60
+ "get_tracking_manager",
61
+ "MethodInputSchema",
62
+ "MethodOutputSchema",
63
+ "MethodCallRecordSchema",
64
+ "TrackingSessionSchema",
65
+ # Evaluation
66
+ "EvaluationCriteriaSchema",
67
+ "EvaluationResultSchema",
68
+ ]
@@ -0,0 +1,142 @@
1
+ from __future__ import annotations
2
+
3
+ from abc import ABC, abstractmethod
4
+ from typing import Any, Dict, Iterable, List, Optional, Callable, Tuple
5
+ import time
6
+ import traceback
7
+ import contextlib
8
+
9
+
10
+ class BaseComponent(ABC):
11
+ """Minimal, dependency-free lifecycle + evaluation mixin for all components.
12
+
13
+ Responsibilities
14
+ - hold a name + config
15
+ - provide setup()/shutdown() lifecycle
16
+ - provide __call__ that auto-setup then delegates to run()
17
+ - provide evaluate() helper for quick smoke tests (no external deps)
18
+ - context manager support to ensure shutdown() on exit
19
+ """
20
+
21
+ def __init__(self, name: str, config: Optional[Dict[str, Any]] = None) -> None:
22
+ self.name: str = name
23
+ self.config: Dict[str, Any] = dict(config or {})
24
+ self.initialized: bool = False
25
+
26
+ # ---------- lifecycle ----------
27
+ def setup(self) -> None:
28
+ """Initialize heavy resources (override in subclasses)."""
29
+ self.initialized = True
30
+
31
+ def shutdown(self) -> None:
32
+ """Release resources (override in subclasses)."""
33
+ self.initialized = False
34
+
35
+ @abstractmethod
36
+ def run(self, *args: Any, **kwargs: Any) -> Any:
37
+ """Execute the primary operation for the component."""
38
+ raise NotImplementedError
39
+
40
+ def __call__(self, *args: Any, **kwargs: Any) -> Any:
41
+ if not self.initialized:
42
+ self.setup()
43
+ return self.run(*args, **kwargs)
44
+
45
+ # ---------- context manager ----------
46
+ def __enter__(self) -> "BaseComponent":
47
+ if not self.initialized:
48
+ self.setup()
49
+ return self
50
+
51
+ def __exit__(self, exc_type, exc, tb) -> None:
52
+ # Always attempt to shutdown, even if exceptions happened
53
+ with contextlib.suppress(Exception):
54
+ self.shutdown()
55
+
56
+ # ---------- utility: timed call wrapper ----------
57
+ def timed(
58
+ self, fn: Callable[..., Any], *args: Any, **kwargs: Any
59
+ ) -> Tuple[Any, float]:
60
+ start = time.time()
61
+ out = fn(*args, **kwargs)
62
+ return out, time.time() - start
63
+
64
+ # ---------- micro evaluation harness ----------
65
+ def evaluate(
66
+ self,
67
+ methods: Optional[List[str]] = None,
68
+ test_cases: Optional[Dict[str, List[Dict[str, Any]]]] = None,
69
+ metric_fn: Optional[Callable[[Any, Any], float]] = None,
70
+ verbose: bool = True,
71
+ ) -> Dict[str, Any]:
72
+ """Evaluate one or more public methods using a tiny harness.
73
+
74
+ test_cases format:
75
+ {
76
+ "run": [
77
+ {"args": [...], "kwargs": {...}, "expected": <any>},
78
+ ...
79
+ ],
80
+ "other_method": [...]
81
+ }
82
+ """
83
+ methods = methods or ["run"]
84
+ results: Dict[str, Any] = {}
85
+
86
+ for method_name in methods:
87
+ if not hasattr(self, method_name):
88
+ raise AttributeError(
89
+ f"{self.__class__.__name__} has no method '{method_name}'"
90
+ )
91
+ method = getattr(self, method_name)
92
+ if not callable(method):
93
+ raise TypeError(f"{method_name} is not callable")
94
+
95
+ cases = (test_cases or {}).get(method_name, [])
96
+ mres: List[Dict[str, Any]] = []
97
+ if verbose:
98
+ print(
99
+ f"🔍 Evaluating {self.name}.{method_name} on {len(cases)} case(s)..."
100
+ )
101
+
102
+ for i, case in enumerate(cases):
103
+ args = list(case.get("args", []))
104
+ kwargs = dict(case.get("kwargs", {}))
105
+ expected = case.get("expected", None)
106
+
107
+ t0 = time.time()
108
+ try:
109
+ out = method(*args, **kwargs)
110
+ dt = time.time() - t0
111
+ score = (
112
+ metric_fn(out, expected)
113
+ if (metric_fn and expected is not None)
114
+ else None
115
+ )
116
+ mres.append(
117
+ {
118
+ "case": i,
119
+ "ok": True, # kept for backwards-compat
120
+ "success": True, # <- added for your tests
121
+ "time": dt,
122
+ "input": {"args": args, "kwargs": kwargs},
123
+ "output": out,
124
+ "expected": expected,
125
+ "score": score,
126
+ }
127
+ )
128
+ except Exception as e:
129
+ mres.append(
130
+ {
131
+ "case": i,
132
+ "ok": False, # kept for backwards-compat
133
+ "success": False, # <- added for your tests
134
+ "error": f"{e}",
135
+ "traceback": traceback.format_exc(),
136
+ }
137
+ )
138
+ results[method_name] = mres
139
+
140
+ if verbose:
141
+ print(f"✅ Evaluation complete for {self.name}.")
142
+ return results
@@ -0,0 +1,12 @@
1
+ from __future__ import annotations
2
+ import os
3
+ from dataclasses import dataclass
4
+
5
+ @dataclass
6
+ class Settings:
7
+ env: str = os.environ.get("AI_ENV", "dev")
8
+ debug: bool = os.environ.get("AI_DEBUG", "0") == "1"
9
+ # Add more keys here as needed, always optional to avoid deps.
10
+ # Example: OPENROUTER_API_KEY = os.environ.get("OPENROUTER_API_KEY")
11
+
12
+ settings = Settings()