Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ lint:

.PHONY: test
test: update generate-test-certs
uv run pytest ./packages/**/tests/
uv run pytest ./packages/**/tests/ ./samples/langgraph/hitl-tools/tests/ ./samples/langgraph/kebab/tests/

.PHONY: build
build: update format
Expand Down
4 changes: 2 additions & 2 deletions python/samples/langgraph/hitl-tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1

# Run the application
CMD ["uv", "run", "samples/langgraph/hitl-tools/hitl_tools/cli.py"]
# Run the installed console entry point so package-relative imports resolve.
CMD ["uv", "run", "--package", "hitl-tools", "hitl-tools"]
21 changes: 13 additions & 8 deletions python/samples/langgraph/hitl-tools/hitl_tools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,39 @@
import os

import uvicorn
from agent import graph
from kagent.core import KAgentConfig
from kagent.langgraph import KAgentApp

from .agent import graph

logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")

logger = logging.getLogger(__name__)


def main():
"""Main entry point for the CLI."""
def build_app():
"""Build the HITL tools ASGI application."""
with open(os.path.join(os.path.dirname(__file__), "agent-card.json"), "r") as f:
agent_card = json.load(f)

config = KAgentConfig()
app = KAgentApp(
return KAgentApp(
graph=graph,
agent_card=agent_card,
config=config,
config=KAgentConfig(),
tracing=True,
)
).build()


def main():
"""Main entry point for the CLI."""
app = build_app()

port = int(os.getenv("PORT", "8080"))
host = os.getenv("HOST", "0.0.0.0")
logger.info(f"Starting server on {host}:{port}")

uvicorn.run(
app.build(),
app,
host=host,
port=port,
log_level="info",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Regression tests for the HITL tools console entry point."""

import importlib

from fastapi.testclient import TestClient


def test_main_passes_healthy_app_to_uvicorn(monkeypatch):
monkeypatch.setenv("OPENAI_API_KEY", "fake")
monkeypatch.setenv("KAGENT_API_URL", "http://localhost:8083")
monkeypatch.setenv("KAGENT_GATEWAY_URL", "http://localhost:8083")
monkeypatch.setenv("KAGENT_NAME", "hitl-tools")
monkeypatch.setenv("KAGENT_NAMESPACE", "default")

cli = importlib.import_module("hitl_tools.cli")
captured = {}
monkeypatch.setattr(cli.uvicorn, "run", lambda app, **kwargs: captured.update(app=app, kwargs=kwargs))

cli.main()

assert TestClient(captured["app"]).get("/health").text == "OK"
assert captured["kwargs"] == {"host": "0.0.0.0", "port": 8080, "log_level": "info"}
3 changes: 2 additions & 1 deletion python/samples/langgraph/kebab/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1

CMD ["uv", "run", "samples/langgraph/kebab/kebab/cli.py"]
# Run the installed console entry point so package-relative imports resolve.
CMD ["uv", "run", "--package", "kebab", "kebab"]
20 changes: 13 additions & 7 deletions python/samples/langgraph/kebab/kebab/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,39 @@
import os

import uvicorn
from agent import graph
from kagent.core import KAgentConfig
from kagent.langgraph import KAgentApp

from .agent import graph

logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")

logger = logging.getLogger(__name__)


def main():
def build_app():
"""Build the kebab ASGI application."""
with open(os.path.join(os.path.dirname(__file__), "agent-card.json"), "r") as f:
agent_card = json.load(f)

config = KAgentConfig()
app = KAgentApp(
return KAgentApp(
graph=graph,
agent_card=agent_card,
config=config,
config=KAgentConfig(),
tracing=False,
)
).build()


def main():
"""Run the kebab agent server."""
app = build_app()

port = int(os.getenv("PORT", "8080"))
host = os.getenv("HOST", "0.0.0.0")
logger.info("Starting server on %s:%s", host, port)

uvicorn.run(
app.build(),
app,
host=host,
port=port,
log_level="info",
Expand Down
22 changes: 22 additions & 0 deletions python/samples/langgraph/kebab/tests/test_kebab_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Regression tests for the kebab console entry point."""

import importlib

from fastapi.testclient import TestClient


def test_main_passes_healthy_app_to_uvicorn(monkeypatch):
monkeypatch.setenv("OPENAI_API_KEY", "fake")
monkeypatch.setenv("KAGENT_API_URL", "http://localhost:8083")
monkeypatch.setenv("KAGENT_GATEWAY_URL", "http://localhost:8083")
monkeypatch.setenv("KAGENT_NAME", "kebab")
monkeypatch.setenv("KAGENT_NAMESPACE", "default")

cli = importlib.import_module("kebab.cli")
captured = {}
monkeypatch.setattr(cli.uvicorn, "run", lambda app, **kwargs: captured.update(app=app, kwargs=kwargs))

cli.main()

assert TestClient(captured["app"]).get("/health").text == "OK"
assert captured["kwargs"] == {"host": "0.0.0.0", "port": 8080, "log_level": "info"}
Loading