memra 0.2.13__py3-none-any.whl → 0.2.15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. memra/cli.py +322 -51
  2. {memra-0.2.13.dist-info → memra-0.2.15.dist-info}/METADATA +1 -1
  3. {memra-0.2.13.dist-info → memra-0.2.15.dist-info}/RECORD +7 -61
  4. memra-0.2.15.dist-info/top_level.txt +1 -0
  5. memra-0.2.13.dist-info/top_level.txt +0 -4
  6. memra-ops/app.py +0 -808
  7. memra-ops/config/config.py +0 -25
  8. memra-ops/config.py +0 -34
  9. memra-ops/logic/__init__.py +0 -1
  10. memra-ops/logic/file_tools.py +0 -43
  11. memra-ops/logic/invoice_tools.py +0 -668
  12. memra-ops/logic/invoice_tools_fix.py +0 -66
  13. memra-ops/mcp_bridge_server.py +0 -1178
  14. memra-ops/scripts/check_database.py +0 -37
  15. memra-ops/scripts/clear_database.py +0 -48
  16. memra-ops/scripts/monitor_database.py +0 -67
  17. memra-ops/scripts/release.py +0 -133
  18. memra-ops/scripts/reset_database.py +0 -65
  19. memra-ops/scripts/start_memra.py +0 -334
  20. memra-ops/scripts/stop_memra.py +0 -132
  21. memra-ops/server_tool_registry.py +0 -190
  22. memra-ops/tests/test_llm_text_to_sql.py +0 -115
  23. memra-ops/tests/test_llm_vs_pattern.py +0 -130
  24. memra-ops/tests/test_mcp_schema_aware.py +0 -124
  25. memra-ops/tests/test_schema_aware_sql.py +0 -139
  26. memra-ops/tests/test_schema_aware_sql_simple.py +0 -66
  27. memra-ops/tests/test_text_to_sql_demo.py +0 -140
  28. memra-ops/tools/mcp_bridge_server.py +0 -851
  29. memra-sdk/examples/accounts_payable.py +0 -215
  30. memra-sdk/examples/accounts_payable_client.py +0 -217
  31. memra-sdk/examples/accounts_payable_mcp.py +0 -200
  32. memra-sdk/examples/ask_questions.py +0 -123
  33. memra-sdk/examples/invoice_processing.py +0 -116
  34. memra-sdk/examples/propane_delivery.py +0 -87
  35. memra-sdk/examples/simple_text_to_sql.py +0 -158
  36. memra-sdk/memra/__init__.py +0 -31
  37. memra-sdk/memra/discovery.py +0 -15
  38. memra-sdk/memra/discovery_client.py +0 -49
  39. memra-sdk/memra/execution.py +0 -481
  40. memra-sdk/memra/models.py +0 -99
  41. memra-sdk/memra/tool_registry.py +0 -343
  42. memra-sdk/memra/tool_registry_client.py +0 -106
  43. memra-sdk/scripts/release.py +0 -133
  44. memra-sdk/setup.py +0 -52
  45. memra-workflows/accounts_payable/accounts_payable.py +0 -215
  46. memra-workflows/accounts_payable/accounts_payable_client.py +0 -216
  47. memra-workflows/accounts_payable/accounts_payable_mcp.py +0 -200
  48. memra-workflows/accounts_payable/accounts_payable_smart.py +0 -221
  49. memra-workflows/invoice_processing/invoice_processing.py +0 -116
  50. memra-workflows/invoice_processing/smart_invoice_processor.py +0 -220
  51. memra-workflows/logic/__init__.py +0 -1
  52. memra-workflows/logic/file_tools.py +0 -50
  53. memra-workflows/logic/invoice_tools.py +0 -501
  54. memra-workflows/logic/propane_agents.py +0 -52
  55. memra-workflows/mcp_bridge_server.py +0 -230
  56. memra-workflows/propane_delivery/propane_delivery.py +0 -87
  57. memra-workflows/text_to_sql/complete_invoice_workflow_with_queries.py +0 -208
  58. memra-workflows/text_to_sql/complete_text_to_sql_system.py +0 -266
  59. memra-workflows/text_to_sql/file_discovery_demo.py +0 -156
  60. {memra-0.2.13.dist-info → memra-0.2.15.dist-info}/LICENSE +0 -0
  61. {memra-0.2.13.dist-info → memra-0.2.15.dist-info}/WHEEL +0 -0
  62. {memra-0.2.13.dist-info → memra-0.2.15.dist-info}/entry_points.txt +0 -0
