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/currency/tests/

.PHONY: build
build: update format
Expand Down
4 changes: 2 additions & 2 deletions python/samples/langgraph/currency/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/currency/currency/cli.py"]
# Run the installed console entry point so package-relative imports resolve.
CMD ["uv", "run", "--package", "currency", "currency"]
19 changes: 12 additions & 7 deletions python/samples/langgraph/currency/currency/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,41 @@
import os

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

from .agent import graph

# Configure logging
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."""
# from script directory
def build_app():
"""Build the currency agent 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,
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
32 changes: 32 additions & 0 deletions python/samples/langgraph/currency/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Regression tests for the currency console entry point."""

import importlib

from fastapi.testclient import TestClient


def test_main_passes_healthy_app_to_uvicorn(monkeypatch, tmp_path):
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", "currency")
monkeypatch.setenv("KAGENT_NAMESPACE", "default")
checkpoint_db = tmp_path / "currency-checkpoints.sqlite"
monkeypatch.setenv("KAGENT_CHECKPOINT_DB", str(checkpoint_db))

cli = importlib.import_module("currency.cli")
captured = {}

def run(app, **kwargs):
captured["app"] = app
captured["kwargs"] = kwargs

monkeypatch.setattr(cli.uvicorn, "run", run)
cli.main()

response = TestClient(captured["app"]).get("/health")

assert response.status_code == 200
assert response.text == "OK"
assert checkpoint_db.exists()
assert captured["kwargs"] == {"host": "0.0.0.0", "port": 8080, "log_level": "info"}
Loading