naas-abi-core 1.4.1__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.
- assets/favicon.ico +0 -0
- assets/logo.png +0 -0
- naas_abi_core/__init__.py +1 -0
- naas_abi_core/apps/api/api.py +245 -0
- naas_abi_core/apps/api/api_test.py +281 -0
- naas_abi_core/apps/api/openapi_doc.py +144 -0
- naas_abi_core/apps/mcp/Dockerfile.mcp +35 -0
- naas_abi_core/apps/mcp/mcp_server.py +243 -0
- naas_abi_core/apps/mcp/mcp_server_test.py +163 -0
- naas_abi_core/apps/terminal_agent/main.py +555 -0
- naas_abi_core/apps/terminal_agent/terminal_style.py +175 -0
- naas_abi_core/engine/Engine.py +87 -0
- naas_abi_core/engine/EngineProxy.py +109 -0
- naas_abi_core/engine/Engine_test.py +6 -0
- naas_abi_core/engine/IEngine.py +91 -0
- naas_abi_core/engine/conftest.py +45 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration.py +216 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_Deploy.py +7 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_GenericLoader.py +49 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_ObjectStorageService.py +159 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_ObjectStorageService_test.py +26 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_SecretService.py +138 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_SecretService_test.py +74 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_TripleStoreService.py +224 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_TripleStoreService_test.py +109 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_VectorStoreService.py +76 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_VectorStoreService_test.py +33 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_test.py +9 -0
- naas_abi_core/engine/engine_configuration/utils/PydanticModelValidator.py +15 -0
- naas_abi_core/engine/engine_loaders/EngineModuleLoader.py +302 -0
- naas_abi_core/engine/engine_loaders/EngineOntologyLoader.py +16 -0
- naas_abi_core/engine/engine_loaders/EngineServiceLoader.py +47 -0
- naas_abi_core/integration/__init__.py +7 -0
- naas_abi_core/integration/integration.py +28 -0
- naas_abi_core/models/Model.py +198 -0
- naas_abi_core/models/OpenRouter.py +18 -0
- naas_abi_core/models/OpenRouter_test.py +36 -0
- naas_abi_core/module/Module.py +252 -0
- naas_abi_core/module/ModuleAgentLoader.py +50 -0
- naas_abi_core/module/ModuleUtils.py +20 -0
- naas_abi_core/modules/templatablesparqlquery/README.md +196 -0
- naas_abi_core/modules/templatablesparqlquery/__init__.py +39 -0
- naas_abi_core/modules/templatablesparqlquery/ontologies/TemplatableSparqlQueryOntology.ttl +116 -0
- naas_abi_core/modules/templatablesparqlquery/workflows/GenericWorkflow.py +48 -0
- naas_abi_core/modules/templatablesparqlquery/workflows/TemplatableSparqlQueryLoader.py +192 -0
- naas_abi_core/pipeline/__init__.py +6 -0
- naas_abi_core/pipeline/pipeline.py +70 -0
- naas_abi_core/services/__init__.py +0 -0
- naas_abi_core/services/agent/Agent.py +1619 -0
- naas_abi_core/services/agent/AgentMemory_test.py +28 -0
- naas_abi_core/services/agent/Agent_test.py +214 -0
- naas_abi_core/services/agent/IntentAgent.py +1179 -0
- naas_abi_core/services/agent/IntentAgent_test.py +139 -0
- naas_abi_core/services/agent/beta/Embeddings.py +181 -0
- naas_abi_core/services/agent/beta/IntentMapper.py +120 -0
- naas_abi_core/services/agent/beta/LocalModel.py +88 -0
- naas_abi_core/services/agent/beta/VectorStore.py +89 -0
- naas_abi_core/services/agent/test_agent_memory.py +278 -0
- naas_abi_core/services/agent/test_postgres_integration.py +145 -0
- naas_abi_core/services/cache/CacheFactory.py +31 -0
- naas_abi_core/services/cache/CachePort.py +63 -0
- naas_abi_core/services/cache/CacheService.py +246 -0
- naas_abi_core/services/cache/CacheService_test.py +85 -0
- naas_abi_core/services/cache/adapters/secondary/CacheFSAdapter.py +39 -0
- naas_abi_core/services/object_storage/ObjectStorageFactory.py +57 -0
- naas_abi_core/services/object_storage/ObjectStoragePort.py +47 -0
- naas_abi_core/services/object_storage/ObjectStorageService.py +41 -0
- naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterFS.py +52 -0
- naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterNaas.py +131 -0
- naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterS3.py +171 -0
- naas_abi_core/services/ontology/OntologyPorts.py +36 -0
- naas_abi_core/services/ontology/OntologyService.py +17 -0
- naas_abi_core/services/ontology/adaptors/secondary/OntologyService_SecondaryAdaptor_NERPort.py +37 -0
- naas_abi_core/services/secret/Secret.py +138 -0
- naas_abi_core/services/secret/SecretPorts.py +45 -0
- naas_abi_core/services/secret/Secret_test.py +65 -0
- naas_abi_core/services/secret/adaptors/secondary/Base64Secret.py +57 -0
- naas_abi_core/services/secret/adaptors/secondary/Base64Secret_test.py +39 -0
- naas_abi_core/services/secret/adaptors/secondary/NaasSecret.py +88 -0
- naas_abi_core/services/secret/adaptors/secondary/NaasSecret_test.py +25 -0
- naas_abi_core/services/secret/adaptors/secondary/dotenv_secret_secondaryadaptor.py +29 -0
- naas_abi_core/services/triple_store/TripleStoreFactory.py +116 -0
- naas_abi_core/services/triple_store/TripleStorePorts.py +223 -0
- naas_abi_core/services/triple_store/TripleStoreService.py +419 -0
- naas_abi_core/services/triple_store/adaptors/secondary/AWSNeptune.py +1300 -0
- naas_abi_core/services/triple_store/adaptors/secondary/AWSNeptune_test.py +284 -0
- naas_abi_core/services/triple_store/adaptors/secondary/Oxigraph.py +597 -0
- naas_abi_core/services/triple_store/adaptors/secondary/Oxigraph_test.py +1474 -0
- naas_abi_core/services/triple_store/adaptors/secondary/TripleStoreService__SecondaryAdaptor__Filesystem.py +223 -0
- naas_abi_core/services/triple_store/adaptors/secondary/TripleStoreService__SecondaryAdaptor__ObjectStorage.py +234 -0
- naas_abi_core/services/triple_store/adaptors/secondary/base/TripleStoreService__SecondaryAdaptor__FileBase.py +18 -0
- naas_abi_core/services/vector_store/IVectorStorePort.py +101 -0
- naas_abi_core/services/vector_store/IVectorStorePort_test.py +189 -0
- naas_abi_core/services/vector_store/VectorStoreFactory.py +47 -0
- naas_abi_core/services/vector_store/VectorStoreService.py +171 -0
- naas_abi_core/services/vector_store/VectorStoreService_test.py +185 -0
- naas_abi_core/services/vector_store/__init__.py +13 -0
- naas_abi_core/services/vector_store/adapters/QdrantAdapter.py +251 -0
- naas_abi_core/services/vector_store/adapters/QdrantAdapter_test.py +57 -0
- naas_abi_core/tests/test_services_imports.py +69 -0
- naas_abi_core/utils/Expose.py +55 -0
- naas_abi_core/utils/Graph.py +182 -0
- naas_abi_core/utils/JSON.py +49 -0
- naas_abi_core/utils/LazyLoader.py +44 -0
- naas_abi_core/utils/Logger.py +12 -0
- naas_abi_core/utils/OntologyReasoner.py +141 -0
- naas_abi_core/utils/OntologyYaml.py +681 -0
- naas_abi_core/utils/SPARQL.py +256 -0
- naas_abi_core/utils/Storage.py +33 -0
- naas_abi_core/utils/StorageUtils.py +398 -0
- naas_abi_core/utils/String.py +52 -0
- naas_abi_core/utils/Workers.py +114 -0
- naas_abi_core/utils/__init__.py +0 -0
- naas_abi_core/utils/onto2py/README.md +0 -0
- naas_abi_core/utils/onto2py/__init__.py +10 -0
- naas_abi_core/utils/onto2py/__main__.py +29 -0
- naas_abi_core/utils/onto2py/onto2py.py +611 -0
- naas_abi_core/utils/onto2py/tests/ttl2py_test.py +271 -0
- naas_abi_core/workflow/__init__.py +5 -0
- naas_abi_core/workflow/workflow.py +48 -0
- naas_abi_core-1.4.1.dist-info/METADATA +630 -0
- naas_abi_core-1.4.1.dist-info/RECORD +124 -0
- naas_abi_core-1.4.1.dist-info/WHEEL +4 -0
- naas_abi_core-1.4.1.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: naas-abi-core
|
|
3
|
+
Version: 1.4.1
|
|
4
|
+
Summary: Abi framework allowing you to build your AI system.
|
|
5
|
+
Project-URL: Homepage, https://github.com/jupyter-naas/abi
|
|
6
|
+
Project-URL: Repository, https://github.com/jupyter-naas/abi/tree/main/libs/naas-abi-core
|
|
7
|
+
Author-email: Maxime Jublou <maxime@naas.ai>, Florent Ravenel <florent@naas.ai>, Jeremy Ravenel <jeremy@naas.ai>
|
|
8
|
+
Requires-Python: <4,>=3.10
|
|
9
|
+
Requires-Dist: click<8.2,>=8.1.1
|
|
10
|
+
Requires-Dist: docker>=7.1.0
|
|
11
|
+
Requires-Dist: dotenv>=0.9.9
|
|
12
|
+
Requires-Dist: fastapi<0.116,>=0.115.5
|
|
13
|
+
Requires-Dist: fastmcp>=2.13.2
|
|
14
|
+
Requires-Dist: langchain-openai<0.4,>=0.3.3
|
|
15
|
+
Requires-Dist: langgraph-checkpoint-postgres>=2.0.21
|
|
16
|
+
Requires-Dist: langgraph>=0.6.6
|
|
17
|
+
Requires-Dist: loguru<0.8,>=0.7.2
|
|
18
|
+
Requires-Dist: pandas-stubs>=2.3.2.251219
|
|
19
|
+
Requires-Dist: pandas>=2.3.3
|
|
20
|
+
Requires-Dist: pillow>=12.0.0
|
|
21
|
+
Requires-Dist: pip>=25.1.1
|
|
22
|
+
Requires-Dist: psycopg[binary,pool]>=3.0.0
|
|
23
|
+
Requires-Dist: pydantic>=2.11.5
|
|
24
|
+
Requires-Dist: pydash>=8.0.5
|
|
25
|
+
Requires-Dist: pytz>=2025.2
|
|
26
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
27
|
+
Requires-Dist: rdflib<8,>=7.1.1
|
|
28
|
+
Requires-Dist: rich<14,>=13.9.4
|
|
29
|
+
Requires-Dist: spacy>=3.8.7
|
|
30
|
+
Requires-Dist: sparqlwrapper>=2.0.0
|
|
31
|
+
Requires-Dist: sse-starlette<3,>=2.1.3
|
|
32
|
+
Requires-Dist: starlette>=0.46.2
|
|
33
|
+
Requires-Dist: types-paramiko>=4.0.0.20250822
|
|
34
|
+
Requires-Dist: types-pyyaml>=6.0.12.20250915
|
|
35
|
+
Requires-Dist: types-tqdm>=4.67.0.20250809
|
|
36
|
+
Provides-Extra: all
|
|
37
|
+
Requires-Dist: boto3-stubs>=1.42.19; extra == 'all'
|
|
38
|
+
Requires-Dist: boto3<2,>=1.38.19; extra == 'all'
|
|
39
|
+
Requires-Dist: langchain-openai>=0.3.35; extra == 'all'
|
|
40
|
+
Requires-Dist: paramiko<4.0.0,>=3.5.1; extra == 'all'
|
|
41
|
+
Requires-Dist: qdrant-client>=1.14.3; extra == 'all'
|
|
42
|
+
Requires-Dist: sshtunnel>=0.4.0; extra == 'all'
|
|
43
|
+
Provides-Extra: aws
|
|
44
|
+
Requires-Dist: boto3-stubs>=1.42.19; extra == 'aws'
|
|
45
|
+
Requires-Dist: boto3<2,>=1.38.19; extra == 'aws'
|
|
46
|
+
Provides-Extra: openrouter
|
|
47
|
+
Requires-Dist: langchain-openai>=0.3.35; extra == 'openrouter'
|
|
48
|
+
Provides-Extra: qdrant
|
|
49
|
+
Requires-Dist: qdrant-client>=1.14.3; extra == 'qdrant'
|
|
50
|
+
Provides-Extra: ssh
|
|
51
|
+
Requires-Dist: paramiko<4.0.0,>=3.5.1; extra == 'ssh'
|
|
52
|
+
Requires-Dist: sshtunnel>=0.4.0; extra == 'ssh'
|
|
53
|
+
Description-Content-Type: text/markdown
|
|
54
|
+
|
|
55
|
+
# naas-abi-core
|
|
56
|
+
|
|
57
|
+
The core implementation library for ABI (Agentic Brain Infrastructure), providing the fundamental building blocks for building unified AI systems. This library implements the core concepts, services, and architecture patterns that enable ontology-driven AI applications.
|
|
58
|
+
|
|
59
|
+
## Overview
|
|
60
|
+
|
|
61
|
+
The ABI Library is the core implementation of ABI's concepts, designed to build a unified AI system. This library provides the fundamental building blocks for connecting, processing, and utilizing data across different AI components.
|
|
62
|
+
|
|
63
|
+
`naas-abi-core` is the foundational library that powers the ABI framework. It provides:
|
|
64
|
+
|
|
65
|
+
- **Engine**: Central orchestration system that loads and coordinates modules, services, and ontologies
|
|
66
|
+
- **Services**: Hexagonal architecture-based services for storage, secrets, and AI capabilities
|
|
67
|
+
- **Modules**: Modular system for organizing agents, integrations, pipelines, and workflows
|
|
68
|
+
- **Agents**: LangGraph-based AI agents with tool binding and conversation management
|
|
69
|
+
- **Applications**: Ready-to-use interfaces (REST API, Terminal, MCP Protocol)
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install naas-abi-core
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Optional Dependencies
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# For Qdrant vector store support
|
|
81
|
+
pip install naas-abi-core[qdrant]
|
|
82
|
+
|
|
83
|
+
# For AWS S3 object storage support
|
|
84
|
+
pip install naas-abi-core[aws]
|
|
85
|
+
|
|
86
|
+
# For SSH tunnel support
|
|
87
|
+
pip install naas-abi-core[ssh]
|
|
88
|
+
|
|
89
|
+
# For OpenRouter integration
|
|
90
|
+
pip install naas-abi-core[openrouter]
|
|
91
|
+
|
|
92
|
+
# Install all optional dependencies
|
|
93
|
+
pip install naas-abi-core[all]
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Core Architecture
|
|
97
|
+
|
|
98
|
+
### Engine
|
|
99
|
+
|
|
100
|
+
The `Engine` is the central orchestrator that:
|
|
101
|
+
|
|
102
|
+
1. **Loads Configuration**: Reads and validates YAML configuration files
|
|
103
|
+
2. **Initializes Services**: Sets up storage, vector, triple store, and secret services based on module dependencies
|
|
104
|
+
3. **Loads Modules**: Discovers and loads modules with their agents, integrations, pipelines, and workflows
|
|
105
|
+
4. **Loads Ontologies**: Loads RDF ontologies into the triple store for semantic reasoning
|
|
106
|
+
5. **Initializes Components**: Calls `on_initialized()` on all modules after everything is loaded
|
|
107
|
+
|
|
108
|
+
**Example Usage:**
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from naas_abi_core.engine.Engine import Engine
|
|
112
|
+
|
|
113
|
+
# Initialize engine with default configuration (config.yaml)
|
|
114
|
+
engine = Engine()
|
|
115
|
+
|
|
116
|
+
# Load all modules
|
|
117
|
+
engine.load()
|
|
118
|
+
|
|
119
|
+
# Or load specific modules
|
|
120
|
+
engine.load(module_names=["naas_abi", "my_custom_module"])
|
|
121
|
+
|
|
122
|
+
# Access loaded modules
|
|
123
|
+
for module_name, module in engine.modules.items():
|
|
124
|
+
print(f"Module: {module_name}")
|
|
125
|
+
print(f"Agents: {[agent.__name__ for agent in module.agents]}")
|
|
126
|
+
|
|
127
|
+
# Access services
|
|
128
|
+
triple_store = engine.services.triple_store
|
|
129
|
+
vector_store = engine.services.vector_store
|
|
130
|
+
object_storage = engine.services.object_storage
|
|
131
|
+
secret_service = engine.services.secret
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Modules
|
|
135
|
+
|
|
136
|
+
Modules are the primary organizational unit in ABI. Each module can contain:
|
|
137
|
+
|
|
138
|
+
- **Agents**: AI agents that can be used for conversations and task execution
|
|
139
|
+
- **Integrations**: Connections to third-party services and APIs
|
|
140
|
+
- **Pipelines**: Data transformation processes that convert raw data into semantic representations
|
|
141
|
+
- **Workflows**: Business logic that can be exposed as tools, API endpoints, or scheduled jobs
|
|
142
|
+
- **Ontologies**: RDF/Turtle files that define semantic knowledge structures
|
|
143
|
+
|
|
144
|
+
**Module Structure:**
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from naas_abi_core.module.Module import BaseModule, ModuleConfiguration
|
|
148
|
+
from naas_abi_core.engine.EngineProxy import EngineProxy
|
|
149
|
+
|
|
150
|
+
class MyModule(BaseModule):
|
|
151
|
+
class Configuration(ModuleConfiguration):
|
|
152
|
+
# Module-specific configuration
|
|
153
|
+
api_key: str
|
|
154
|
+
|
|
155
|
+
dependencies = ModuleDependencies(
|
|
156
|
+
modules=[], # Other modules this module depends on
|
|
157
|
+
services=[TripleStoreService, VectorStoreService] # Required services
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
def on_load(self):
|
|
161
|
+
# Called when module is loaded
|
|
162
|
+
# Load ontologies, agents, etc.
|
|
163
|
+
super().on_load()
|
|
164
|
+
|
|
165
|
+
def on_initialized(self):
|
|
166
|
+
# Called after all modules and services are initialized
|
|
167
|
+
# Safe to access other modules and services here
|
|
168
|
+
pass
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Services
|
|
172
|
+
|
|
173
|
+
Services form the foundational layer of ABI, implementing the Hexagonal Architecture (Ports & Adapters) pattern to provide flexible and system-agnostic interfaces. This architectural approach allows ABI to seamlessly integrate with existing systems while maintaining clean separation of concerns.
|
|
174
|
+
|
|
175
|
+
Each service defines a primary port (interface) that specifies its capabilities, while multiple secondary adapters can implement this interface for different backend systems. This means you can:
|
|
176
|
+
|
|
177
|
+
- Easily swap implementations without changing business logic
|
|
178
|
+
- Add new integrations by implementing new adapters
|
|
179
|
+
- Test components in isolation using mock adapters
|
|
180
|
+
|
|
181
|
+
For example, the Secret Service could connect to various backend systems through different adapters:
|
|
182
|
+
- Hashicorp Vault
|
|
183
|
+
- AWS Secrets Manager
|
|
184
|
+
- Azure Key Vault
|
|
185
|
+
- Environment Variables
|
|
186
|
+
- Local File System
|
|
187
|
+
- Google Cloud Secret Manager
|
|
188
|
+
- Kubernetes Secrets
|
|
189
|
+
|
|
190
|
+
This modular approach ensures that ABI can be deployed in any environment while maintaining consistent interfaces and behavior across different infrastructure choices.
|
|
191
|
+
|
|
192
|
+
#### Triple Store Service
|
|
193
|
+
|
|
194
|
+
Manages RDF knowledge graphs for semantic reasoning and ontology storage.
|
|
195
|
+
|
|
196
|
+
**Supported Backends:**
|
|
197
|
+
- Oxigraph (default)
|
|
198
|
+
- SPARQL endpoints
|
|
199
|
+
- Custom adapters
|
|
200
|
+
|
|
201
|
+
**Example:**
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
from naas_abi_core.services.triple_store.TripleStoreService import TripleStoreService
|
|
205
|
+
|
|
206
|
+
triple_store = engine.services.triple_store
|
|
207
|
+
|
|
208
|
+
# Query the knowledge graph
|
|
209
|
+
results = triple_store.query("""
|
|
210
|
+
SELECT ?subject ?predicate ?object
|
|
211
|
+
WHERE {
|
|
212
|
+
?subject ?predicate ?object
|
|
213
|
+
}
|
|
214
|
+
LIMIT 10
|
|
215
|
+
""")
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
#### Vector Store Service
|
|
219
|
+
|
|
220
|
+
Manages vector embeddings for semantic search and similarity matching.
|
|
221
|
+
|
|
222
|
+
**Supported Backends:**
|
|
223
|
+
- Qdrant (optional, requires `[qdrant]` extra)
|
|
224
|
+
- Custom adapters
|
|
225
|
+
|
|
226
|
+
**Example:**
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
from naas_abi_core.services.vector_store.VectorStoreService import VectorStoreService
|
|
230
|
+
|
|
231
|
+
vector_store = engine.services.vector_store
|
|
232
|
+
|
|
233
|
+
# Store embeddings
|
|
234
|
+
vector_store.upsert(
|
|
235
|
+
collection_name="intents",
|
|
236
|
+
vectors=[embedding],
|
|
237
|
+
ids=["intent_1"],
|
|
238
|
+
payloads=[{"text": "user query"}]
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
# Search similar vectors
|
|
242
|
+
results = vector_store.search(
|
|
243
|
+
collection_name="intents",
|
|
244
|
+
query_vector=query_embedding,
|
|
245
|
+
limit=5
|
|
246
|
+
)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### Object Storage Service
|
|
250
|
+
|
|
251
|
+
Manages file storage for documents, reports, and generated content.
|
|
252
|
+
|
|
253
|
+
**Supported Backends:**
|
|
254
|
+
- AWS S3 (optional, requires `[aws]` extra)
|
|
255
|
+
- MinIO
|
|
256
|
+
- Local file system
|
|
257
|
+
- Custom adapters
|
|
258
|
+
|
|
259
|
+
**Example:**
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
from naas_abi_core.services.object_storage.ObjectStorageService import ObjectStorageService
|
|
263
|
+
|
|
264
|
+
object_storage = engine.services.object_storage
|
|
265
|
+
|
|
266
|
+
# Upload a file
|
|
267
|
+
object_storage.upload(
|
|
268
|
+
bucket="my-bucket",
|
|
269
|
+
key="documents/report.pdf",
|
|
270
|
+
file_path="/path/to/report.pdf"
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
# Download a file
|
|
274
|
+
object_storage.download(
|
|
275
|
+
bucket="my-bucket",
|
|
276
|
+
key="documents/report.pdf",
|
|
277
|
+
file_path="/path/to/downloaded.pdf"
|
|
278
|
+
)
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
#### Secret Service
|
|
282
|
+
|
|
283
|
+
Manages secrets and credentials securely across different storage systems.
|
|
284
|
+
|
|
285
|
+
**Supported Backends:**
|
|
286
|
+
- Environment variables
|
|
287
|
+
- Naas Secret Manager
|
|
288
|
+
- Hashicorp Vault
|
|
289
|
+
- AWS Secrets Manager
|
|
290
|
+
- Azure Key Vault
|
|
291
|
+
- Google Cloud Secret Manager
|
|
292
|
+
- Kubernetes Secrets
|
|
293
|
+
- Local file system
|
|
294
|
+
- Custom adapters
|
|
295
|
+
|
|
296
|
+
**Example:**
|
|
297
|
+
|
|
298
|
+
```python
|
|
299
|
+
from naas_abi_core.services.secret.Secret import Secret
|
|
300
|
+
|
|
301
|
+
secret_service = engine.services.secret
|
|
302
|
+
|
|
303
|
+
# Get a secret
|
|
304
|
+
api_key = secret_service.get("OPENAI_API_KEY")
|
|
305
|
+
|
|
306
|
+
# List all secrets
|
|
307
|
+
all_secrets = secret_service.list()
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
#### Cache Service
|
|
311
|
+
|
|
312
|
+
Provides intelligent caching for API calls, tool results, and model responses to optimize performance and manage rate limits.
|
|
313
|
+
|
|
314
|
+
**Example:**
|
|
315
|
+
|
|
316
|
+
```python
|
|
317
|
+
from naas_abi_core.services.cache.CacheService import CacheService
|
|
318
|
+
|
|
319
|
+
cache = CacheService()
|
|
320
|
+
|
|
321
|
+
# Cache a function result
|
|
322
|
+
@cache.cache(ttl=3600)
|
|
323
|
+
def expensive_api_call(param: str):
|
|
324
|
+
# Expensive operation
|
|
325
|
+
return result
|
|
326
|
+
|
|
327
|
+
# Force refresh
|
|
328
|
+
result = expensive_api_call(param, force_refresh=True)
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## Core Concepts
|
|
332
|
+
|
|
333
|
+
### Integration
|
|
334
|
+
|
|
335
|
+
Integrations provide standardized connections to third-party services and data sources. They handle:
|
|
336
|
+
- Authentication and authorization
|
|
337
|
+
- API communication
|
|
338
|
+
- Data format standardization
|
|
339
|
+
- Error handling and retries
|
|
340
|
+
|
|
341
|
+
**Example:**
|
|
342
|
+
|
|
343
|
+
```python
|
|
344
|
+
from naas_abi_core.integration.integration import Integration, IntegrationConfiguration
|
|
345
|
+
|
|
346
|
+
class MyAPIConfiguration(IntegrationConfiguration):
|
|
347
|
+
api_key: str
|
|
348
|
+
base_url: str
|
|
349
|
+
|
|
350
|
+
class MyAPIIntegration(Integration):
|
|
351
|
+
def __init__(self, configuration: MyAPIConfiguration):
|
|
352
|
+
super().__init__(configuration)
|
|
353
|
+
# Initialize connection
|
|
354
|
+
|
|
355
|
+
def fetch_data(self):
|
|
356
|
+
# Implement API call
|
|
357
|
+
pass
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### Pipeline
|
|
361
|
+
|
|
362
|
+
Pipelines are responsible for data ingestion and transformation into the ontological layer. They:
|
|
363
|
+
- Utilize integrations to fetch data
|
|
364
|
+
- Transform raw data into semantic representations
|
|
365
|
+
- Maintain data consistency and quality
|
|
366
|
+
- Map external data models to ABI's ontology
|
|
367
|
+
|
|
368
|
+
**Example:**
|
|
369
|
+
|
|
370
|
+
```python
|
|
371
|
+
from naas_abi_core.pipeline.pipeline import Pipeline, PipelineConfiguration, PipelineParameters
|
|
372
|
+
from rdflib import Graph
|
|
373
|
+
|
|
374
|
+
class MyPipelineConfiguration(PipelineConfiguration):
|
|
375
|
+
integration_config: dict
|
|
376
|
+
|
|
377
|
+
class MyPipelineParameters(PipelineParameters):
|
|
378
|
+
source: str
|
|
379
|
+
|
|
380
|
+
class MyPipeline(Pipeline):
|
|
381
|
+
def __init__(self, configuration: MyPipelineConfiguration):
|
|
382
|
+
super().__init__(configuration)
|
|
383
|
+
|
|
384
|
+
def run(self, parameters: MyPipelineParameters) -> Graph:
|
|
385
|
+
# Fetch data from integration
|
|
386
|
+
# Transform to RDF
|
|
387
|
+
# Return Graph
|
|
388
|
+
graph = Graph()
|
|
389
|
+
# ... add triples to graph
|
|
390
|
+
return graph
|
|
391
|
+
|
|
392
|
+
def trigger(self, event, ontology_name, triple) -> Graph:
|
|
393
|
+
# Event-driven pipeline execution
|
|
394
|
+
return self.run(MyPipelineParameters(source="event"))
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### Workflow
|
|
398
|
+
|
|
399
|
+
Workflows leverage the ontological layer to implement business logic and provide data to consumers. They can be used by:
|
|
400
|
+
- Large Language Models (LLMs)
|
|
401
|
+
- Remote APIs and services
|
|
402
|
+
- Other automated processes
|
|
403
|
+
|
|
404
|
+
**Example:**
|
|
405
|
+
|
|
406
|
+
```python
|
|
407
|
+
from naas_abi_core.workflow.workflow import Workflow, WorkflowConfiguration, WorkflowParameters
|
|
408
|
+
from pydantic import BaseModel
|
|
409
|
+
|
|
410
|
+
class MyWorkflowParameters(WorkflowParameters):
|
|
411
|
+
input_data: str
|
|
412
|
+
|
|
413
|
+
class MyWorkflowConfiguration(WorkflowConfiguration):
|
|
414
|
+
processing_option: str
|
|
415
|
+
|
|
416
|
+
class MyWorkflow(Workflow[MyWorkflowParameters]):
|
|
417
|
+
def __init__(self, configuration: MyWorkflowConfiguration):
|
|
418
|
+
super().__init__(configuration)
|
|
419
|
+
|
|
420
|
+
def run(self, parameters: MyWorkflowParameters):
|
|
421
|
+
# Implement business logic
|
|
422
|
+
# Query knowledge graph
|
|
423
|
+
# Process data
|
|
424
|
+
# Return results
|
|
425
|
+
return {"result": "processed"}
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### Agent
|
|
429
|
+
|
|
430
|
+
Agents are AI-powered assistants that can have conversations, use tools, and delegate to sub-agents.
|
|
431
|
+
|
|
432
|
+
**Features:**
|
|
433
|
+
- LangGraph-based conversation management
|
|
434
|
+
- Tool binding and execution
|
|
435
|
+
- Sub-agent delegation
|
|
436
|
+
- Intent-based routing
|
|
437
|
+
- Conversation persistence (PostgreSQL checkpointing)
|
|
438
|
+
- Event streaming for real-time updates
|
|
439
|
+
|
|
440
|
+
**Example:**
|
|
441
|
+
|
|
442
|
+
```python
|
|
443
|
+
from naas_abi_core.services.agent.Agent import Agent
|
|
444
|
+
from langchain_openai import ChatOpenAI
|
|
445
|
+
|
|
446
|
+
class MyAgent(Agent):
|
|
447
|
+
def __init__(self):
|
|
448
|
+
super().__init__(
|
|
449
|
+
name="MyAgent",
|
|
450
|
+
description="An agent that helps with specific tasks",
|
|
451
|
+
system_prompt="You are a helpful assistant...",
|
|
452
|
+
chat_model=ChatOpenAI(model="gpt-4"),
|
|
453
|
+
tools=[my_tool, my_workflow],
|
|
454
|
+
agents=[sub_agent] # Optional sub-agents
|
|
455
|
+
)
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
## Applications
|
|
459
|
+
|
|
460
|
+
### REST API
|
|
461
|
+
|
|
462
|
+
FastAPI-based REST API that automatically exposes all agents, workflows, and pipelines.
|
|
463
|
+
|
|
464
|
+
**Features:**
|
|
465
|
+
- OpenAPI/Swagger documentation
|
|
466
|
+
- OAuth2 authentication
|
|
467
|
+
- CORS support
|
|
468
|
+
- Automatic endpoint generation from agents/workflows/pipelines
|
|
469
|
+
|
|
470
|
+
**Usage:**
|
|
471
|
+
|
|
472
|
+
```python
|
|
473
|
+
from naas_abi_core.apps.api.api import api
|
|
474
|
+
|
|
475
|
+
# Run the API server
|
|
476
|
+
api()
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
**Endpoints:**
|
|
480
|
+
- `GET /` - API landing page
|
|
481
|
+
- `GET /docs` - Swagger UI documentation
|
|
482
|
+
- `GET /redoc` - ReDoc documentation
|
|
483
|
+
- `POST /agents/{agent_name}/completion` - Agent completion endpoint
|
|
484
|
+
- `POST /workflows/{workflow_name}/run` - Workflow execution endpoint
|
|
485
|
+
- `POST /pipelines/{pipeline_name}/run` - Pipeline execution endpoint
|
|
486
|
+
|
|
487
|
+
### Terminal Agent
|
|
488
|
+
|
|
489
|
+
Interactive terminal interface for chatting with agents.
|
|
490
|
+
|
|
491
|
+
**Usage:**
|
|
492
|
+
|
|
493
|
+
```python
|
|
494
|
+
from naas_abi_core.apps.terminal_agent.main import run_agent
|
|
495
|
+
from naas_abi_core.services.agent.Agent import Agent
|
|
496
|
+
|
|
497
|
+
agent = MyAgent()
|
|
498
|
+
run_agent(agent)
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
### MCP Server
|
|
502
|
+
|
|
503
|
+
Model Context Protocol (MCP) server for integration with Claude Desktop and VS Code.
|
|
504
|
+
|
|
505
|
+
**Features:**
|
|
506
|
+
- Dynamic agent discovery from OpenAPI spec
|
|
507
|
+
- HTTP and stdio transport modes
|
|
508
|
+
- Automatic tool registration
|
|
509
|
+
|
|
510
|
+
**Usage:**
|
|
511
|
+
|
|
512
|
+
```bash
|
|
513
|
+
# Start MCP server
|
|
514
|
+
python -m naas_abi_core.apps.mcp.mcp_server
|
|
515
|
+
|
|
516
|
+
# Or with HTTP transport
|
|
517
|
+
MCP_TRANSPORT=http python -m naas_abi_core.apps.mcp.mcp_server
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
## Configuration
|
|
521
|
+
|
|
522
|
+
ABI uses YAML configuration files (typically `config.yaml`) to configure:
|
|
523
|
+
|
|
524
|
+
- **Services**: Storage backends, connection details
|
|
525
|
+
- **Modules**: Which modules to load and their configurations
|
|
526
|
+
- **API**: API title, description, CORS settings
|
|
527
|
+
- **Global Config**: AI mode (cloud, local, airgap)
|
|
528
|
+
|
|
529
|
+
**Example Configuration:**
|
|
530
|
+
|
|
531
|
+
```yaml
|
|
532
|
+
api:
|
|
533
|
+
title: "My ABI API"
|
|
534
|
+
description: "API for my AI system"
|
|
535
|
+
cors_origins:
|
|
536
|
+
- "http://localhost:9879"
|
|
537
|
+
|
|
538
|
+
global_config:
|
|
539
|
+
ai_mode: "cloud" # or "local" or "airgap"
|
|
540
|
+
|
|
541
|
+
services:
|
|
542
|
+
triple_store:
|
|
543
|
+
type: "oxigraph"
|
|
544
|
+
url: "http://localhost:7878"
|
|
545
|
+
|
|
546
|
+
vector_store:
|
|
547
|
+
type: "qdrant"
|
|
548
|
+
url: "http://localhost:6333"
|
|
549
|
+
|
|
550
|
+
object_storage:
|
|
551
|
+
type: "minio"
|
|
552
|
+
endpoint: "http://localhost:9000"
|
|
553
|
+
|
|
554
|
+
secret:
|
|
555
|
+
type: "env"
|
|
556
|
+
|
|
557
|
+
modules:
|
|
558
|
+
- module: "naas_abi"
|
|
559
|
+
enabled: true
|
|
560
|
+
- path: "./src/my_module"
|
|
561
|
+
enabled: true
|
|
562
|
+
config:
|
|
563
|
+
api_key: "${MY_API_KEY}"
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
## Key Dependencies
|
|
567
|
+
|
|
568
|
+
- **rdflib**: RDF and ontology management
|
|
569
|
+
- **langgraph**: Agent conversation management
|
|
570
|
+
- **langgraph-checkpoint-postgres**: Conversation persistence
|
|
571
|
+
- **fastapi**: REST API framework
|
|
572
|
+
- **sparqlwrapper**: SPARQL query execution
|
|
573
|
+
- **pydantic**: Data validation and configuration
|
|
574
|
+
- **loguru**: Logging
|
|
575
|
+
- **langchain-openai**: OpenAI integration
|
|
576
|
+
|
|
577
|
+
## Architecture Patterns
|
|
578
|
+
|
|
579
|
+
### Hexagonal Architecture (Ports & Adapters)
|
|
580
|
+
|
|
581
|
+
All services follow the Hexagonal Architecture pattern:
|
|
582
|
+
|
|
583
|
+
- **Primary Port**: Interface defining service capabilities
|
|
584
|
+
- **Secondary Adapters**: Implementations for different backends
|
|
585
|
+
- **Benefits**: Easy swapping of implementations, testability, system-agnostic design
|
|
586
|
+
|
|
587
|
+
### Module System
|
|
588
|
+
|
|
589
|
+
- **Dependency Resolution**: Automatic dependency resolution and ordering
|
|
590
|
+
- **Lazy Loading**: Services loaded only when needed by modules
|
|
591
|
+
- **Lifecycle Hooks**: `on_load()` and `on_initialized()` for setup
|
|
592
|
+
- **Isolation**: Modules can be developed and tested independently
|
|
593
|
+
|
|
594
|
+
### Event-Driven Pipelines
|
|
595
|
+
|
|
596
|
+
Pipelines can be triggered by:
|
|
597
|
+
- Manual execution via API or code
|
|
598
|
+
- Ontology events (triple insertions/updates)
|
|
599
|
+
- Scheduled jobs
|
|
600
|
+
- Workflow triggers
|
|
601
|
+
|
|
602
|
+
## Development
|
|
603
|
+
|
|
604
|
+
### Running Tests
|
|
605
|
+
|
|
606
|
+
```bash
|
|
607
|
+
pytest
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
### Type Checking
|
|
611
|
+
|
|
612
|
+
```bash
|
|
613
|
+
mypy naas_abi_core
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
### Building
|
|
617
|
+
|
|
618
|
+
```bash
|
|
619
|
+
uv build
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
## See Also
|
|
623
|
+
|
|
624
|
+
- [ABI Main README](../../README.md) - Complete ABI framework documentation
|
|
625
|
+
- [naas-abi-cli](../naas-abi-cli/) - CLI tool for ABI projects
|
|
626
|
+
- [naas-abi-marketplace](../naas-abi-marketplace/) - Marketplace modules and agents
|
|
627
|
+
|
|
628
|
+
## License
|
|
629
|
+
|
|
630
|
+
MIT License
|