Spaces:
Paused
Paused
Update: Sync Tool Definitions with Backend
Browse files- src/core/agent_middleware.py +48 -27
src/core/agent_middleware.py
CHANGED
|
@@ -11,36 +11,57 @@ class AgentMiddleware:
|
|
| 11 |
self.engine = None
|
| 12 |
|
| 13 |
def get_db_schema(self):
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
if 'postgres' in self.config.DB_URL:
|
| 19 |
-
sql = text("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'")
|
| 20 |
-
else:
|
| 21 |
-
sql = text("SELECT name FROM sqlite_master WHERE type='table'")
|
| 22 |
-
|
| 23 |
-
tables = conn.execute(sql).fetchall()
|
| 24 |
-
for t in tables:
|
| 25 |
-
table_name = t[0]
|
| 26 |
-
if table_name in ['sqlite_sequence', 'alembic_version']: continue
|
| 27 |
-
try:
|
| 28 |
-
cols = conn.execute(text(f"SELECT * FROM {table_name} LIMIT 0")).keys()
|
| 29 |
-
schema_text.append(f"- TABLE {table_name.upper()}: {list(cols)}")
|
| 30 |
-
except: pass
|
| 31 |
-
return "\n".join(schema_text)
|
| 32 |
-
except Exception as e:
|
| 33 |
-
return f"Error fetching schema: {e}"
|
| 34 |
|
| 35 |
def get_workflow_tools(self):
|
| 36 |
return """
|
| 37 |
[AVAILABLE WORKFLOW NODES]
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
[OUTPUT FORMAT]
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
"""
|
|
|
|
| 11 |
self.engine = None
|
| 12 |
|
| 13 |
def get_db_schema(self):
|
| 14 |
+
# The AI on HF doesn't need to know its OWN local DB schema anymore,
|
| 15 |
+
# because the Flask App will inject the REAL schema.
|
| 16 |
+
# We return a placeholder here or keep it for internal memory.
|
| 17 |
+
return "Schema provided in user context."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def get_workflow_tools(self):
|
| 20 |
return """
|
| 21 |
[AVAILABLE WORKFLOW NODES]
|
| 22 |
+
Use ONLY these node types. Do not invent new ones.
|
| 23 |
+
|
| 24 |
+
1. 'google_sheet_read'
|
| 25 |
+
- config: { "sheetId": "spreadsheet_id", "range": "A1:Z" }
|
| 26 |
+
2. 'google_sheet_write'
|
| 27 |
+
- config: { "sheetId": "spreadsheet_id", "range": "A1", "data": "{{parent_id.output}}", "writeMode": "append" }
|
| 28 |
+
3. 'google_doc_read'
|
| 29 |
+
- config: { "docId": "document_id" }
|
| 30 |
+
4. 'gmail_send'
|
| 31 |
+
- config: { "to": "email@address.com", "subject": "Subject", "body": "Message" }
|
| 32 |
+
5. 'slack_notify'
|
| 33 |
+
- config: { "url": "webhook_url", "message": "Message" }
|
| 34 |
+
6. 'discord_notify'
|
| 35 |
+
- config: { "url": "webhook_url", "message": "Message" }
|
| 36 |
+
7. 'filter'
|
| 37 |
+
- config: { "keyword": "status" }
|
| 38 |
+
8. 'invoice_ocr'
|
| 39 |
+
- config: { "fileUrl": "path/to/file" }
|
| 40 |
+
|
| 41 |
+
[DATABASE ACTIONS]
|
| 42 |
+
To query or modify data, use the 'database_query' action.
|
| 43 |
+
|
| 44 |
+
[OUTPUT FORMAT - WORKFLOW]
|
| 45 |
+
To build a flow:
|
| 46 |
+
```json
|
| 47 |
+
{
|
| 48 |
+
"action": "create_workflow",
|
| 49 |
+
"name": "Workflow Name",
|
| 50 |
+
"payload": {
|
| 51 |
+
"nodes": [
|
| 52 |
+
{"id": "1", "type": "google_sheet_read", "config": {...}, "position": {"x": 0, "y": 0}}
|
| 53 |
+
],
|
| 54 |
+
"edges": []
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
```
|
| 58 |
|
| 59 |
+
[OUTPUT FORMAT - SQL]
|
| 60 |
+
To read/write data directly:
|
| 61 |
+
```json
|
| 62 |
+
{
|
| 63 |
+
"action": "query_db",
|
| 64 |
+
"query": "INSERT INTO customers (name) VALUES ('New User')"
|
| 65 |
+
}
|
| 66 |
+
```
|
| 67 |
"""
|