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/openai/basic_agent/tests/

.PHONY: build
build: update format
Expand Down
4 changes: 2 additions & 2 deletions python/samples/openai/basic_agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ ENV PATH="/app/.venv/bin:$PATH"
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1

# Run the agent
CMD ["python", "samples/openai/basic_agent/basic_agent/agent.py"]
# Run the installed console entry point so package imports resolve.
CMD ["uv", "run", "--package", "basic-openai-agent", "basic-openai-agent"]

26 changes: 15 additions & 11 deletions python/samples/openai/basic_agent/basic_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,29 @@ def get_weather(location: str) -> str:
AgentCard(),
)

config = KAgentConfig()

# Create KAgent app
app = KAgentApp(
agent=agent,
agent_card=agent_card,
config=config,
)
def build_app():
"""Build the basic OpenAI agent ASGI application."""
return KAgentApp(
agent=agent,
agent_card=agent_card,
config=KAgentConfig(),
).build()


# Build the FastAPI application
fastapi_app = app.build()
app = build_app()


if __name__ == "__main__":
def main():
"""Run the basic OpenAI agent server."""
import uvicorn

logging.basicConfig(level=logging.INFO)
logger.info("Starting Basic OpenAI Agent...")
logger.info("Server will be available at http://0.0.0.0:8080")

uvicorn.run(fastapi_app, host="0.0.0.0", port=8080)
uvicorn.run(app, host="0.0.0.0", port=8080)


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions python/samples/openai/basic_agent/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ dependencies = [
"uvicorn>=0.51.0",
]

[project.scripts]
basic-openai-agent = "basic_agent.agent:main"

[tool.uv.sources]
kagent-openai = { workspace = true }

Expand Down
29 changes: 29 additions & 0 deletions python/samples/openai/basic_agent/tests/test_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Regression tests for the basic OpenAI agent 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", "basic-openai-agent")
monkeypatch.setenv("KAGENT_NAMESPACE", "default")

agent = importlib.import_module("basic_agent.agent")
captured = {}

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

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

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

assert response.status_code == 200
assert response.text == "OK"
assert captured["kwargs"] == {"host": "0.0.0.0", "port": 8080}
Loading