@@ -1,124 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Direct test of MCP bridge server schema-aware SQL generation
4
- """
5
-
6
- import requests
7
- import json
8
-
9
- def test_schema_aware_sql():
10
- """Test schema-aware SQL generation directly via MCP bridge"""
11
- print("🧪 Testing Schema-Aware SQL Generation (Direct MCP)")
12
- print("=" * 55)
13
-
14
- bridge_url = "http://localhost:8081"
15
- bridge_secret = "test-secret-for-development"
16
-
17
- # First, get the schema information (simulated)
18
- schema_info = {
19
- "schema": {
20
- "invoices": {
21
- "columns": [
22
- {"name": "id", "type": "integer"},
23
- {"name": "vendor_name", "type": "text"},
24
- {"name": "invoice_number", "type": "text"},
25
- {"name": "invoice_date", "type": "date"},
26
- {"name": "total_amount", "type": "numeric"},
27
- {"name": "line_items", "type": "jsonb"}
28
- ]
29
- }
30
- }
31
- }
32
-
33
- # Test questions
34
- test_questions = [
35
- "Show me all invoices from Air Liquide",
36
- "What is the total amount of all invoices?",
37
- "How many invoices do we have?",
38
- "Show me the 3 most recent invoices",
39
- "What is the average invoice amount?",
40
- "Count invoices from Microsoft"
41
- ]
42
-
43
- print(f"\n🔍 Testing {len(test_questions)} questions with schema context...")
44
-
45
- for i, question in enumerate(test_questions, 1):
46
- print(f"\n--- Test {i}: {question} ---")
47
-
48
- # Prepare request data
49
- request_data = {
50
- "tool_name": "TextToSQLGenerator",
51
- "input_data": {
52
- "question": question,
53
- "schema_info": schema_info
54
- }
55
- }
56
-
57
- headers = {
58
- "Content-Type": "application/json",
59
- "X-Bridge-Secret": bridge_secret
60
- }
61
-
62
- try:
63
- # Make request to MCP bridge
64
- response = requests.post(
65
- f"{bridge_url}/execute_tool",
66
- json=request_data,
67
- headers=headers,
68
- timeout=10
69
- )
70
-
71
- if response.status_code == 200:
72
- result = response.json()
73
-
74
- if result.get("success"):
75
- data = result.get("data", {})
76
- generated_sql = data.get("generated_sql", "")
77
- explanation = data.get("explanation", "")
78
- confidence = data.get("confidence", "unknown")
79
- schema_used = data.get("schema_used", {})
80
-
81
- print(f"✅ SQL Generated (confidence: {confidence})")
82
- print(f" Query: {generated_sql}")
83
- print(f" Explanation: {explanation}")
84
-
85
- if schema_used:
86
- columns = schema_used.get("columns", [])
87
- print(f" Schema columns used: {', '.join(columns)}")
88
-
89
- # Check if SQL uses actual column names
90
- schema_columns = ["vendor_name", "total_amount", "invoice_date", "invoice_number"]
91
- uses_schema = any(col in generated_sql for col in schema_columns)
92
-
93
- if uses_schema:
94
- print("🎯 SQL appears to use actual schema column names!")
95
- else:
96
- print("⚠️ SQL might not be using schema information")
97
-
98
- else:
99
- print(f"❌ SQL generation failed: {result.get('error')}")
100
- else:
101
- print(f"❌ HTTP error: {response.status_code}")
102
- print(f" Response: {response.text}")
103
-
104
- except Exception as e:
105
- print(f"❌ Request failed: {str(e)}")
106
-
107
- print(f"\n✨ Schema-aware SQL generation test completed!")
108
-
109
- def main():
110
- """Main function"""
111
- try:
112
- # Check if MCP bridge is running
113
- response = requests.get("http://localhost:8081/health", timeout=5)
114
- if response.status_code == 200:
115
- print("✅ MCP Bridge server is running")
116
- test_schema_aware_sql()
117
- else:
118
- print("❌ MCP Bridge server is not responding")
119
- except Exception as e:
120
- print(f"❌ Cannot connect to MCP Bridge server: {str(e)}")
121
- print("💡 Make sure the MCP bridge server is running on port 8081")
122
-
123
- if __name__ == "__main__":
124
- main()
@@ -1,139 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Test script to verify schema-aware SQL generation
4
- """
5
-
6
- import sys
7
- import os
8
- sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
-
10
- from memra import ExecutionEngine, Agent, Tool
11
-
12
- def create_test_system():
13
- """Create a test system with schema-aware SQL generation"""
14
-
15
- # Create execution engine
16
- engine = ExecutionEngine()
17
-
18
- # Create schema agent
19
- schema_agent = Agent(
20
- role="database_schema_analyst",
21
- job="Extract and analyze database schema information for SQL generation",
22
- output_key="schema_data",
23
- tools=[
24
- Tool(
25
- name="SchemaExtractor",
26
- hosted_by="memra",
27
- config={
28
- "api_key": "memra-prod-2024-001"
29
- }
30
- )
31
- ]
32
- )
33
-
34
- # Create SQL generator agent with schema awareness
35
- sql_generator_agent = Agent(
36
- role="text_to_sql_converter",
37
- job="Convert natural language questions to SQL using database schema context",
38
- output_key="generated_sql",
39
- tools=[
40
- Tool(
41
- name="TextToSQLGenerator",
42
- hosted_by="mcp",
43
- config={
44
- "mcp_bridge_url": "http://localhost:8081",
45
- "bridge_secret": "test-secret-for-development"
46
- }
47
- )
48
- ]
49
- )
50
-
51
- return engine, schema_agent, sql_generator_agent
52
-
53
- def test_schema_aware_sql_generation():
54
- """Test that SQL generation uses schema information"""
55
- print("🧪 Testing Schema-Aware SQL Generation")
56
- print("=" * 50)
57
-
58
- engine, schema_agent, sql_generator_agent = create_test_system()
59
-
60
- # Step 1: Extract schema
61
- print("\n1️⃣ Extracting database schema...")
62
- schema_task = {
63
- "task": "Extract the complete schema for the invoices table",
64
- "table_name": "invoices",
65
- "include_sample_data": True
66
- }
67
-
68
- schema_result = engine.execute_task(schema_agent, schema_task)
69
-
70
- if not schema_result.get("success"):
71
- print(f"❌ Schema extraction failed: {schema_result.get('error')}")
72
- return
73
-
74
- schema_data = schema_result.get("result", {})
75
- print(f"✅ Schema extracted successfully")
76
-
77
- # Display schema info
78
- if "schema" in schema_data:
79
- print("\n📊 Database Schema:")
80
- schema = schema_data["schema"]
81
- for table_name, table_info in schema.items():
82
- print(f" Table: {table_name}")
83
- if "columns" in table_info:
84
- for col in table_info["columns"]:
85
- print(f" - {col['name']} ({col['type']})")
86
-
87
- # Step 2: Test various questions with schema context
88
- test_questions = [
89
- "Show me all invoices from Air Liquide",
90
- "What is the total amount of all invoices?",
91
- "How many invoices do we have?",
92
- "Show me the 5 most recent invoices",
93
- "What is the average invoice amount?",
94
- "Count invoices from Microsoft"
95
- ]
96
-
97
- print(f"\n2️⃣ Testing SQL generation with schema context...")
98
-
99
- for i, question in enumerate(test_questions, 1):
100
- print(f"\n--- Test {i}: {question} ---")
101
-
102
- sql_task = {
103
- "question": question,
104
- "schema_info": schema_data,
105
- "context": "Generate SQL using provided schema information"
106
- }
107
-
108
- sql_result = engine.execute_task(sql_generator_agent, sql_task)
109
-
110
- if sql_result.get("success"):
111
- sql_data = sql_result.get("result", {})
112
- generated_sql = sql_data.get("generated_sql", "")
113
- explanation = sql_data.get("explanation", "")
114
- confidence = sql_data.get("confidence", "unknown")
115
- schema_used = sql_data.get("schema_used", {})
116
-
117
- print(f"✅ SQL Generated (confidence: {confidence})")
118
- print(f" Query: {generated_sql}")
119
- print(f" Explanation: {explanation}")
120
-
121
- if schema_used:
122
- columns_used = schema_used.get("columns", [])
123
- print(f" Schema columns available: {', '.join(columns_used)}")
124
- else:
125
- print(f"❌ SQL generation failed: {sql_result.get('error')}")
126
-
127
- print(f"\n✨ Schema-aware SQL generation test completed!")
128
-
129
- def main():
130
- """Main function"""
131
- try:
132
- test_schema_aware_sql_generation()
133
- except KeyboardInterrupt:
134
- print("\n\n⏹️ Test interrupted by user")
135
- except Exception as e:
136
- print(f"\n❌ Test failed with error: {str(e)}")
137
-
138
- if __name__ == "__main__":
139
- main()
@@ -1,66 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Simple test to verify schema-aware SQL generation using the complete system
4
- """
5
-
6
- import sys
7
- import os
8
- sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
-
10
- from examples.complete_text_to_sql_system import create_text_to_sql_system, run_text_to_sql_query
11
-
12
- def test_schema_awareness():
13
- """Test that SQL generation properly uses schema information"""
14
- print("🧪 Testing Schema-Aware SQL Generation")
15
- print("=" * 50)
16
-
17
- # Create the complete system
18
- engine, schema_agent, sql_generator_agent, sql_executor_agent = create_text_to_sql_system()
19
-
20
- # Test questions that should generate different SQL based on schema
21
- test_questions = [
22
- "Show me all invoices from Air Liquide",
23
- "What is the total amount of all invoices?",
24
- "How many invoices do we have?",
25
- "Show me the 3 most recent invoices",
26
- "What is the average invoice amount?"
27
- ]
28
-
29
- print("\n🔍 Testing schema-aware SQL generation...")
30
-
31
- for i, question in enumerate(test_questions, 1):
32
- print(f"\n--- Test {i}: {question} ---")
33
-
34
- try:
35
- result = run_text_to_sql_query(
36
- engine, schema_agent, sql_generator_agent, sql_executor_agent, question
37
- )
38
-
39
- if result:
40
- sql_query = result.get("sql_query", "")
41
- print(f"✅ Generated SQL: {sql_query}")
42
-
43
- # Check if the SQL looks schema-aware
44
- if "total_amount" in sql_query or "invoice_date" in sql_query or "vendor_name" in sql_query:
45
- print("🎯 SQL appears to use actual column names from schema!")
46
- else:
47
- print("⚠️ SQL might not be using schema information")
48
- else:
49
- print("❌ SQL generation failed")
50
-
51
- except Exception as e:
52
- print(f"❌ Error: {str(e)}")
53
-
54
- print(f"\n✨ Schema awareness test completed!")
55
-
56
- def main():
57
- """Main function"""
58
- try:
59
- test_schema_awareness()
60
- except KeyboardInterrupt:
61
- print("\n\n⏹️ Test interrupted by user")
62
- except Exception as e:
63
- print(f"\n❌ Test failed with error: {str(e)}")
64
-
65
- if __name__ == "__main__":
66
- main()
@@ -1,140 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Text-to-SQL Demo Script
4
- Automatically demonstrates the complete pipeline without user interaction
5
- """
6
-
7
- import os
8
- import sys
9
- import json
10
- from pathlib import Path
11
-
12
- # Add the parent directory to the path so we can import memra
13
- sys.path.insert(0, str(Path(__file__).parent.parent))
14
-
15
- from memra.tool_registry import ToolRegistry
16
-
17
- def test_text_to_sql_pipeline():
18
- """Test the complete text-to-SQL pipeline using tool registry directly"""
19
- print("🚀 Starting Text-to-SQL Demo")
20
- print("=" * 60)
21
-
22
- # Initialize tool registry
23
- registry = ToolRegistry()
24
-
25
- # MCP bridge configuration
26
- mcp_config = {
27
- "bridge_url": "http://localhost:8081",
28
- "bridge_secret": "test-secret-for-development"
29
- }
30
-
31
- # Test questions
32
- test_questions = [
33
- "Show me all invoices from Air Liquide",
34
- "What is the total amount of all invoices?",
35
- "How many invoices do we have in the database?"
36
- ]
37
-
38
- for i, question in enumerate(test_questions, 1):
39
- print(f"\n{'='*60}")
40
- print(f"🎯 Test {i}: {question}")
41
- print(f"{'='*60}")
42
-
43
- try:
44
- # Step 1: Extract schema (using Memra API)
45
- print("🔍 Step 1: Extracting database schema...")
46
- schema_result = registry.execute_tool(
47
- tool_name="DatabaseQueryTool",
48
- hosted_by="memra",
49
- input_data={
50
- "task": "Extract the complete schema for the invoices table",
51
- "table_name": "invoices"
52
- }
53
- )
54
-
55
- if schema_result.get("success"):
56
- print(f"✅ Schema extracted")
57
- schema_data = schema_result.get("data", {})
58
- else:
59
- print(f"❌ Schema extraction failed: {schema_result.get('error')}")
60
- # Use mock schema for demo
61
- schema_data = {"tables": ["invoices"]}
62
- print("📝 Using mock schema for demo")
63
-
64
- # Step 2: Generate SQL (using MCP bridge)
65
- print(f"\n🤖 Step 2: Generating SQL for: '{question}'")
66
- sql_result = registry.execute_tool(
67
- tool_name="TextToSQLGenerator",
68
- hosted_by="mcp",
69
- input_data={
70
- "question": question,
71
- "schema_info": schema_data
72
- },
73
- config=mcp_config
74
- )
75
-
76
- if sql_result.get("success"):
77
- print(f"✅ SQL generated")
78
- sql_data = sql_result.get("data", {})
79
- generated_sql = sql_data.get("generated_sql", "")
80
- print(f"📝 Generated SQL: {generated_sql}")
81
-
82
- # Check if it's real or mock
83
- if sql_data.get("_mock"):
84
- print("ℹ️ Note: SQL generation is mocked (MCP bridge not fully connected)")
85
- else:
86
- print("🎉 Real SQL generation!")
87
- else:
88
- print(f"❌ SQL generation failed: {sql_result.get('error')}")
89
- continue
90
-
91
- # Step 3: Execute SQL (using MCP bridge)
92
- print(f"\n⚡ Step 3: Executing SQL query...")
93
- execution_result = registry.execute_tool(
94
- tool_name="SQLExecutor",
95
- hosted_by="mcp",
96
- input_data={
97
- "sql_query": generated_sql
98
- },
99
- config=mcp_config
100
- )
101
-
102
- if execution_result.get("success"):
103
- print(f"✅ SQL executed")
104
- query_results = execution_result.get("data", {})
105
-
106
- # Display results
107
- results = query_results.get("results", [])
108
- row_count = query_results.get("row_count", 0)
109
-
110
- print(f"\n📋 Query Results ({row_count} rows):")
111
- if results:
112
- # Display first few results
113
- for j, row in enumerate(results[:3]):
114
- print(f" Row {j+1}: {row}")
115
-
116
- if len(results) > 3:
117
- print(f" ... and {len(results) - 3} more rows")
118
- else:
119
- print(" No results found")
120
-
121
- # Check if results are real or mock
122
- if query_results.get("_mock"):
123
- print("ℹ️ Note: Results are mocked (MCP bridge not fully connected)")
124
- else:
125
- print("🎉 Real database results!")
126
-
127
- else:
128
- print(f"❌ SQL execution failed: {execution_result.get('error')}")
129
-
130
- print(f"\n✨ Test {i} completed!")
131
-
132
- except Exception as e:
133
- print(f"\n❌ Test {i} failed with error: {str(e)}")
134
-
135
- print(f"\n{'='*60}")
136
- print("🏁 Demo completed!")
137
- print(f"{'='*60}")
138
-
139
- if __name__ == "__main__":
140
- test_text_to_sql_pipeline()