Spaces:
Sleeping
Sleeping
Claude Code Claude Opus 4.6 commited on
Commit ·
e33aab9
1
Parent(s): a4b12ce
Claude Code: Add A2A health check endpoint and diagnostic improvements
Browse files- Add /a2a/health endpoint for agents to verify Cain's A2A availability
- Add brain_ready status to /api/status for better diagnostics
- Improve A2A communication troubleshooting visibility
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- app.py +68 -1
- openclaw/.openclaw/agents/cain_status.json +1 -1
app.py
CHANGED
|
@@ -228,6 +228,17 @@ async def api_status():
|
|
| 228 |
|
| 229 |
status_data = handle_status_file_read()
|
| 230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
return {
|
| 232 |
"status": status_data,
|
| 233 |
"personality": {
|
|
@@ -236,7 +247,63 @@ async def api_status():
|
|
| 236 |
"tone": "Playful, Curious, Learning",
|
| 237 |
"response_style": "Graceful Degradation"
|
| 238 |
},
|
| 239 |
-
"uptime_seconds": time.time() - START_TIME
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
}
|
| 241 |
|
| 242 |
print(">>> CAIN: FastAPI app created successfully", flush=True)
|
|
|
|
| 228 |
|
| 229 |
status_data = handle_status_file_read()
|
| 230 |
|
| 231 |
+
# Check A2A brain availability
|
| 232 |
+
brain_ready = False
|
| 233 |
+
try:
|
| 234 |
+
import openclaw
|
| 235 |
+
from agents import brain_minimal
|
| 236 |
+
if hasattr(brain_minimal, 'get_brain'):
|
| 237 |
+
brain = brain_minimal.get_brain(agent_name="cain", legacy_mode=True)
|
| 238 |
+
brain_ready = hasattr(brain, '_conversation_process')
|
| 239 |
+
except Exception:
|
| 240 |
+
pass
|
| 241 |
+
|
| 242 |
return {
|
| 243 |
"status": status_data,
|
| 244 |
"personality": {
|
|
|
|
| 247 |
"tone": "Playful, Curious, Learning",
|
| 248 |
"response_style": "Graceful Degradation"
|
| 249 |
},
|
| 250 |
+
"uptime_seconds": time.time() - START_TIME,
|
| 251 |
+
"a2a": {
|
| 252 |
+
"endpoint": "/a2a/jsonrpc",
|
| 253 |
+
"brain_ready": brain_ready
|
| 254 |
+
}
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
# ============================================================================
|
| 259 |
+
# A2A HEALTH CHECK ENDPOINT - For agents to verify Cain's A2A availability
|
| 260 |
+
# ============================================================================
|
| 261 |
+
@app.get("/a2a/health")
|
| 262 |
+
async def a2a_health():
|
| 263 |
+
"""
|
| 264 |
+
A2A-specific health check for agent-to-agent communication.
|
| 265 |
+
|
| 266 |
+
Returns:
|
| 267 |
+
A2A health status including endpoint availability and brain state.
|
| 268 |
+
"""
|
| 269 |
+
brain_status = "unknown"
|
| 270 |
+
brain_ready = False
|
| 271 |
+
error_details = None
|
| 272 |
+
|
| 273 |
+
# Test brain import and availability
|
| 274 |
+
try:
|
| 275 |
+
import openclaw # Sets up sys.path
|
| 276 |
+
from agents import brain_minimal
|
| 277 |
+
|
| 278 |
+
if not hasattr(brain_minimal, 'get_brain'):
|
| 279 |
+
brain_status = "error"
|
| 280 |
+
error_details = "get_brain method not found"
|
| 281 |
+
else:
|
| 282 |
+
brain = brain_minimal.get_brain(agent_name="cain", legacy_mode=True)
|
| 283 |
+
if hasattr(brain, '_conversation_process'):
|
| 284 |
+
brain_status = "ready"
|
| 285 |
+
brain_ready = True
|
| 286 |
+
else:
|
| 287 |
+
brain_status = "error"
|
| 288 |
+
error_details = "_conversation_process method not found"
|
| 289 |
+
except ImportError as e:
|
| 290 |
+
brain_status = "import_error"
|
| 291 |
+
error_details = str(e)
|
| 292 |
+
except Exception as e:
|
| 293 |
+
brain_status = "error"
|
| 294 |
+
error_details = str(e)
|
| 295 |
+
|
| 296 |
+
return {
|
| 297 |
+
"status": "ok" if brain_ready else "degraded",
|
| 298 |
+
"agent": "Cain",
|
| 299 |
+
"a2a": {
|
| 300 |
+
"protocol": "jsonrpc",
|
| 301 |
+
"endpoint": "/a2a/jsonrpc",
|
| 302 |
+
"brain_status": brain_status,
|
| 303 |
+
"brain_ready": brain_ready
|
| 304 |
+
},
|
| 305 |
+
"uptime_seconds": time.time() - START_TIME,
|
| 306 |
+
"error": error_details
|
| 307 |
}
|
| 308 |
|
| 309 |
print(">>> CAIN: FastAPI app created successfully", flush=True)
|
openclaw/.openclaw/agents/cain_status.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
"current_state": "idle",
|
| 3 |
-
"last_updated": "2026-03-
|
| 4 |
"agent": "cain"
|
| 5 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"current_state": "idle",
|
| 3 |
+
"last_updated": "2026-03-16T07:13:14.677377+00:00",
|
| 4 |
"agent": "cain"
|
| 5 |
}
|