Update app.py with Agent Zero Canvas
Browse files1 unmodified line234567896 unmodified lines161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869701 unmodified line# requires-python = ">=3.10"# dependencies = [# "marimo",# "gqlalchemy",# "plotly",# ]# ///6 unmodified lines@app.celldef _():import marimo as moreturn mo,@app.celldef _(mo):mo.md("# π¦ VerdantClaw-Secure")mo.md("**Status:** β Online")mo.md("---")return@app.celldef _(mo):mo.md("### π Memgraph Query")query = mo.ui.text_area(label="Cypher Query:",value="MATCH (n) RETURN n LIMIT 10",full_width=True)return query,@app.celldef _(mo, query):from gqlalchemy import Memgraphtry:memgraph = Memgraph(host='localhost', port=7687)results = list(memgraph.execute(query.value))mo.md(f"**Results:** {len(results)} rows")mo.ui.table(results)except Exception as e:mo.md(f"β Memgraph error: {e}")return@app.celldef _(mo):mo.md("---")mo.md("### π¬ Chat")chat = mo.ui.text_area(label="Message:", full_width=True)return chat,@app.celldef _(chat, mo):if chat.value:mo.md(f"**You:** {chat.value}")returnif __name__ == "__main__":app.run()1 unmodified line23456786 unmodified lines1516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788891 unmodified line# requires-python = ">=3.10"# dependencies = [# "marimo",# "openai",# ]# ///6 unmodified lines@app.celldef _():import marimo as moimport osimport jsonreturn mo, os, json@app.celldef _(mo):mo.md("""# β€ Agent Zero CanvasConnected to **Agent Zero** via Hermes API (OpenAI-compatible).""")return@app.celldef _(mo, os, json):# --- API Key Resolution ---# Priority: AGENT_ZERO_API_KEY > parsed from API_KEYS_JSON > fallbackapi_key = os.environ.get("AGENT_ZERO_API_KEY", "")if not api_key:# Parse API_KEYS_JSON (same logic as verdant_claw entrypoint.sh)keys_json = os.environ.get("API_KEYS_JSON", "")if keys_json:try:keys = json.loads(keys_json)# Use the "agent_zero" key if present, otherwise fall back to "openai"api_key = keys.get("agent_zero", keys.get("openai", ""))except json.JSONDecodeError:passif not api_key:api_key = "hermes-secret-key-123" # default for local dev# --- Base URL ---# This MUST be the public tunnel URL for your Lightning AI Studio port 8642base_url = os.environ.get("AGENT_ZERO_BASE_URL","https://8642-01kmke6kkwzc5svsxjvqje6yth.cloudspaces.litng.ai/v1")chat = mo.ui.chat(mo.ai.llm.openai("hermes-agent",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.",api_key=api_key,base_url=base_url,),prompts=["What tools do you have available?","Use Hermes to analyze this problem","Help me write a Python script",],show_configuration_controls=True,)chatreturn base_url, api_key, chat@app.celldef _(chat, mo):mo.md(f"**Messages exchanged:** {len(chat.value) if chat.value else 0}")returnif __name__ == "__main__":app.run()
app.py+55-36