Skip to content
This repository was archived by the owner on Nov 12, 2026. It is now read-only.

fix: Read HOST and PORT from env vars instead of hardcoding - #254

Merged
huang195 merged 4 commits into
mainfrom
fix/respect-port-env-var
Apr 21, 2026
Merged

huang195 merged 4 commits into
mainfrom
fix/respect-port-env-var

Conversation

@huang195

Copy link
Copy Markdown
Member

Summary

  • All 8 A2A agent examples now read HOST and PORT from environment variables in their run() functions
  • Defaults unchanged: 0.0.0.0:8000 — no behavior change for existing deployments

Context

The kagenti operator's proxy-sidecar mode uses port-stealing: the reverse proxy takes over the agent's original port (e.g. 8000), and the agent is moved to a free port via the PORT env var. Agents that ignore PORT fail with address already in use because both the reverse proxy and the agent try to bind to 8000.

Agents fixed

  • cheerup_agent
  • file_organizer
  • generic_agent
  • image_service
  • recipe_agent
  • reservation_service
  • trivia_agent
  • weather_service

Assisted-By: Claude (Anthropic AI) [email protected]

All A2A agent examples hardcoded host=0.0.0.0 and port=8000 in
their run() functions. The kagenti operator's proxy-sidecar mode
uses port-stealing — it sets the PORT env var to move the agent
to a free port so the reverse proxy can take over the original
port. Agents that ignore PORT fail with 'address already in use'.

Now all 8 agents read HOST and PORT from environment variables
with the same defaults (0.0.0.0:8000), so they work with both
envoy-sidecar mode (no env vars set, uses defaults) and
proxy-sidecar mode (operator sets PORT to the relocated port).

Signed-off-by: Hai Huang <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
…cher

Read PORT env var instead of SERVICE_PORT to align with the
operator's port-stealing convention. Also fixes a bug in
slack_researcher/config.py that was reading SERVICE_URL instead
of SERVICE_PORT.

Updated: config.py, .env files, .env.template, README.md for
both agents.

Signed-off-by: Hai Huang <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
@huang195
huang195 requested a review from a team as a code owner April 21, 2026 10:35
huang195 added a commit to rossoctl/cortex that referenced this pull request Apr 21, 2026
Aligns with rossoctl/examples#254 which renamed the env var
from SERVICE_PORT to PORT across all agents. The operator sets PORT
during proxy-sidecar port-stealing.

Signed-off-by: Hai Huang <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
Remove --host and --port CLI args from CMD since run() reads
HOST and PORT env vars directly. Add EXPOSE 8000 for documentation
and a comment explaining the PORT env var convention and operator
port-stealing.

Signed-off-by: Hai Huang <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
EXPOSE is purely documentation and has no effect in Kubernetes.
Removing it and the associated comments to avoid confusion since
the actual port is controlled by the PORT env var at runtime.

Signed-off-by: Hai Huang <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>

@esnible esnible left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This was much needed.

Please take over and close #208

@huang195
huang195 merged commit fc41da8 into main Apr 21, 2026
10 checks passed
@huang195
huang195 deleted the fix/respect-port-env-var branch April 21, 2026 13:35
huang195 added a commit to huang195/kagenti-extensions that referenced this pull request May 5, 2026
Aligns with rossoctl/examples#254 which renamed the env var
from SERVICE_PORT to PORT across all agents. The operator sets PORT
during proxy-sidecar port-stealing.

Signed-off-by: Hai Huang <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants