memra 0.2.2__py3-none-any.whl → 0.2.3__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.
memra/__init__.py CHANGED
@@ -6,18 +6,22 @@ Think of it as "Kubernetes for business logic" where agents are the pods and
6
6
  departments are the deployments.
7
7
  """
8
8
 
9
- __version__ = "0.2.2"
9
+ __version__ = "0.2.3"
10
10
 
11
11
  # Core imports
12
- from .models import Agent, Department, Tool
12
+ from .models import Agent, Department, Tool, LLM
13
13
  from .execution import ExecutionEngine
14
+ from .discovery_client import check_api_health, get_api_status
14
15
 
15
16
  # Make key classes available at package level
16
17
  __all__ = [
17
18
  "Agent",
18
19
  "Department",
19
20
  "Tool",
21
+ "LLM",
20
22
  "ExecutionEngine",
23
+ "check_api_health",
24
+ "get_api_status",
21
25
  "__version__"
22
26
  ]
23
27
 
memra/execution.py CHANGED
@@ -216,6 +216,21 @@ class ExecutionEngine:
216
216
  # Use local registry for MCP and other local tools
217
217
  print(f"🏠 {agent.role}: Using local registry for {tool_name}")
218
218
  config_to_pass = tool_spec.get("config") if isinstance(tool_spec, dict) else tool_spec.config
219
+
220
+ # For MCP tools, merge department context MCP configuration
221
+ if hosted_by == "mcp":
222
+ mcp_config = {}
223
+ dept_context = context.get("department_context", {})
224
+ if "mcp_bridge_url" in dept_context:
225
+ mcp_config["bridge_url"] = dept_context["mcp_bridge_url"]
226
+ if "mcp_bridge_secret" in dept_context:
227
+ mcp_config["bridge_secret"] = dept_context["mcp_bridge_secret"]
228
+
229
+ # Merge with tool-specific config if it exists
230
+ if config_to_pass:
231
+ mcp_config.update(config_to_pass)
232
+ config_to_pass = mcp_config
233
+
219
234
  print(f"🔧 {agent.role}: Config for {tool_name}: {config_to_pass}")
220
235
  tool_result = self.tool_registry.execute_tool(
221
236
  tool_name,
@@ -325,6 +340,34 @@ class ExecutionEngine:
325
340
  not tool_data.get("_mock", False) # Not mock data
326
341
  )
327
342
 
343
+ elif tool_name == "FileDiscovery":
344
+ # Real work if it actually discovered files in a real directory
345
+ return (
346
+ "files" in tool_data and
347
+ isinstance(tool_data["files"], list) and
348
+ "directory" in tool_data and
349
+ tool_data.get("success", False) == True
350
+ )
351
+
352
+ elif tool_name == "FileCopy":
353
+ # Real work if it actually copied a file
354
+ return (
355
+ "destination_path" in tool_data and
356
+ "source_path" in tool_data and
357
+ tool_data.get("success", False) == True and
358
+ tool_data.get("operation") == "copy_completed"
359
+ )
360
+
361
+ elif tool_name == "TextToSQL":
362
+ # Real work if it actually executed SQL and returned real results
363
+ return (
364
+ "generated_sql" in tool_data and
365
+ "results" in tool_data and
366
+ isinstance(tool_data["results"], list) and
367
+ tool_data.get("success", False) == True and
368
+ not tool_data.get("_mock", False) # Not mock data
369
+ )
370
+
328
371
  # Default to mock work
329
372
  return False
330
373
 
memra/tool_registry.py CHANGED
@@ -24,6 +24,8 @@ class ToolRegistry:
24
24
  ("OCRTool", "Perform OCR on images and documents"),
25
25
  ("InvoiceExtractionWorkflow", "Extract structured data from invoices"),
26
26
  ("FileReader", "Read files from the filesystem"),
27
+ ("FileDiscovery", "Discover and list files in directories"),
28
+ ("FileCopy", "Copy files to standard processing directories"),
27
29
  ]
28
30
 
29
31
  for tool_name, description in server_tools:
@@ -33,6 +35,9 @@ class ToolRegistry:
33
35
  mcp_tools = [
34
36
  ("DataValidator", "Validate data against schemas"),
35
37
  ("PostgresInsert", "Insert data into PostgreSQL database"),
38
+ ("TextToSQL", "Convert natural language questions to SQL queries and execute them"),
39
+ ("SQLExecutor", "Execute SQL queries against PostgreSQL database"),
40
+ ("TextToSQLGenerator", "Generate SQL from natural language questions"),
36
41
  ]
37
42
 
38
43
  for tool_name, description in mcp_tools:
@@ -169,6 +174,155 @@ class ToolRegistry:
169
174
  "_mock": True
170
175
  }
171
176
  }
177
+ elif tool_name == "FileDiscovery":
178
+ # Mock file discovery - in real implementation, would scan directories
179
+ directory = input_data.get("directory", "invoices")
180
+ file_pattern = input_data.get("pattern", "*.pdf")
181
+
182
+ # Simulate finding files in the directory
183
+ mock_files = [
184
+ {
185
+ "filename": "10352259310.PDF",
186
+ "path": f"{directory}/10352259310.PDF",
187
+ "size": "542KB",
188
+ "modified": "2024-05-28",
189
+ "type": "PDF"
190
+ }
191
+ ]
192
+
193
+ return {
194
+ "success": True,
195
+ "data": {
196
+ "directory": directory,
197
+ "pattern": file_pattern,
198
+ "files_found": len(mock_files),
199
+ "files": mock_files,
200
+ "message": f"Found {len(mock_files)} files in {directory}/ directory"
201
+ }
202
+ }
203
+
204
+ elif tool_name == "FileCopy":
205
+ # Mock file copy - in real implementation, would copy files
206
+ source_path = input_data.get("source_path", "")
207
+ destination_dir = input_data.get("destination_dir", "invoices")
208
+
209
+ if not source_path:
210
+ return {
211
+ "success": False,
212
+ "error": "Source path is required"
213
+ }
214
+
215
+ # Extract filename from path
216
+ import os
217
+ filename = os.path.basename(source_path)
218
+ destination_path = f"{destination_dir}/{filename}"
219
+
220
+ return {
221
+ "success": True,
222
+ "data": {
223
+ "source_path": source_path,
224
+ "destination_path": destination_path,
225
+ "message": f"File copied from {source_path} to {destination_path}",
226
+ "file_size": "245KB",
227
+ "operation": "copy_completed"
228
+ }
229
+ }
230
+ elif tool_name == "TextToSQL":
231
+ # Mock text-to-SQL - in real implementation, would use LLM to generate SQL
232
+ question = input_data.get("question", "")
233
+ schema = input_data.get("schema", {})
234
+
235
+ if not question:
236
+ return {
237
+ "success": False,
238
+ "error": "Question is required for text-to-SQL conversion"
239
+ }
240
+
241
+ # Simulate SQL generation and execution
242
+ mock_sql = "SELECT vendor_name, invoice_number, total_amount FROM invoices WHERE vendor_name ILIKE '%air liquide%' ORDER BY invoice_date DESC LIMIT 5;"
243
+ mock_results = [
244
+ {
245
+ "vendor_name": "Air Liquide Canada Inc.",
246
+ "invoice_number": "INV-12345",
247
+ "total_amount": 1234.56
248
+ },
249
+ {
250
+ "vendor_name": "Air Liquide Canada Inc.",
251
+ "invoice_number": "INV-67890",
252
+ "total_amount": 2345.67
253
+ }
254
+ ]
255
+
256
+ return {
257
+ "success": True,
258
+ "data": {
259
+ "question": question,
260
+ "generated_sql": mock_sql,
261
+ "results": mock_results,
262
+ "row_count": len(mock_results),
263
+ "message": f"Found {len(mock_results)} results for: {question}",
264
+ "_mock": True
265
+ }
266
+ }
267
+ elif tool_name == "SQLExecutor":
268
+ # Mock SQL execution
269
+ sql_query = input_data.get("sql_query", "")
270
+
271
+ if not sql_query:
272
+ return {
273
+ "success": False,
274
+ "error": "SQL query is required"
275
+ }
276
+
277
+ # Mock results based on query type
278
+ if sql_query.upper().startswith("SELECT"):
279
+ mock_results = [
280
+ {"vendor_name": "Air Liquide Canada Inc.", "invoice_number": "INV-12345", "total_amount": 1234.56},
281
+ {"vendor_name": "Air Liquide Canada Inc.", "invoice_number": "INV-67890", "total_amount": 2345.67}
282
+ ]
283
+ return {
284
+ "success": True,
285
+ "data": {
286
+ "query": sql_query,
287
+ "results": mock_results,
288
+ "row_count": len(mock_results),
289
+ "columns": ["vendor_name", "invoice_number", "total_amount"],
290
+ "_mock": True
291
+ }
292
+ }
293
+ else:
294
+ return {
295
+ "success": True,
296
+ "data": {
297
+ "query": sql_query,
298
+ "affected_rows": 1,
299
+ "message": "Query executed successfully",
300
+ "_mock": True
301
+ }
302
+ }
303
+ elif tool_name == "TextToSQLGenerator":
304
+ # Mock SQL generation
305
+ question = input_data.get("question", "")
306
+
307
+ if not question:
308
+ return {
309
+ "success": False,
310
+ "error": "Question is required for SQL generation"
311
+ }
312
+
313
+ # Generate mock SQL based on question
314
+ mock_sql = "SELECT * FROM invoices WHERE vendor_name ILIKE '%air liquide%'"
315
+
316
+ return {
317
+ "success": True,
318
+ "data": {
319
+ "question": question,
320
+ "generated_sql": mock_sql,
321
+ "explanation": "Generated SQL query based on natural language question",
322
+ "confidence": "medium",
323
+ "_mock": True
324
+ }
325
+ }
172
326
  else:
173
327
  return {
174
328
  "success": False,
@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.4
2
+ Name: memra
3
+ Version: 0.2.3
4
+ Summary: Declarative framework for enterprise workflows with MCP integration - Client SDK
5
+ Home-page: https://github.com/memra/memra-sdk
6
+ Author: Memra
7
+ Author-email: Memra <support@memra.com>
8
+ License: MIT
9
+ Project-URL: Homepage, https://memra.co
10
+ Project-URL: Repository, https://github.com/memra-platform/memra-sdk
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Requires-Python: >=3.8
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: pydantic>=1.8.0
23
+ Requires-Dist: httpx>=0.24.0
24
+ Requires-Dist: typing-extensions>=4.0.0
25
+ Requires-Dist: aiohttp>=3.8.0
26
+ Requires-Dist: aiohttp-cors>=0.7.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=6.0; extra == "dev"
29
+ Requires-Dist: pytest-asyncio; extra == "dev"
30
+ Requires-Dist: black; extra == "dev"
31
+ Requires-Dist: flake8; extra == "dev"
32
+ Provides-Extra: mcp
33
+ Requires-Dist: psycopg2-binary>=2.9.0; extra == "mcp"
34
+ Dynamic: author
35
+ Dynamic: home-page
36
+ Dynamic: requires-python
37
+
38
+ # Memra SDK
39
+
40
+ The core Memra framework for building AI-powered business workflows.
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ pip install memra
46
+ ```
47
+
48
+ ## Quick Start
49
+
50
+ ```python
51
+ from memra import Agent, Department, LLM, ExecutionEngine
52
+
53
+ # Define an agent
54
+ agent = Agent(
55
+ role="Data Analyst",
56
+ job="Analyze customer data",
57
+ llm=LLM(model="llama-3.2-11b-vision-preview"),
58
+ sops=["Load data", "Perform analysis", "Generate report"],
59
+ output_key="analysis_result"
60
+ )
61
+
62
+ # Create a department
63
+ department = Department(
64
+ name="Analytics",
65
+ mission="Provide data insights",
66
+ agents=[agent],
67
+ workflow_order=["Data Analyst"]
68
+ )
69
+
70
+ # Execute the workflow
71
+ engine = ExecutionEngine()
72
+ result = engine.execute_department(department, {"data": "customer_data.csv"})
73
+ ```
74
+
75
+ ## Core Components
76
+
77
+ ### Agent
78
+ An AI worker that performs specific tasks using LLMs and tools.
79
+
80
+ ### Department
81
+ A team of agents working together to accomplish a mission.
82
+
83
+ ### ExecutionEngine
84
+ Orchestrates the execution of departments and their workflows.
85
+
86
+ ### LLM
87
+ Configuration for language models used by agents.
88
+
89
+ ## Examples
90
+
91
+ See the `examples/` directory for basic usage examples:
92
+ - `simple_text_to_sql.py` - Basic text-to-SQL conversion
93
+ - `ask_questions.py` - Simple question answering
94
+
95
+ ## Documentation
96
+
97
+ For detailed documentation, visit [docs.memra.co](https://docs.memra.co)
98
+
99
+ ## License
100
+
101
+ MIT License - see LICENSE file for details.
@@ -0,0 +1,12 @@
1
+ memra/__init__.py,sha256=zVO29fnEDclBI9x9SFVzF9uJYAKhPDTNrMFMWuw6JC8,787
2
+ memra/discovery.py,sha256=yJIQnrDQu1nyzKykCIuzG_5SW5dIXHCEBLLKRWacIoY,480
3
+ memra/discovery_client.py,sha256=AbnKn6qhyrf7vmOvknEeDzH4tiGHsqPHtDaein_qaW0,1271
4
+ memra/execution.py,sha256=P7tAur0SEMtX6uLlfxTfCZBgMLIRj6Wl3dsv2EA9fHc,23443
5
+ memra/models.py,sha256=sXMPRnMB_mUVtJdBFyd0ElCf_uh1yqx7iLssIYNm0vI,3333
6
+ memra/tool_registry.py,sha256=P2TafpiqV19yzi0jVrQQrXFGBpQkbmePbRfEW_ai24M,14700
7
+ memra/tool_registry_client.py,sha256=uzMQ4COvRams9vuPLcqcdljUpDlAYU_tyFxrRhrA0Lc,4009
8
+ memra-0.2.3.dist-info/METADATA,sha256=gr4yyJc9wX49JFvxLdbQCP7HFdoEC_NqSH06uxvnq08,2737
9
+ memra-0.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ memra-0.2.3.dist-info/entry_points.txt,sha256=LBVjwWoxWJRzNLgeByPn6xUvWFIRnqnemvAZgIoSt08,41
11
+ memra-0.2.3.dist-info/top_level.txt,sha256=pXWcTRS1zctdiSUivW4iyKpJ4tcfIu-1BW_fpbal3OY,6
12
+ memra-0.2.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.7.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
File without changes
@@ -1,148 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: memra
3
- Version: 0.2.2
4
- Summary: Declarative framework for enterprise workflows with MCP integration - Client SDK
5
- Home-page: https://github.com/memra/memra-sdk
6
- Author: Memra
7
- Author-email: Memra <support@memra.com>
8
- License: MIT
9
- Project-URL: Homepage, https://memra.co
10
- Project-URL: Repository, https://github.com/memra-platform/memra-sdk
11
- Classifier: Development Status :: 3 - Alpha
12
- Classifier: Intended Audience :: Developers
13
- Classifier: License :: OSI Approved :: MIT License
14
- Classifier: Operating System :: OS Independent
15
- Classifier: Programming Language :: Python :: 3
16
- Classifier: Programming Language :: Python :: 3.8
17
- Classifier: Programming Language :: Python :: 3.9
18
- Classifier: Programming Language :: Python :: 3.10
19
- Classifier: Programming Language :: Python :: 3.11
20
- Requires-Python: >=3.8
21
- Description-Content-Type: text/markdown
22
- License-File: LICENSE
23
- Requires-Dist: pydantic>=1.8.0
24
- Requires-Dist: httpx>=0.24.0
25
- Requires-Dist: typing-extensions>=4.0.0
26
- Requires-Dist: aiohttp>=3.8.0
27
- Requires-Dist: aiohttp-cors>=0.7.0
28
- Provides-Extra: dev
29
- Requires-Dist: pytest>=6.0; extra == "dev"
30
- Requires-Dist: pytest-asyncio; extra == "dev"
31
- Requires-Dist: black; extra == "dev"
32
- Requires-Dist: flake8; extra == "dev"
33
- Provides-Extra: mcp
34
- Requires-Dist: psycopg2-binary>=2.9.0; extra == "mcp"
35
-
36
- # Memra SDK
37
-
38
- A declarative orchestration framework for AI-powered business workflows. Think of it as "Kubernetes for business logic" where agents are the pods and departments are the deployments.
39
-
40
- ## 🚀 Team Setup
41
-
42
- **New team member?** See the complete setup guide: **[TEAM_SETUP.md](TEAM_SETUP.md)**
43
-
44
- This includes:
45
- - Database setup (PostgreSQL + Docker)
46
- - Local development environment
47
- - Testing instructions
48
- - Troubleshooting guide
49
-
50
- ## Quick Start
51
-
52
- ```python
53
- from memra.sdk.models import Agent, Department, Tool
54
-
55
- # Define your agents
56
- data_extractor = Agent(
57
- role="Data Extraction Specialist",
58
- job="Extract and validate data",
59
- tools=[Tool(name="DataExtractor", hosted_by="memra")],
60
- input_keys=["input_data"],
61
- output_key="extracted_data"
62
- )
63
-
64
- # Create a department
65
- dept = Department(
66
- name="Data Processing",
67
- mission="Process and validate data",
68
- agents=[data_extractor]
69
- )
70
-
71
- # Run the workflow
72
- result = dept.run({"input_data": {...}})
73
- ```
74
-
75
- ## Installation
76
-
77
- ```bash
78
- pip install memra
79
- ```
80
-
81
- ## API Access
82
-
83
- Memra requires an API key to execute workflows on the hosted infrastructure.
84
-
85
- ### Get Your API Key
86
- Contact [info@memra.co](mailto:info@memra.co) for API access.
87
-
88
- ### Set Your API Key
89
- ```bash
90
- # Set environment variable
91
- export MEMRA_API_KEY="your-api-key-here"
92
-
93
- # Or add to your shell profile for persistence
94
- echo 'export MEMRA_API_KEY="your-api-key-here"' >> ~/.zshrc
95
- ```
96
-
97
- ### Test Your Setup
98
- ```bash
99
- python examples/accounts_payable_client.py
100
- ```
101
-
102
- ## Architecture
103
-
104
- The Memra platform consists of three main components:
105
-
106
- - **Memra SDK** (this repository): Client library for building and executing workflows
107
- - **Memra Server**: Hosted infrastructure for heavy AI processing tools
108
- - **MCP Bridge**: Local execution environment for database operations
109
-
110
- Tools are automatically routed between server and local execution based on their `hosted_by` configuration.
111
-
112
- ## Documentation
113
-
114
- Documentation is coming soon. For now, see the examples below and in the `examples/` directory.
115
-
116
- ## Example: Propane Delivery Workflow
117
-
118
- See the `examples/propane_delivery.py` file for a complete example of how to use Memra to orchestrate a propane delivery workflow.
119
-
120
- ## Contributing
121
-
122
- We welcome contributions! Please see our [contributing guide](CONTRIBUTING.md) for details.
123
-
124
- ## License
125
-
126
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
127
-
128
- ## Repository Structure
129
-
130
- ```
131
- ├── examples/ # Example workflows and use cases
132
- │ ├── accounts_payable_client.py # API-based accounts payable workflow
133
- │ ├── accounts_payable_mcp.py # MCP-enabled accounts payable workflow
134
- │ ├── invoice_processing.py # Simple invoice processing example
135
- │ └── propane_delivery.py # Propane delivery domain example
136
- ├── memra/ # Core SDK package
137
- │ ├── __init__.py # Package initialization
138
- │ ├── tool_registry.py # Tool discovery and routing
139
- │ └── sdk/ # SDK components
140
- │ ├── __init__.py
141
- │ ├── client.py # API client
142
- │ ├── execution_engine.py # Workflow execution
143
- │ └── models.py # Core data models
144
- ├── docs/ # Documentation
145
- ├── tests/ # Test suite
146
- ├── local/dependencies/ # Local development setup
147
- └── scripts/ # Utility scripts
148
- ```
@@ -1,13 +0,0 @@
1
- memra/__init__.py,sha256=5WPh9vku8_ZV4T6WayAqArKAj1RDkbL47SsnA9GWD7A,662
2
- memra/discovery.py,sha256=yJIQnrDQu1nyzKykCIuzG_5SW5dIXHCEBLLKRWacIoY,480
3
- memra/discovery_client.py,sha256=AbnKn6qhyrf7vmOvknEeDzH4tiGHsqPHtDaein_qaW0,1271
4
- memra/execution.py,sha256=bg822ED6yYN7APjPac1LRhv48gtxV4DUPvzpyLyBa2I,21443
5
- memra/models.py,sha256=sXMPRnMB_mUVtJdBFyd0ElCf_uh1yqx7iLssIYNm0vI,3333
6
- memra/tool_registry.py,sha256=N7kpYQxgJcSMDDCX-_6og1-of3QKEaoz6H16ptCCg48,7784
7
- memra/tool_registry_client.py,sha256=uzMQ4COvRams9vuPLcqcdljUpDlAYU_tyFxrRhrA0Lc,4009
8
- memra-0.2.2.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- memra-0.2.2.dist-info/METADATA,sha256=jrZ9AwcGtPK-pc9TGGGoi1oJzXxcGx7LUsbsd6NxcxA,4856
10
- memra-0.2.2.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
11
- memra-0.2.2.dist-info/entry_points.txt,sha256=LBVjwWoxWJRzNLgeByPn6xUvWFIRnqnemvAZgIoSt08,41
12
- memra-0.2.2.dist-info/top_level.txt,sha256=pXWcTRS1zctdiSUivW4iyKpJ4tcfIu-1BW_fpbal3OY,6
13
- memra-0.2.2.dist-info/RECORD,,