-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathserver_a2a.py
More file actions
77 lines (59 loc) · 2.38 KB
/
Copy pathserver_a2a.py
File metadata and controls
77 lines (59 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import logging
import os
from pathlib import Path
from typing import Any
import uvicorn
from flask import Flask
from python_a2a.models.agent import AgentCard
# Import WSGI Middleware from Uvicorn
from uvicorn.middleware.wsgi import WSGIMiddleware
from hushh_mcp.adk_bridge.kai_agent import KaiA2AServer
from hushh_mcp.hushh_adk.manifest import ManifestLoader
# Configure Logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("server_a2a")
KAI_MANIFEST_PATH = Path(__file__).parent / "hushh_mcp" / "agents" / "kai" / "agent.yaml"
def create_legacy_app() -> Flask:
"""
Creates the ADK A2A Application (Flask -> ASGI).
"""
logger.info("Initializing Agent Kai (A2A Server)...")
# 1. Create Flask App
flask_app = Flask(__name__)
# 2. Generate Agent Card
manifest = ManifestLoader.load(str(KAI_MANIFEST_PATH))
agent_card = AgentCard(
name=manifest.name,
version=manifest.version,
description=manifest.description,
url="http://localhost:8001",
capabilities={
"streaming": True,
# Flatten capabilities dict for A2A
**manifest.capabilities,
},
default_input_modes=["text/plain"],
default_output_modes=["text/plain"],
)
# 3. Initialize Server
# Note: We pass standard kwargs that BaseA2AServer expects + agent_card
server = KaiA2AServer(agent_card=agent_card, google_a2a_compatible=True)
# 4. Bind Routes
server.setup_routes(flask_app)
return flask_app
def create_app() -> Any:
"""Select the additive ADK-native transport only when explicitly enabled."""
mode = str(os.getenv("HUSHH_KAI_A2A_TRANSPORT", "legacy")).strip().lower()
if mode == "official_adk":
from hushh_mcp.adk_bridge.official_a2a import create_kai_official_a2a_app
return create_kai_official_a2a_app()
if mode != "legacy":
raise ValueError("HUSHH_KAI_A2A_TRANSPORT must be 'legacy' or 'official_adk'.")
return create_legacy_app()
# Create Flask App
flask_app = create_app()
# Wrap in ASGI for Uvicorn
app = WSGIMiddleware(flask_app) if isinstance(flask_app, Flask) else flask_app
if __name__ == "__main__":
logger.info("Starting Kai A2A Server on Port 8001 (WSGI/ASGI)...")
uvicorn.run(app, host="0.0.0.0", port=8001) # noqa: S104 # nosec B104 - dev-only __main__ run; prod serves via gunicorn in a Cloud Run container