rakam-systems-core 0.1.1rc7__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.
- rakam_systems_core-0.1.1rc7/.gitignore +46 -0
- rakam_systems_core-0.1.1rc7/.python-version +1 -0
- rakam_systems_core-0.1.1rc7/PKG-INFO +162 -0
- rakam_systems_core-0.1.1rc7/README.md +152 -0
- rakam_systems_core-0.1.1rc7/pyproject.toml +19 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/__init__.py +41 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/__init__.py +68 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/base.py +142 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/config.py +12 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/config_loader.py +580 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/config_schema.py +395 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/__init__.py +30 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/agent.py +83 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/chat_history.py +122 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/chunker.py +11 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/embedding_model.py +10 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/indexer.py +10 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/llm_gateway.py +139 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/loader.py +86 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/reranker.py +10 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/retriever.py +11 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/tool.py +162 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/tool_invoker.py +260 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/tool_loader.py +374 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/tool_registry.py +287 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/interfaces/vectorstore.py +37 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/mcp/README.md +545 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/mcp/__init__.py +0 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/mcp/mcp_server.py +334 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/tracking.py +602 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_core/vs_core.py +55 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_utils/__init__.py +16 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_utils/logging.py +126 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_utils/metrics.py +10 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_utils/s3.py +480 -0
- rakam_systems_core-0.1.1rc7/src/rakam_systems_core/ai_utils/tracing.py +5 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Python specific
|
|
2
|
+
*.pyc
|
|
3
|
+
*.pyo
|
|
4
|
+
*.pyd
|
|
5
|
+
__pycache__/
|
|
6
|
+
.pytest_cache/
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Environments
|
|
10
|
+
.env
|
|
11
|
+
*.env
|
|
12
|
+
*.venv*
|
|
13
|
+
venv/
|
|
14
|
+
*venv/
|
|
15
|
+
ENV/
|
|
16
|
+
env/
|
|
17
|
+
env.bak/
|
|
18
|
+
venv.bak/
|
|
19
|
+
|
|
20
|
+
# VS Code
|
|
21
|
+
.vscode/
|
|
22
|
+
.vscode/*
|
|
23
|
+
|
|
24
|
+
# PyCharm
|
|
25
|
+
.idea/
|
|
26
|
+
.idea/*
|
|
27
|
+
|
|
28
|
+
# OS specific
|
|
29
|
+
.DS_Store
|
|
30
|
+
Thumbs.db
|
|
31
|
+
|
|
32
|
+
#data
|
|
33
|
+
data/
|
|
34
|
+
dist/
|
|
35
|
+
logs/
|
|
36
|
+
|
|
37
|
+
# Build artifacts
|
|
38
|
+
*.egg-info/
|
|
39
|
+
|
|
40
|
+
# tracking data
|
|
41
|
+
agent_tracking/
|
|
42
|
+
|
|
43
|
+
# docs
|
|
44
|
+
docs/
|
|
45
|
+
|
|
46
|
+
temp_path/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.11
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rakam-systems-core
|
|
3
|
+
Version: 0.1.1rc7
|
|
4
|
+
Summary: A Package containing core logic and schema for rakam-systems
|
|
5
|
+
Author-email: Mohamed Hilel <mohammedjassemhlel@gmail.com>, Peng Zheng <pengzheng990630@outlook.com>, somebodyawesome-dev <luckynoob2011830@gmail.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: boto3>=1.26.0
|
|
8
|
+
Requires-Dist: pydantic
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# Rakam System Core
|
|
12
|
+
|
|
13
|
+
The core package of Rakam Systems providing foundational interfaces, base components, and utilities.
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
`rakam-system-core` is the foundation of the Rakam Systems framework. It provides:
|
|
18
|
+
|
|
19
|
+
- **Base Component**: Abstract base class with lifecycle management
|
|
20
|
+
- **Interfaces**: Standard interfaces for agents, tools, vector stores, embeddings, and loaders
|
|
21
|
+
- **Configuration System**: YAML/JSON configuration loading and validation
|
|
22
|
+
- **Tracking System**: Input/output tracking for debugging and evaluation
|
|
23
|
+
- **Logging Utilities**: Structured logging with color support
|
|
24
|
+
|
|
25
|
+
This package is required by both `rakam-system-agent` and `rakam-systems-vectorstore`.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install -e ./rakam-system-core
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Key Components
|
|
34
|
+
|
|
35
|
+
### BaseComponent
|
|
36
|
+
|
|
37
|
+
All components extend `BaseComponent` which provides:
|
|
38
|
+
|
|
39
|
+
- Lifecycle management with `setup()` and `shutdown()` methods
|
|
40
|
+
- Auto-initialization via `__call__`
|
|
41
|
+
- Context manager support
|
|
42
|
+
- Built-in evaluation harness
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from rakam_systems_core.ai_core.base import BaseComponent
|
|
46
|
+
|
|
47
|
+
class MyComponent(BaseComponent):
|
|
48
|
+
def setup(self):
|
|
49
|
+
super().setup()
|
|
50
|
+
# Initialize resources
|
|
51
|
+
|
|
52
|
+
def shutdown(self):
|
|
53
|
+
# Clean up resources
|
|
54
|
+
super().shutdown()
|
|
55
|
+
|
|
56
|
+
def run(self, *args, **kwargs):
|
|
57
|
+
# Main logic
|
|
58
|
+
pass
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Interfaces
|
|
62
|
+
|
|
63
|
+
Standard interfaces for building AI systems:
|
|
64
|
+
|
|
65
|
+
- **AgentComponent**: AI agents with sync/async support
|
|
66
|
+
- **ToolComponent**: Callable tools for agents
|
|
67
|
+
- **LLMGateway**: LLM provider abstraction
|
|
68
|
+
- **VectorStore**: Vector storage interface
|
|
69
|
+
- **EmbeddingModel**: Text embedding interface
|
|
70
|
+
- **Loader**: Document loading interface
|
|
71
|
+
- **Chunker**: Text chunking interface
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from rakam_systems_core.ai_core.interfaces.agent import AgentComponent
|
|
75
|
+
from rakam_systems_core.ai_core.interfaces.tool import ToolComponent
|
|
76
|
+
from rakam_systems_core.ai_core.interfaces.vectorstore import VectorStore
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Configuration System
|
|
80
|
+
|
|
81
|
+
Load and validate configurations from YAML files:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from rakam_systems_core.ai_core.config_loader import ConfigurationLoader
|
|
85
|
+
|
|
86
|
+
loader = ConfigurationLoader()
|
|
87
|
+
config = loader.load_from_yaml("agent_config.yaml")
|
|
88
|
+
agent = loader.create_agent("my_agent", config)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Tracking System
|
|
92
|
+
|
|
93
|
+
Track inputs and outputs for debugging:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from rakam_systems_core.ai_core.tracking import TrackingMixin
|
|
97
|
+
|
|
98
|
+
class MyAgent(TrackingMixin, BaseAgent):
|
|
99
|
+
pass
|
|
100
|
+
|
|
101
|
+
agent.enable_tracking(output_dir="./tracking")
|
|
102
|
+
# Use agent...
|
|
103
|
+
agent.export_tracking_data(format='csv')
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Package Structure
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
rakam-system-core/
|
|
110
|
+
├── src/rakam_systems_core/
|
|
111
|
+
│ ├── ai_core/
|
|
112
|
+
│ │ ├── base.py # BaseComponent
|
|
113
|
+
│ │ ├── interfaces/ # Standard interfaces
|
|
114
|
+
│ │ ├── config_loader.py # Configuration system
|
|
115
|
+
│ │ ├── tracking.py # I/O tracking
|
|
116
|
+
│ │ └── mcp/ # MCP server support
|
|
117
|
+
│ └── ai_utils/
|
|
118
|
+
│ └── logging.py # Logging utilities
|
|
119
|
+
└── pyproject.toml
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Usage in Other Packages
|
|
123
|
+
|
|
124
|
+
### Agent Package
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
# rakam-system-agent uses core interfaces
|
|
128
|
+
from rakam_systems_core.ai_core.interfaces.agent import AgentComponent
|
|
129
|
+
from rakam_system_agent import BaseAgent
|
|
130
|
+
|
|
131
|
+
agent = BaseAgent(name="my_agent", model="openai:gpt-4o")
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Vectorstore Package
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
# rakam-systems-vectorstore uses core interfaces
|
|
138
|
+
from rakam_systems_core.ai_core.interfaces.vectorstore import VectorStore
|
|
139
|
+
from rakam_systems_vectorstore import ConfigurablePgVectorStore
|
|
140
|
+
|
|
141
|
+
store = ConfigurablePgVectorStore(config=config)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Development
|
|
145
|
+
|
|
146
|
+
This package contains only interfaces and utilities. To contribute:
|
|
147
|
+
|
|
148
|
+
1. Install in editable mode: `pip install -e ./rakam-system-core`
|
|
149
|
+
2. Make changes to interfaces or utilities
|
|
150
|
+
3. Ensure backward compatibility with agent and vectorstore packages
|
|
151
|
+
4. Update version in `pyproject.toml`
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
Apache 2.0
|
|
156
|
+
|
|
157
|
+
## Links
|
|
158
|
+
|
|
159
|
+
- [Main Repository](https://github.com/Rakam-AI/rakam-systems)
|
|
160
|
+
- [Documentation](../docs/)
|
|
161
|
+
- [Agent Package](../rakam-system-agent/)
|
|
162
|
+
- [Vectorstore Package](../rakam-systems-vectorstore/)
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Rakam System Core
|
|
2
|
+
|
|
3
|
+
The core package of Rakam Systems providing foundational interfaces, base components, and utilities.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`rakam-system-core` is the foundation of the Rakam Systems framework. It provides:
|
|
8
|
+
|
|
9
|
+
- **Base Component**: Abstract base class with lifecycle management
|
|
10
|
+
- **Interfaces**: Standard interfaces for agents, tools, vector stores, embeddings, and loaders
|
|
11
|
+
- **Configuration System**: YAML/JSON configuration loading and validation
|
|
12
|
+
- **Tracking System**: Input/output tracking for debugging and evaluation
|
|
13
|
+
- **Logging Utilities**: Structured logging with color support
|
|
14
|
+
|
|
15
|
+
This package is required by both `rakam-system-agent` and `rakam-systems-vectorstore`.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install -e ./rakam-system-core
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Key Components
|
|
24
|
+
|
|
25
|
+
### BaseComponent
|
|
26
|
+
|
|
27
|
+
All components extend `BaseComponent` which provides:
|
|
28
|
+
|
|
29
|
+
- Lifecycle management with `setup()` and `shutdown()` methods
|
|
30
|
+
- Auto-initialization via `__call__`
|
|
31
|
+
- Context manager support
|
|
32
|
+
- Built-in evaluation harness
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from rakam_systems_core.ai_core.base import BaseComponent
|
|
36
|
+
|
|
37
|
+
class MyComponent(BaseComponent):
|
|
38
|
+
def setup(self):
|
|
39
|
+
super().setup()
|
|
40
|
+
# Initialize resources
|
|
41
|
+
|
|
42
|
+
def shutdown(self):
|
|
43
|
+
# Clean up resources
|
|
44
|
+
super().shutdown()
|
|
45
|
+
|
|
46
|
+
def run(self, *args, **kwargs):
|
|
47
|
+
# Main logic
|
|
48
|
+
pass
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Interfaces
|
|
52
|
+
|
|
53
|
+
Standard interfaces for building AI systems:
|
|
54
|
+
|
|
55
|
+
- **AgentComponent**: AI agents with sync/async support
|
|
56
|
+
- **ToolComponent**: Callable tools for agents
|
|
57
|
+
- **LLMGateway**: LLM provider abstraction
|
|
58
|
+
- **VectorStore**: Vector storage interface
|
|
59
|
+
- **EmbeddingModel**: Text embedding interface
|
|
60
|
+
- **Loader**: Document loading interface
|
|
61
|
+
- **Chunker**: Text chunking interface
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from rakam_systems_core.ai_core.interfaces.agent import AgentComponent
|
|
65
|
+
from rakam_systems_core.ai_core.interfaces.tool import ToolComponent
|
|
66
|
+
from rakam_systems_core.ai_core.interfaces.vectorstore import VectorStore
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Configuration System
|
|
70
|
+
|
|
71
|
+
Load and validate configurations from YAML files:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from rakam_systems_core.ai_core.config_loader import ConfigurationLoader
|
|
75
|
+
|
|
76
|
+
loader = ConfigurationLoader()
|
|
77
|
+
config = loader.load_from_yaml("agent_config.yaml")
|
|
78
|
+
agent = loader.create_agent("my_agent", config)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Tracking System
|
|
82
|
+
|
|
83
|
+
Track inputs and outputs for debugging:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from rakam_systems_core.ai_core.tracking import TrackingMixin
|
|
87
|
+
|
|
88
|
+
class MyAgent(TrackingMixin, BaseAgent):
|
|
89
|
+
pass
|
|
90
|
+
|
|
91
|
+
agent.enable_tracking(output_dir="./tracking")
|
|
92
|
+
# Use agent...
|
|
93
|
+
agent.export_tracking_data(format='csv')
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Package Structure
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
rakam-system-core/
|
|
100
|
+
├── src/rakam_systems_core/
|
|
101
|
+
│ ├── ai_core/
|
|
102
|
+
│ │ ├── base.py # BaseComponent
|
|
103
|
+
│ │ ├── interfaces/ # Standard interfaces
|
|
104
|
+
│ │ ├── config_loader.py # Configuration system
|
|
105
|
+
│ │ ├── tracking.py # I/O tracking
|
|
106
|
+
│ │ └── mcp/ # MCP server support
|
|
107
|
+
│ └── ai_utils/
|
|
108
|
+
│ └── logging.py # Logging utilities
|
|
109
|
+
└── pyproject.toml
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Usage in Other Packages
|
|
113
|
+
|
|
114
|
+
### Agent Package
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
# rakam-system-agent uses core interfaces
|
|
118
|
+
from rakam_systems_core.ai_core.interfaces.agent import AgentComponent
|
|
119
|
+
from rakam_system_agent import BaseAgent
|
|
120
|
+
|
|
121
|
+
agent = BaseAgent(name="my_agent", model="openai:gpt-4o")
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Vectorstore Package
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
# rakam-systems-vectorstore uses core interfaces
|
|
128
|
+
from rakam_systems_core.ai_core.interfaces.vectorstore import VectorStore
|
|
129
|
+
from rakam_systems_vectorstore import ConfigurablePgVectorStore
|
|
130
|
+
|
|
131
|
+
store = ConfigurablePgVectorStore(config=config)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Development
|
|
135
|
+
|
|
136
|
+
This package contains only interfaces and utilities. To contribute:
|
|
137
|
+
|
|
138
|
+
1. Install in editable mode: `pip install -e ./rakam-system-core`
|
|
139
|
+
2. Make changes to interfaces or utilities
|
|
140
|
+
3. Ensure backward compatibility with agent and vectorstore packages
|
|
141
|
+
4. Update version in `pyproject.toml`
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
Apache 2.0
|
|
146
|
+
|
|
147
|
+
## Links
|
|
148
|
+
|
|
149
|
+
- [Main Repository](https://github.com/Rakam-AI/rakam-systems)
|
|
150
|
+
- [Documentation](../docs/)
|
|
151
|
+
- [Agent Package](../rakam-system-agent/)
|
|
152
|
+
- [Vectorstore Package](../rakam-systems-vectorstore/)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "rakam-systems-core"
|
|
3
|
+
version = "0.1.1rc7"
|
|
4
|
+
description = "A Package containing core logic and schema for rakam-systems"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{name = "Mohamed Hilel", email = "mohammedjassemhlel@gmail.com"},
|
|
8
|
+
{name = "Peng Zheng", email = "pengzheng990630@outlook.com"},
|
|
9
|
+
{name = "somebodyawesome-dev", email = "luckynoob2011830@gmail.com"}
|
|
10
|
+
]
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"pydantic",
|
|
14
|
+
"boto3>=1.26.0", # For S3 utilities
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[build-system]
|
|
18
|
+
requires = ["hatchling"]
|
|
19
|
+
build-backend = "hatchling.build"
|
|
@@ -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()
|