Commit 7896f651 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Fix Agentic ADK Web ingress prefix

parent 48d60da9
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -104,14 +104,14 @@ spec:
              mountPath: /var/lib/tfs-agentic
          readinessProbe:
            httpGet:
              path: /dev-ui/
              path: /agentic/dev-ui/
              port: 8000
            initialDelaySeconds: 10
            periodSeconds: 10
            failureThreshold: 12
          livenessProbe:
            httpGet:
              path: /dev-ui/
              path: /agentic/dev-ui/
              port: 8000
            initialDelaySeconds: 20
            periodSeconds: 20
@@ -154,7 +154,6 @@ metadata:
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "60"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  rules:
+32 −18
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@ import json
import os
from pathlib import Path

import uvicorn
from google.adk.cli.fast_api import get_fast_api_app

from agentic.Config import validate_agentic_llm_configuration
from agentic.service.a2a_transport import build_agent_card
from agentic.service.settings import HTTP_ROOT_PATH, SESSION_DB_PATH
@@ -28,12 +31,13 @@ from agentic.service.settings import HTTP_ROOT_PATH, SESSION_DB_PATH
ADK_APPS_DIR = Path("/var/teraflow/adk_apps")
ADK_APP_DIR = ADK_APPS_DIR.joinpath("agentic")
ADK_APP_CARD = ADK_APP_DIR.joinpath("agent.json")
ADK_HOST = "0.0.0.0"
ADK_PORT = 8000


def main() -> None:
    """Write the runtime Agent Card and replace this process with ADK Web."""
def _write_agent_card() -> None:
    """Write the runtime Agent Card consumed by ADK A2A exposure."""

    validate_agentic_llm_configuration()
    ADK_APP_DIR.mkdir(parents=True, exist_ok=True)
    card = build_agent_card(a2a_path="/a2a/agentic")
    ADK_APP_CARD.write_text(
@@ -41,23 +45,33 @@ def main() -> None:
        encoding="utf-8",
    )

    argv = [
        "adk",
        "web",
        "--a2a",
        "--host",
        "0.0.0.0",
        "--port",
        "8000",
        "--url_prefix",
        HTTP_ROOT_PATH or "/agentic",
        "--session_service_uri",
        f"sqlite:///{SESSION_DB_PATH}",
        ".",
    ]

def _build_adk_app():
    """Build the ADK Web application with a reverse-proxy root path."""

    root_path = HTTP_ROOT_PATH or "/agentic"
    app = get_fast_api_app(
        agents_dir=".",
        web=True,
        a2a=True,
        host=ADK_HOST,
        port=ADK_PORT,
        url_prefix=root_path,
        session_service_uri=f"sqlite:///{SESSION_DB_PATH}",
        use_local_storage=False,
    )
    app.root_path = root_path
    return app


def main() -> None:
    """Write the runtime Agent Card and run ADK Web."""

    validate_agentic_llm_configuration()
    _write_agent_card()
    os.chdir(str(ADK_APPS_DIR))
    os.environ["PYTHONPATH"] = "/var/teraflow"
    os.execvp("adk", argv)
    uvicorn.run(_build_adk_app(), host=ADK_HOST, port=ADK_PORT)


if __name__ == "__main__":
+26 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
# limitations under the License.

from pathlib import Path
from types import SimpleNamespace

from agentic.Config import (
    DEFAULT_AGENTIC_GRAPH,
@@ -90,6 +91,31 @@ def test_agentic_manifest_exposes_adk_web_a2a_runtime() -> None:
    assert "tfs-ingress-agentic-api" not in manifest
    assert "tfs-ingress-agentic-web" not in manifest
    assert "tfs-ingress-agentic" in manifest
    assert "rewrite-target" not in manifest
    assert "path: /agentic/dev-ui/" in manifest


def test_adk_web_sets_prefixed_fastapi_root_path(monkeypatch) -> None:
    from agentic.service import adk_web

    fake_app = SimpleNamespace(root_path="")
    factory_kwargs = {}

    def fake_get_fast_api_app(**kwargs):
        factory_kwargs.update(kwargs)
        return fake_app

    monkeypatch.setattr(adk_web, "HTTP_ROOT_PATH", "/agentic")
    monkeypatch.setattr(adk_web, "SESSION_DB_PATH", "/tmp/adk.sqlite")
    monkeypatch.setattr(adk_web, "get_fast_api_app", fake_get_fast_api_app)

    app = adk_web._build_adk_app()

    assert app.root_path == "/agentic"
    assert factory_kwargs["url_prefix"] == "/agentic"
    assert factory_kwargs["a2a"] is True
    assert factory_kwargs["web"] is True
    assert factory_kwargs["session_service_uri"] == "sqlite:////tmp/adk.sqlite"


def test_parse_peers(monkeypatch) -> None: