modaic 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.
Potentially problematic release.
This version of modaic might be problematic. Click here for more details.
- modaic-0.1.0/LICENSE +31 -0
- modaic-0.1.0/PKG-INFO +281 -0
- modaic-0.1.0/README.md +222 -0
- modaic-0.1.0/pyproject.toml +89 -0
- modaic-0.1.0/setup.cfg +4 -0
- modaic-0.1.0/src/modaic/__init__.py +25 -0
- modaic-0.1.0/src/modaic/agents/rag_agent.py +33 -0
- modaic-0.1.0/src/modaic/agents/registry.py +84 -0
- modaic-0.1.0/src/modaic/auto_agent.py +228 -0
- modaic-0.1.0/src/modaic/context/__init__.py +34 -0
- modaic-0.1.0/src/modaic/context/base.py +1064 -0
- modaic-0.1.0/src/modaic/context/dtype_mapping.py +25 -0
- modaic-0.1.0/src/modaic/context/table.py +585 -0
- modaic-0.1.0/src/modaic/context/text.py +94 -0
- modaic-0.1.0/src/modaic/databases/__init__.py +35 -0
- modaic-0.1.0/src/modaic/databases/graph_database.py +269 -0
- modaic-0.1.0/src/modaic/databases/sql_database.py +355 -0
- modaic-0.1.0/src/modaic/databases/vector_database/__init__.py +12 -0
- modaic-0.1.0/src/modaic/databases/vector_database/benchmarks/baseline.py +123 -0
- modaic-0.1.0/src/modaic/databases/vector_database/benchmarks/common.py +48 -0
- modaic-0.1.0/src/modaic/databases/vector_database/benchmarks/fork.py +132 -0
- modaic-0.1.0/src/modaic/databases/vector_database/benchmarks/threaded.py +119 -0
- modaic-0.1.0/src/modaic/databases/vector_database/vector_database.py +722 -0
- modaic-0.1.0/src/modaic/databases/vector_database/vendors/milvus.py +408 -0
- modaic-0.1.0/src/modaic/databases/vector_database/vendors/mongodb.py +0 -0
- modaic-0.1.0/src/modaic/databases/vector_database/vendors/pinecone.py +0 -0
- modaic-0.1.0/src/modaic/databases/vector_database/vendors/qdrant.py +1 -0
- modaic-0.1.0/src/modaic/exceptions.py +38 -0
- modaic-0.1.0/src/modaic/hub.py +305 -0
- modaic-0.1.0/src/modaic/indexing.py +127 -0
- modaic-0.1.0/src/modaic/module_utils.py +341 -0
- modaic-0.1.0/src/modaic/observability.py +275 -0
- modaic-0.1.0/src/modaic/precompiled.py +429 -0
- modaic-0.1.0/src/modaic/query_language.py +321 -0
- modaic-0.1.0/src/modaic/storage/__init__.py +3 -0
- modaic-0.1.0/src/modaic/storage/file_store.py +239 -0
- modaic-0.1.0/src/modaic/storage/pickle_store.py +25 -0
- modaic-0.1.0/src/modaic/types.py +287 -0
- modaic-0.1.0/src/modaic/utils.py +21 -0
- modaic-0.1.0/src/modaic.egg-info/PKG-INFO +281 -0
- modaic-0.1.0/src/modaic.egg-info/SOURCES.txt +47 -0
- modaic-0.1.0/src/modaic.egg-info/dependency_links.txt +1 -0
- modaic-0.1.0/src/modaic.egg-info/requires.txt +18 -0
- modaic-0.1.0/src/modaic.egg-info/top_level.txt +1 -0
- modaic-0.1.0/tests/test_auto_agent.py +175 -0
- modaic-0.1.0/tests/test_observability.py +0 -0
- modaic-0.1.0/tests/test_precompiled.py +415 -0
- modaic-0.1.0/tests/test_query_language.py +156 -0
- modaic-0.1.0/tests/test_types.py +317 -0
modaic-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Modaic Inc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Additional Terms:
|
|
26
|
+
|
|
27
|
+
1. You may not modify this Software in any way that changes the default hub
|
|
28
|
+
endpoint, nor distribute derivative works that route agents or models to
|
|
29
|
+
a hub other than modaic.dev.
|
|
30
|
+
|
|
31
|
+
2. All other rights are granted as per the MIT License.
|
modaic-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: modaic
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: **Mod**ular **A**gent **I**nfrastructure **C**ollective, a python framework for managing and sharing DSPy agents
|
|
5
|
+
Author-email: Tyrin <tytodd@mit.edu>, Farouk <farouk@modaic.dev>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Modaic Inc
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
Additional Terms:
|
|
31
|
+
|
|
32
|
+
1. You may not modify this Software in any way that changes the default hub
|
|
33
|
+
endpoint, nor distribute derivative works that route agents or models to
|
|
34
|
+
a hub other than modaic.dev.
|
|
35
|
+
|
|
36
|
+
2. All other rights are granted as per the MIT License.
|
|
37
|
+
|
|
38
|
+
Requires-Python: >=3.10
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
License-File: LICENSE
|
|
41
|
+
Requires-Dist: aenum>=3.1.16
|
|
42
|
+
Requires-Dist: dspy>=2.6.27
|
|
43
|
+
Requires-Dist: duckdb>=1.3.2
|
|
44
|
+
Requires-Dist: filetype>=1.2.0
|
|
45
|
+
Requires-Dist: gitpython>=3.1.45
|
|
46
|
+
Requires-Dist: immutables>=0.21
|
|
47
|
+
Requires-Dist: langchain-community>=0.3.29
|
|
48
|
+
Requires-Dist: langchain-core>=0.3.72
|
|
49
|
+
Requires-Dist: langchain-text-splitters>=0.3.9
|
|
50
|
+
Requires-Dist: more-itertools>=10.8.0
|
|
51
|
+
Requires-Dist: opik>=1.8.42
|
|
52
|
+
Requires-Dist: pillow>=11.3.0
|
|
53
|
+
Requires-Dist: pymilvus>=2.5.14
|
|
54
|
+
Requires-Dist: sqlalchemy>=2.0.42
|
|
55
|
+
Requires-Dist: tomlkit>=0.13.3
|
|
56
|
+
Provides-Extra: pinecone
|
|
57
|
+
Requires-Dist: pinecone>=7.3.0; extra == "pinecone"
|
|
58
|
+
Dynamic: license-file
|
|
59
|
+
|
|
60
|
+
[](https://docs.modaic.dev)
|
|
61
|
+
# Modaic 🐙
|
|
62
|
+
**Mod**ular **A**gent **I**nfrastructure **C**ollective, a Python framework for building AI agents with structured context management, database integration, and retrieval-augmented generation (RAG) capabilities.
|
|
63
|
+
|
|
64
|
+
## Overview
|
|
65
|
+
|
|
66
|
+
Modaic provides a comprehensive toolkit for creating intelligent agents that can work with diverse data sources including tables, documents, and databases. Built on top of DSPy, it offers a way to share and manage declarative agent architectures with integrated vector, SQL, and graph database support.
|
|
67
|
+
|
|
68
|
+
## Key Features
|
|
69
|
+
|
|
70
|
+
- **Hub Support**: Load and share precompiled agents from Modaic Hub
|
|
71
|
+
- **Context Management**: Structured handling of molecular and atomic context types
|
|
72
|
+
- **Database Integration**: Support for Vector (Milvus, Pinecone, Qdrant), SQL (SQLite, MySQL, PostgreSQL), and Graph (Memgraph, Neo4j)
|
|
73
|
+
- **Agent Framework**: Precompiled and auto-loading agent architectures
|
|
74
|
+
- **Table Processing**: Advanced Excel/CSV processing with SQL querying capabilities
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
## Installation
|
|
78
|
+
|
|
79
|
+
### Using uv (recommended)
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
uv add modaic
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Optional (for hub operations):
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
export MODAIC_TOKEN="<your-token>"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Using pip
|
|
92
|
+
Please note that you will not be able to push agents to the Modaic Hub with pip.
|
|
93
|
+
```bash
|
|
94
|
+
pip install modaic
|
|
95
|
+
```
|
|
96
|
+
## Quick Start
|
|
97
|
+
|
|
98
|
+
### Creating a Simple Agent
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from modaic import PrecompiledAgent, PrecompiledConfig
|
|
102
|
+
|
|
103
|
+
class WeatherConfig(PrecompiledConfig):
|
|
104
|
+
weather: str = "sunny"
|
|
105
|
+
|
|
106
|
+
class WeatherAgent(PrecompiledAgent):
|
|
107
|
+
config: WeatherConfig
|
|
108
|
+
|
|
109
|
+
def __init__(self, config: WeatherConfig, **kwargs):
|
|
110
|
+
super().__init__(config, **kwargs)
|
|
111
|
+
|
|
112
|
+
def forward(self, query: str) -> str:
|
|
113
|
+
return f"The weather in {query} is {self.config.weather}."
|
|
114
|
+
|
|
115
|
+
agent = WeatherAgent(WeatherConfig())
|
|
116
|
+
print(agent(query="Tokyo"))
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Save and load locally:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
agent.save_precompiled("./my-weather")
|
|
123
|
+
|
|
124
|
+
from modaic import AutoAgent, AutoConfig
|
|
125
|
+
|
|
126
|
+
cfg = AutoConfig.from_precompiled("./my-weather", local=True)
|
|
127
|
+
loaded = AutoAgent.from_precompiled("./my-weather", local=True)
|
|
128
|
+
print(loaded(query="Kyoto"))
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Working with Tables
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from pathlib import Path
|
|
135
|
+
from modaic.context import Table, TableFile
|
|
136
|
+
import pandas as pd
|
|
137
|
+
|
|
138
|
+
# Load from Excel/CSV
|
|
139
|
+
excel = TableFile.from_file(
|
|
140
|
+
file_ref="employees.xlsx",
|
|
141
|
+
file=Path("employees.xlsx"),
|
|
142
|
+
file_type="xlsx",
|
|
143
|
+
)
|
|
144
|
+
csv = TableFile.from_file(
|
|
145
|
+
file_ref="data.csv",
|
|
146
|
+
file=Path("data.csv"),
|
|
147
|
+
file_type="csv",
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
# Create from DataFrame
|
|
151
|
+
df = pd.DataFrame({"col1": [1, 2, 3], "col2": [4, 5, 6]})
|
|
152
|
+
table = Table(df=df, name="my_table")
|
|
153
|
+
|
|
154
|
+
# Query with SQL (refer to in-memory table as `this`)
|
|
155
|
+
result = table.query("SELECT * FROM this WHERE col1 > 1")
|
|
156
|
+
|
|
157
|
+
# Convert to markdown
|
|
158
|
+
markdown = table.markdown()
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Database Integration
|
|
162
|
+
|
|
163
|
+
#### SQL Database
|
|
164
|
+
```python
|
|
165
|
+
from modaic.databases import SQLDatabase, SQLiteBackend
|
|
166
|
+
|
|
167
|
+
# Configure and connect
|
|
168
|
+
backend = SQLiteBackend(db_path="my_database.db")
|
|
169
|
+
db = SQLDatabase(backend)
|
|
170
|
+
|
|
171
|
+
# Add table
|
|
172
|
+
db.add_table(table)
|
|
173
|
+
|
|
174
|
+
# Query
|
|
175
|
+
rows = db.fetchall("SELECT * FROM my_table")
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
#### Vector Database
|
|
179
|
+
#### Graph Database
|
|
180
|
+
```python
|
|
181
|
+
from modaic.context import Context, Relation
|
|
182
|
+
from modaic.databases import GraphDatabase, MemgraphConfig, Neo4jConfig
|
|
183
|
+
|
|
184
|
+
# Configure backend (choose one)
|
|
185
|
+
mg = GraphDatabase(MemgraphConfig())
|
|
186
|
+
# or
|
|
187
|
+
neo = GraphDatabase(Neo4jConfig())
|
|
188
|
+
|
|
189
|
+
# Define nodes
|
|
190
|
+
class Person(Context):
|
|
191
|
+
name: str
|
|
192
|
+
age: int
|
|
193
|
+
|
|
194
|
+
class KNOWS(Relation):
|
|
195
|
+
since: int
|
|
196
|
+
|
|
197
|
+
alice = Person(name="Alice", age=30)
|
|
198
|
+
bob = Person(name="Bob", age=28)
|
|
199
|
+
|
|
200
|
+
# Save nodes
|
|
201
|
+
alice.save(mg)
|
|
202
|
+
bob.save(mg)
|
|
203
|
+
|
|
204
|
+
# Create relationship (Alice)-[KNOWS]->(Bob)
|
|
205
|
+
rel = (alice >> KNOWS(since=2020) >> bob)
|
|
206
|
+
rel.save(mg)
|
|
207
|
+
|
|
208
|
+
# Query
|
|
209
|
+
rows = mg.execute_and_fetch("MATCH (a:Person)-[r:KNOWS]->(b:Person) RETURN a, r, b LIMIT 5")
|
|
210
|
+
```
|
|
211
|
+
```python
|
|
212
|
+
from modaic import Embedder
|
|
213
|
+
from modaic.context import Text
|
|
214
|
+
from modaic.databases import VectorDatabase, MilvusBackend
|
|
215
|
+
|
|
216
|
+
# Setup embedder and backend
|
|
217
|
+
embedder = Embedder("openai/text-embedding-3-small")
|
|
218
|
+
backend = MilvusBackend.from_local("vector.db") # milvus lite
|
|
219
|
+
|
|
220
|
+
# Initialize database
|
|
221
|
+
vdb = VectorDatabase(backend=backend, embedder=embedder, payload_class=Text)
|
|
222
|
+
|
|
223
|
+
# Create collection and add records
|
|
224
|
+
vdb.create_collection("my_collection", payload_class=Text)
|
|
225
|
+
vdb.add_records("my_collection", [Text(text="hello world"), Text(text="modaic makes sharing agents easy")])
|
|
226
|
+
|
|
227
|
+
# Search
|
|
228
|
+
results = vdb.search("my_collection", query="hello", k=3)
|
|
229
|
+
top_hit_text = results[0][0].context.text
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Architecture
|
|
233
|
+
### Agent Types
|
|
234
|
+
|
|
235
|
+
1. **PrecompiledAgent**: Statically defined agents with explicit configuration
|
|
236
|
+
2. **AutoAgent**: Dynamically loaded agents from Modaic Hub or local repositories
|
|
237
|
+
|
|
238
|
+
### Database Support
|
|
239
|
+
|
|
240
|
+
| Database Type | Providers | Use Case |
|
|
241
|
+
|---------------|-----------|----------|
|
|
242
|
+
| **Vector** | Milvus | Semantic search, RAG |
|
|
243
|
+
| **SQL** | SQLite, MySQL, PostgreSQL | Structured queries, table storage |
|
|
244
|
+
|
|
245
|
+
## Examples
|
|
246
|
+
|
|
247
|
+
### TableRAG Example
|
|
248
|
+
|
|
249
|
+
The TableRAG example demonstrates a complete RAG pipeline for table-based question answering:
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
from modaic.precompiled_agent import PrecompiledConfig, PrecompiledAgent
|
|
253
|
+
from modaic.context import Table
|
|
254
|
+
from modaic.databases import VectorDatabase, SQLDatabase
|
|
255
|
+
from modaic.types import Indexer
|
|
256
|
+
|
|
257
|
+
class TableRAGConfig(PrecompiledConfig):
|
|
258
|
+
agent_type = "TableRAGAgent"
|
|
259
|
+
k_recall: int = 50
|
|
260
|
+
k_rerank: int = 5
|
|
261
|
+
|
|
262
|
+
class TableRAGAgent(PrecompiledAgent):
|
|
263
|
+
config: TableRAGConfig # ! Important: config must be annotated with the config class
|
|
264
|
+
|
|
265
|
+
def __init__(self, config: TableRAGConfig, indexer: Indexer, **kwargs):
|
|
266
|
+
super().__init__(config, **kwargs)
|
|
267
|
+
self.indexer = indexer
|
|
268
|
+
# Initialize DSPy modules for reasoning
|
|
269
|
+
|
|
270
|
+
def forward(self, user_query: str) -> str:
|
|
271
|
+
# Retrieve relevant tables
|
|
272
|
+
# Generate SQL queries
|
|
273
|
+
# Combine results and provide answer
|
|
274
|
+
pass
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Support
|
|
278
|
+
|
|
279
|
+
For issues and questions:
|
|
280
|
+
- GitHub Issues: `https://github.com/modaic-ai/modaic/issues`
|
|
281
|
+
- Docs: `https://docs.modaic.dev`
|
modaic-0.1.0/README.md
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
[](https://docs.modaic.dev)
|
|
2
|
+
# Modaic 🐙
|
|
3
|
+
**Mod**ular **A**gent **I**nfrastructure **C**ollective, a Python framework for building AI agents with structured context management, database integration, and retrieval-augmented generation (RAG) capabilities.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Modaic provides a comprehensive toolkit for creating intelligent agents that can work with diverse data sources including tables, documents, and databases. Built on top of DSPy, it offers a way to share and manage declarative agent architectures with integrated vector, SQL, and graph database support.
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
- **Hub Support**: Load and share precompiled agents from Modaic Hub
|
|
12
|
+
- **Context Management**: Structured handling of molecular and atomic context types
|
|
13
|
+
- **Database Integration**: Support for Vector (Milvus, Pinecone, Qdrant), SQL (SQLite, MySQL, PostgreSQL), and Graph (Memgraph, Neo4j)
|
|
14
|
+
- **Agent Framework**: Precompiled and auto-loading agent architectures
|
|
15
|
+
- **Table Processing**: Advanced Excel/CSV processing with SQL querying capabilities
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
### Using uv (recommended)
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
uv add modaic
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Optional (for hub operations):
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
export MODAIC_TOKEN="<your-token>"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Using pip
|
|
33
|
+
Please note that you will not be able to push agents to the Modaic Hub with pip.
|
|
34
|
+
```bash
|
|
35
|
+
pip install modaic
|
|
36
|
+
```
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
### Creating a Simple Agent
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from modaic import PrecompiledAgent, PrecompiledConfig
|
|
43
|
+
|
|
44
|
+
class WeatherConfig(PrecompiledConfig):
|
|
45
|
+
weather: str = "sunny"
|
|
46
|
+
|
|
47
|
+
class WeatherAgent(PrecompiledAgent):
|
|
48
|
+
config: WeatherConfig
|
|
49
|
+
|
|
50
|
+
def __init__(self, config: WeatherConfig, **kwargs):
|
|
51
|
+
super().__init__(config, **kwargs)
|
|
52
|
+
|
|
53
|
+
def forward(self, query: str) -> str:
|
|
54
|
+
return f"The weather in {query} is {self.config.weather}."
|
|
55
|
+
|
|
56
|
+
agent = WeatherAgent(WeatherConfig())
|
|
57
|
+
print(agent(query="Tokyo"))
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Save and load locally:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
agent.save_precompiled("./my-weather")
|
|
64
|
+
|
|
65
|
+
from modaic import AutoAgent, AutoConfig
|
|
66
|
+
|
|
67
|
+
cfg = AutoConfig.from_precompiled("./my-weather", local=True)
|
|
68
|
+
loaded = AutoAgent.from_precompiled("./my-weather", local=True)
|
|
69
|
+
print(loaded(query="Kyoto"))
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Working with Tables
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from pathlib import Path
|
|
76
|
+
from modaic.context import Table, TableFile
|
|
77
|
+
import pandas as pd
|
|
78
|
+
|
|
79
|
+
# Load from Excel/CSV
|
|
80
|
+
excel = TableFile.from_file(
|
|
81
|
+
file_ref="employees.xlsx",
|
|
82
|
+
file=Path("employees.xlsx"),
|
|
83
|
+
file_type="xlsx",
|
|
84
|
+
)
|
|
85
|
+
csv = TableFile.from_file(
|
|
86
|
+
file_ref="data.csv",
|
|
87
|
+
file=Path("data.csv"),
|
|
88
|
+
file_type="csv",
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# Create from DataFrame
|
|
92
|
+
df = pd.DataFrame({"col1": [1, 2, 3], "col2": [4, 5, 6]})
|
|
93
|
+
table = Table(df=df, name="my_table")
|
|
94
|
+
|
|
95
|
+
# Query with SQL (refer to in-memory table as `this`)
|
|
96
|
+
result = table.query("SELECT * FROM this WHERE col1 > 1")
|
|
97
|
+
|
|
98
|
+
# Convert to markdown
|
|
99
|
+
markdown = table.markdown()
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Database Integration
|
|
103
|
+
|
|
104
|
+
#### SQL Database
|
|
105
|
+
```python
|
|
106
|
+
from modaic.databases import SQLDatabase, SQLiteBackend
|
|
107
|
+
|
|
108
|
+
# Configure and connect
|
|
109
|
+
backend = SQLiteBackend(db_path="my_database.db")
|
|
110
|
+
db = SQLDatabase(backend)
|
|
111
|
+
|
|
112
|
+
# Add table
|
|
113
|
+
db.add_table(table)
|
|
114
|
+
|
|
115
|
+
# Query
|
|
116
|
+
rows = db.fetchall("SELECT * FROM my_table")
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### Vector Database
|
|
120
|
+
#### Graph Database
|
|
121
|
+
```python
|
|
122
|
+
from modaic.context import Context, Relation
|
|
123
|
+
from modaic.databases import GraphDatabase, MemgraphConfig, Neo4jConfig
|
|
124
|
+
|
|
125
|
+
# Configure backend (choose one)
|
|
126
|
+
mg = GraphDatabase(MemgraphConfig())
|
|
127
|
+
# or
|
|
128
|
+
neo = GraphDatabase(Neo4jConfig())
|
|
129
|
+
|
|
130
|
+
# Define nodes
|
|
131
|
+
class Person(Context):
|
|
132
|
+
name: str
|
|
133
|
+
age: int
|
|
134
|
+
|
|
135
|
+
class KNOWS(Relation):
|
|
136
|
+
since: int
|
|
137
|
+
|
|
138
|
+
alice = Person(name="Alice", age=30)
|
|
139
|
+
bob = Person(name="Bob", age=28)
|
|
140
|
+
|
|
141
|
+
# Save nodes
|
|
142
|
+
alice.save(mg)
|
|
143
|
+
bob.save(mg)
|
|
144
|
+
|
|
145
|
+
# Create relationship (Alice)-[KNOWS]->(Bob)
|
|
146
|
+
rel = (alice >> KNOWS(since=2020) >> bob)
|
|
147
|
+
rel.save(mg)
|
|
148
|
+
|
|
149
|
+
# Query
|
|
150
|
+
rows = mg.execute_and_fetch("MATCH (a:Person)-[r:KNOWS]->(b:Person) RETURN a, r, b LIMIT 5")
|
|
151
|
+
```
|
|
152
|
+
```python
|
|
153
|
+
from modaic import Embedder
|
|
154
|
+
from modaic.context import Text
|
|
155
|
+
from modaic.databases import VectorDatabase, MilvusBackend
|
|
156
|
+
|
|
157
|
+
# Setup embedder and backend
|
|
158
|
+
embedder = Embedder("openai/text-embedding-3-small")
|
|
159
|
+
backend = MilvusBackend.from_local("vector.db") # milvus lite
|
|
160
|
+
|
|
161
|
+
# Initialize database
|
|
162
|
+
vdb = VectorDatabase(backend=backend, embedder=embedder, payload_class=Text)
|
|
163
|
+
|
|
164
|
+
# Create collection and add records
|
|
165
|
+
vdb.create_collection("my_collection", payload_class=Text)
|
|
166
|
+
vdb.add_records("my_collection", [Text(text="hello world"), Text(text="modaic makes sharing agents easy")])
|
|
167
|
+
|
|
168
|
+
# Search
|
|
169
|
+
results = vdb.search("my_collection", query="hello", k=3)
|
|
170
|
+
top_hit_text = results[0][0].context.text
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Architecture
|
|
174
|
+
### Agent Types
|
|
175
|
+
|
|
176
|
+
1. **PrecompiledAgent**: Statically defined agents with explicit configuration
|
|
177
|
+
2. **AutoAgent**: Dynamically loaded agents from Modaic Hub or local repositories
|
|
178
|
+
|
|
179
|
+
### Database Support
|
|
180
|
+
|
|
181
|
+
| Database Type | Providers | Use Case |
|
|
182
|
+
|---------------|-----------|----------|
|
|
183
|
+
| **Vector** | Milvus | Semantic search, RAG |
|
|
184
|
+
| **SQL** | SQLite, MySQL, PostgreSQL | Structured queries, table storage |
|
|
185
|
+
|
|
186
|
+
## Examples
|
|
187
|
+
|
|
188
|
+
### TableRAG Example
|
|
189
|
+
|
|
190
|
+
The TableRAG example demonstrates a complete RAG pipeline for table-based question answering:
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
from modaic.precompiled_agent import PrecompiledConfig, PrecompiledAgent
|
|
194
|
+
from modaic.context import Table
|
|
195
|
+
from modaic.databases import VectorDatabase, SQLDatabase
|
|
196
|
+
from modaic.types import Indexer
|
|
197
|
+
|
|
198
|
+
class TableRAGConfig(PrecompiledConfig):
|
|
199
|
+
agent_type = "TableRAGAgent"
|
|
200
|
+
k_recall: int = 50
|
|
201
|
+
k_rerank: int = 5
|
|
202
|
+
|
|
203
|
+
class TableRAGAgent(PrecompiledAgent):
|
|
204
|
+
config: TableRAGConfig # ! Important: config must be annotated with the config class
|
|
205
|
+
|
|
206
|
+
def __init__(self, config: TableRAGConfig, indexer: Indexer, **kwargs):
|
|
207
|
+
super().__init__(config, **kwargs)
|
|
208
|
+
self.indexer = indexer
|
|
209
|
+
# Initialize DSPy modules for reasoning
|
|
210
|
+
|
|
211
|
+
def forward(self, user_query: str) -> str:
|
|
212
|
+
# Retrieve relevant tables
|
|
213
|
+
# Generate SQL queries
|
|
214
|
+
# Combine results and provide answer
|
|
215
|
+
pass
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Support
|
|
219
|
+
|
|
220
|
+
For issues and questions:
|
|
221
|
+
- GitHub Issues: `https://github.com/modaic-ai/modaic/issues`
|
|
222
|
+
- Docs: `https://docs.modaic.dev`
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "modaic"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "**Mod**ular **A**gent **I**nfrastructure **C**ollective, a python framework for managing and sharing DSPy agents"
|
|
5
|
+
authors = [{ name = "Tyrin", email = "tytodd@mit.edu" }, {name = "Farouk", email = "farouk@modaic.dev"}]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
license = {file = "LICENSE"}
|
|
8
|
+
requires-python = ">=3.10"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"aenum>=3.1.16",
|
|
11
|
+
"dspy>=2.6.27",
|
|
12
|
+
"duckdb>=1.3.2",
|
|
13
|
+
"filetype>=1.2.0",
|
|
14
|
+
"gitpython>=3.1.45",
|
|
15
|
+
"immutables>=0.21",
|
|
16
|
+
"langchain-community>=0.3.29",
|
|
17
|
+
"langchain-core>=0.3.72",
|
|
18
|
+
"langchain-text-splitters>=0.3.9",
|
|
19
|
+
"more-itertools>=10.8.0",
|
|
20
|
+
"opik>=1.8.42",
|
|
21
|
+
"pillow>=11.3.0",
|
|
22
|
+
"pymilvus>=2.5.14",
|
|
23
|
+
"sqlalchemy>=2.0.42",
|
|
24
|
+
"tomlkit>=0.13.3",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[dependency-groups]
|
|
28
|
+
dev = [
|
|
29
|
+
"colorama>=0.4.6",
|
|
30
|
+
"ipykernel>=6.30.0",
|
|
31
|
+
"mkdocs-material>=9.6.16",
|
|
32
|
+
"mkdocstrings[python]>=0.30.0",
|
|
33
|
+
"pydoc-markdown>=4.8.2",
|
|
34
|
+
"pdoc>=15.0.4",
|
|
35
|
+
"pytest>=8.4.1",
|
|
36
|
+
"ruff>=0.12.7",
|
|
37
|
+
"opik>=1.8.42",
|
|
38
|
+
"matplotlib>=3.10.6",
|
|
39
|
+
]
|
|
40
|
+
examples = [
|
|
41
|
+
"langchain-text-splitters>=0.3.9",
|
|
42
|
+
"pinecone>=7.3.0",
|
|
43
|
+
]
|
|
44
|
+
graph = [
|
|
45
|
+
"gqlalchemy>=1.8.0",
|
|
46
|
+
"pymgclient>=1.5.1",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[project.optional-dependencies]
|
|
50
|
+
pinecone = ["pinecone>=7.3.0"]
|
|
51
|
+
|
|
52
|
+
[tool.setuptools]
|
|
53
|
+
package-dir = {"" = "src"}
|
|
54
|
+
|
|
55
|
+
[tool.setuptools.packages.find]
|
|
56
|
+
where = ["src"]
|
|
57
|
+
exclude = [
|
|
58
|
+
"mintlify*",
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
[tool.ruff]
|
|
62
|
+
line-length = 120
|
|
63
|
+
fix = true
|
|
64
|
+
exclude = ["*scratchpad*.py"]
|
|
65
|
+
|
|
66
|
+
[tool.ruff.lint]
|
|
67
|
+
select = ["E", "F", "I", "B", "T20", "ERA", "ANN", "N"]
|
|
68
|
+
unfixable = [
|
|
69
|
+
"F401",
|
|
70
|
+
"F841",
|
|
71
|
+
]
|
|
72
|
+
ignore = ["ANN202","ANN002", "ANN003", "ANN204", "ANN401"]
|
|
73
|
+
extend-ignore = ["E501"]
|
|
74
|
+
|
|
75
|
+
#[tool.ruff.lint.flake8-todos]
|
|
76
|
+
#task-tags = ["TODO", "FIXME", "XXX", "BUG", "HACK", "NOTE", "CAVEAT", "DOCME"]
|
|
77
|
+
|
|
78
|
+
[tool.ruff.lint.flake8-annotations]
|
|
79
|
+
suppress-none-returning = true
|
|
80
|
+
|
|
81
|
+
[tool.uv.workspace]
|
|
82
|
+
members = [
|
|
83
|
+
"tests/artifacts/test_repos/simple_repo",
|
|
84
|
+
".",
|
|
85
|
+
"tests/artifacts/test_repos/simple_repo_with_compile",
|
|
86
|
+
"tests/artifacts/test_repos/nested_repo",
|
|
87
|
+
"tests/artifacts/test_repos/nested_repo_2",
|
|
88
|
+
"tests/artifacts/test_repos/multi_module_repo",
|
|
89
|
+
]
|
modaic-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from .auto_agent import AutoAgent, AutoConfig, AutoRetriever
|
|
2
|
+
from .indexing import Embedder
|
|
3
|
+
from .observability import Trackable, configure, track, track_modaic_obj
|
|
4
|
+
from .precompiled import Indexer, PrecompiledAgent, PrecompiledConfig, Retriever
|
|
5
|
+
from .query_language import AND, OR, Condition, Prop, Value, parse_modaic_filter
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"AutoAgent",
|
|
9
|
+
"AutoConfig",
|
|
10
|
+
"AutoRetriever",
|
|
11
|
+
"Retriever",
|
|
12
|
+
"Indexer",
|
|
13
|
+
"PrecompiledAgent",
|
|
14
|
+
"PrecompiledConfig",
|
|
15
|
+
"Embedder",
|
|
16
|
+
"configure",
|
|
17
|
+
"track",
|
|
18
|
+
"Trackable",
|
|
19
|
+
"track_modaic_obj",
|
|
20
|
+
"AND",
|
|
21
|
+
"OR",
|
|
22
|
+
"Prop",
|
|
23
|
+
"Value",
|
|
24
|
+
"parse_modaic_filter",
|
|
25
|
+
]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from modaic import Indexer, PrecompiledAgent, PrecompiledConfig
|
|
4
|
+
from modaic.context import Context
|
|
5
|
+
|
|
6
|
+
from .registry import builtin_agent, builtin_config, builtin_indexer
|
|
7
|
+
|
|
8
|
+
agent_name = "basic-rag"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@builtin_config(agent_name)
|
|
12
|
+
class RAGAgentConfig(PrecompiledConfig):
|
|
13
|
+
def __init__(self):
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
def forward(self, query: str) -> str:
|
|
17
|
+
return "hello"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@builtin_indexer(agent_name)
|
|
21
|
+
class RAGIndexer(Indexer):
|
|
22
|
+
def ingest(self, config: RAGAgentConfig, contexts: List[Context]):
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@builtin_agent(agent_name)
|
|
27
|
+
class RAGAgent(PrecompiledAgent):
|
|
28
|
+
def __init__(self, config: RAGAgentConfig, indexer: RAGIndexer):
|
|
29
|
+
super().__init__(config)
|
|
30
|
+
self.indexer = indexer
|
|
31
|
+
|
|
32
|
+
def forward(self, query: str) -> str:
|
|
33
|
+
return "hello"
|