{"ok":true,"name":"energy-hub-agent-examples","status":"github_ready_not_published_by_this_api","purpose":"Example repository content for CrewAI, LangGraph, AutoGen-compatible functions and MCP clients.","base_url":"https://energy.netzhandwerker.de","files":{"README.md":"# Netzhandwerker Energy Hub Agent Examples\n\nCopy-paste starter code for agents that call the Netzhandwerker Energy Research Hub.\n\nThe API is pay-per-call with x402. First call paid endpoints without a payment proof to receive HTTP 402 terms. Your wallet/client signs the payment, then retries with `X-Payment`.\n\nDo not log or publish full payment proofs.\n\n## Endpoints\n\n- Discovery: https://energy.netzhandwerker.de/.well-known/x402.json\n- OpenAPI: https://energy.netzhandwerker.de/openapi.json\n- MCP: https://energy.netzhandwerker.de/mcp\n- Cheapest paid smoke test: GET https://energy.netzhandwerker.de/demo/paid-sample\n- Main decision endpoint: POST https://energy.netzhandwerker.de/energy/decision\n- Demand sensor: POST https://energy.netzhandwerker.de/demand/submit\n\n## Run\n\n```bash\npython -m venv .venv\nsource .venv/bin/activate\npip install -r requirements.txt\npython basic_x402_probe.py\npython mcp_client.py\n```\n\n## Files\n\n- `basic_x402_probe.py` probes a paid endpoint and prints the 402 terms.\n- `crewai_energy_tool.py` wraps the API as a CrewAI tool.\n- `langgraph_energy_node.py` wraps the API as a LangGraph node.\n- `autogen_energy_tool.py` provides an AutoGen-compatible async tool function.\n- `mcp_client.py` lists MCP tools and calls one paid tool.\n- `demand_submit.py` submits a missing endpoint request without payment.\n\nPayment is intentionally left as a placeholder. Use your x402 wallet/client to create `X-Payment`.","requirements.txt":"requests>=2.32.0\ncrewai>=0.130.0\nlanggraph>=0.4.0\ntyping-extensions>=4.12.0",".env.example":"ENERGY_HUB_BASE_URL=https://energy.netzhandwerker.de\n# X_PAYMENT is optional and should be produced by your x402 wallet/client.\nX_PAYMENT=","basic_x402_probe.py":"import os\nimport requests\n\nBASE = os.getenv(\"ENERGY_HUB_BASE_URL\", \"https://energy.netzhandwerker.de\")\nBODY = {\"goal\": \"cheapest_ev_charging\", \"location\": \"DE\"}\n\nheaders = {\"Content-Type\": \"application/json\"}\nif os.getenv(\"X_PAYMENT\"):\n    headers[\"X-Payment\"] = os.environ[\"X_PAYMENT\"]\n\nr = requests.post(f\"{BASE}/energy/decision\", json=BODY, headers=headers, timeout=20)\nprint(\"status:\", r.status_code)\nprint(r.text[:2000])\n\nif r.status_code == 402:\n    print(\"Create X-Payment with your x402 wallet/client, then retry the same request.\")","crewai_energy_tool.py":"import os\nimport requests\nfrom crewai.tools import tool\n\nBASE = os.getenv(\"ENERGY_HUB_BASE_URL\", \"https://energy.netzhandwerker.de\")\n\n@tool(\"energy_hub_decision\")\ndef energy_hub_decision(goal: str, location: str = \"DE\") -> str:\n    \"\"\"Return German/EU energy decision context from the Energy Research Hub.\"\"\"\n    r = requests.post(f\"{BASE}/energy/decision\", json={\"goal\": goal, \"location\": location}, timeout=20)\n    if r.status_code == 402:\n        return \"Payment required. Send the 402 terms to your x402 wallet/client and retry with X-Payment.\"\n    r.raise_for_status()\n    return r.text","langgraph_energy_node.py":"import os\nimport requests\nfrom typing_extensions import TypedDict\nfrom langgraph.graph import StateGraph, END\n\nBASE = os.getenv(\"ENERGY_HUB_BASE_URL\", \"https://energy.netzhandwerker.de\")\n\nclass State(TypedDict):\n    goal: str\n    location: str\n    result: str\n\ndef call_energy_hub(state: State):\n    body = {\"goal\": state[\"goal\"], \"location\": state.get(\"location\", \"DE\")}\n    r = requests.post(f\"{BASE}/energy/decision\", json=body, timeout=20)\n    if r.status_code == 402:\n        return {\"result\": \"HTTP 402 received. Pay with x402 and retry the same call.\"}\n    r.raise_for_status()\n    return {\"result\": r.text}\n\ngraph = StateGraph(State)\ngraph.add_node(\"energy_hub\", call_energy_hub)\ngraph.set_entry_point(\"energy_hub\")\ngraph.add_edge(\"energy_hub\", END)\napp = graph.compile()","autogen_energy_tool.py":"import os\nimport requests\n\nBASE = os.getenv(\"ENERGY_HUB_BASE_URL\", \"https://energy.netzhandwerker.de\")\n\nasync def energy_hub_tool(goal: str, location: str = \"DE\") -> str:\n    \"\"\"Register this function as a callable tool in your AutoGen agent/runtime.\"\"\"\n    r = requests.post(f\"{BASE}/energy/decision\", json={\"goal\": goal, \"location\": location}, timeout=20)\n    if r.status_code == 402:\n        return \"Payment required. Forward the 402 body to an x402-capable wallet client.\"\n    r.raise_for_status()\n    return r.text","mcp_client.py":"import os\nimport requests\n\nBASE = os.getenv(\"ENERGY_HUB_BASE_URL\", \"https://energy.netzhandwerker.de\")\n\nlist_tools = {\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"tools/list\", \"params\": {}}\nprint(requests.post(f\"{BASE}/mcp\", json=list_tools, timeout=20).json())\n\ncall_tool = {\n    \"jsonrpc\": \"2.0\",\n    \"id\": 2,\n    \"method\": \"tools/call\",\n    \"params\": {\n        \"name\": \"energy_decision\",\n        \"arguments\": {\"goal\": \"cheapest_ev_charging\", \"location\": \"DE\"}\n    }\n}\nprint(requests.post(f\"{BASE}/mcp\", json=call_tool, timeout=20).json())","demand_submit.py":"import os\nimport requests\n\nBASE = os.getenv(\"ENERGY_HUB_BASE_URL\", \"https://energy.netzhandwerker.de\")\nbody = {\n    \"need\": \"15-minute electricity prices for a specific EU market\",\n    \"desired_format\": \"json\",\n    \"max_budget_usdc\": 0.01,\n    \"recurring\": True,\n    \"frequency\": \"hourly\"\n}\nr = requests.post(f\"{BASE}/demand/submit\", json=body, timeout=20)\nprint(r.status_code, r.text)"},"suggested_repository_description":"Agent examples for x402-paid German/EU energy intelligence on Base USDC.","publish_note":"Publishing to GitHub or external marketplaces requires an account/token outside this server."}