Update app.py with Agent Zero Canvas
Browse files
app.py
CHANGED
|
@@ -2,8 +2,7 @@
|
|
| 2 |
# requires-python = ">=3.10"
|
| 3 |
# dependencies = [
|
| 4 |
# "marimo",
|
| 5 |
-
# "
|
| 6 |
-
# "plotly",
|
| 7 |
# ]
|
| 8 |
# ///
|
| 9 |
|
|
@@ -16,55 +15,75 @@ app = marimo.App()
|
|
| 16 |
@app.cell
|
| 17 |
def _():
|
| 18 |
import marimo as mo
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
@app.cell
|
| 23 |
def _(mo):
|
| 24 |
-
mo.md(
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
return
|
| 28 |
-
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
mo.md("### π Memgraph Query")
|
| 33 |
-
query = mo.ui.text_area(
|
| 34 |
-
label="Cypher Query:",
|
| 35 |
-
value="MATCH (n) RETURN n LIMIT 10",
|
| 36 |
-
full_width=True
|
| 37 |
)
|
| 38 |
-
return query,
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
@app.cell
|
| 42 |
-
def _(mo, query):
|
| 43 |
-
from gqlalchemy import Memgraph
|
| 44 |
-
try:
|
| 45 |
-
memgraph = Memgraph(host='localhost', port=7687)
|
| 46 |
-
results = list(memgraph.execute(query.value))
|
| 47 |
-
mo.md(f"**Results:** {len(results)} rows")
|
| 48 |
-
mo.ui.table(results)
|
| 49 |
-
except Exception as e:
|
| 50 |
-
mo.md(f"β Memgraph error: {e}")
|
| 51 |
return
|
| 52 |
|
| 53 |
|
| 54 |
@app.cell
|
| 55 |
-
def _(mo):
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
@app.cell
|
| 63 |
def _(chat, mo):
|
| 64 |
-
|
| 65 |
-
|
|
|
|
| 66 |
return
|
| 67 |
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
| 70 |
-
app.run()
|
|
|
|
| 2 |
# requires-python = ">=3.10"
|
| 3 |
# dependencies = [
|
| 4 |
# "marimo",
|
| 5 |
+
# "openai",
|
|
|
|
| 6 |
# ]
|
| 7 |
# ///
|
| 8 |
|
|
|
|
| 15 |
@app.cell
|
| 16 |
def _():
|
| 17 |
import marimo as mo
|
| 18 |
+
import os
|
| 19 |
+
import json
|
| 20 |
+
return mo, os, json
|
| 21 |
|
| 22 |
|
| 23 |
@app.cell
|
| 24 |
def _(mo):
|
| 25 |
+
mo.md(
|
| 26 |
+
"""
|
| 27 |
+
# β€ Agent Zero Canvas
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
Connected to **Agent Zero** via Hermes API (OpenAI-compatible).
|
| 30 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
return
|
| 33 |
|
| 34 |
|
| 35 |
@app.cell
|
| 36 |
+
def _(mo, os, json):
|
| 37 |
+
# --- API Key Resolution ---
|
| 38 |
+
# Priority: AGENT_ZERO_API_KEY > parsed from API_KEYS_JSON > fallback
|
| 39 |
+
api_key = os.environ.get("AGENT_ZERO_API_KEY", "")
|
| 40 |
+
|
| 41 |
+
if not api_key:
|
| 42 |
+
# Parse API_KEYS_JSON (same logic as verdant_claw entrypoint.sh)
|
| 43 |
+
keys_json = os.environ.get("API_KEYS_JSON", "")
|
| 44 |
+
if keys_json:
|
| 45 |
+
try:
|
| 46 |
+
keys = json.loads(keys_json)
|
| 47 |
+
# Use the "agent_zero" key if present, otherwise fall back to "openai"
|
| 48 |
+
api_key = keys.get("agent_zero", keys.get("openai", ""))
|
| 49 |
+
except json.JSONDecodeError:
|
| 50 |
+
pass
|
| 51 |
+
|
| 52 |
+
if not api_key:
|
| 53 |
+
api_key = "hermes-secret-key-123" # default for local dev
|
| 54 |
+
|
| 55 |
+
# --- Base URL ---
|
| 56 |
+
# This MUST be the public tunnel URL for your Lightning AI Studio port 8642
|
| 57 |
+
base_url = os.environ.get(
|
| 58 |
+
"AGENT_ZERO_BASE_URL",
|
| 59 |
+
"https://8642-01kmke6kkwzc5svsxjvqje6yth.cloudspaces.litng.ai/v1"
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
chat = mo.ui.chat(
|
| 63 |
+
mo.ai.llm.openai(
|
| 64 |
+
"hermes-agent",
|
| 65 |
+
system_message="You are Agent Zero, an advanced AI assistant with access to tools including Hermes Agent for complex reasoning, a terminal, browser, and file system.",
|
| 66 |
+
api_key=api_key,
|
| 67 |
+
base_url=base_url,
|
| 68 |
+
),
|
| 69 |
+
prompts=[
|
| 70 |
+
"What tools do you have available?",
|
| 71 |
+
"Use Hermes to analyze this problem",
|
| 72 |
+
"Help me write a Python script",
|
| 73 |
+
],
|
| 74 |
+
show_configuration_controls=True,
|
| 75 |
+
)
|
| 76 |
+
chat
|
| 77 |
+
return base_url, api_key, chat
|
| 78 |
|
| 79 |
|
| 80 |
@app.cell
|
| 81 |
def _(chat, mo):
|
| 82 |
+
mo.md(
|
| 83 |
+
f"**Messages exchanged:** {len(chat.value) if chat.value else 0}"
|
| 84 |
+
)
|
| 85 |
return
|
| 86 |
|
| 87 |
|
| 88 |
if __name__ == "__main__":
|
| 89 |
+
app.run()
|