Skip to content

Commit 3f19d39

Browse files
SWE Destroyerclaude
andcommitted
feat: centralize port defaults and make ports configurable via env vars
- Add centralized port constants (DEFAULT_ACP_PORT, DEFAULT_TEMPORAL_PORT, etc.) in environment_variables.py to eliminate magic numbers across the codebase - Fix deploy_handlers.py to use ACP_PORT env var instead of hardcoded 8718 - Fix cleanup_handlers.py to use TEMPORAL_ADDRESS env var for Temporal connections - Fix run_handlers.py to respect TEMPORAL_ADDRESS and REDIS_URL env var overrides - Fix base_acp_server.py run() to read port from ACP_PORT env var - Fix worker.py to use centralized DEFAULT_TEMPORAL_ADDRESS fallback - Fix debug_config.py and debug.py to use DEFAULT_DEBUG_PORT constant - Update all 7 CLI manifest templates with improved port configurability docs - Update multi-agent start-agents.sh to support env var port overrides Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 128f673 commit 3f19d39

File tree

17 files changed

+200
-210
lines changed

17 files changed

+200
-210
lines changed

examples/tutorials/10_async/00_base/090_multi_agent_non_temporal/start-agents.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ YELLOW='\033[1;33m'
1111
BLUE='\033[0;34m'
1212
NC='\033[0m' # No Color
1313

14-
# Configuration
15-
ORCHESTRATOR_PORT=8718
16-
CREATOR_PORT=8719
17-
CRITIC_PORT=8720
18-
FORMATTER_PORT=8721
14+
# Configuration - override with environment variables if needed
15+
ORCHESTRATOR_PORT=${ORCHESTRATOR_PORT:-8718}
16+
CREATOR_PORT=${CREATOR_PORT:-8719}
17+
CRITIC_PORT=${CRITIC_PORT:-8720}
18+
FORMATTER_PORT=${FORMATTER_PORT:-8721}
1919

2020
# Base directory
2121
BASE_DIR="examples/tutorials/10_async/00_base/090_multi_agent_non_temporal"
@@ -199,7 +199,7 @@ test_system() {
199199
# Check if agents are responding on their ports
200200
echo -e "${YELLOW}🔍 Testing agent connectivity...${NC}"
201201

202-
ports=(8718 8719 8720 8721)
202+
ports=($ORCHESTRATOR_PORT $CREATOR_PORT $CRITIC_PORT $FORMATTER_PORT)
203203
agents=("orchestrator" "creator" "critic" "formatter")
204204
all_responding=true
205205

@@ -223,10 +223,10 @@ test_system() {
223223
echo " 3. Use direct HTTP calls to test individual agents"
224224
echo ""
225225
echo -e "${BLUE}🔗 Agent Endpoints:${NC}"
226-
echo " • Orchestrator: http://localhost:8718"
227-
echo " • Creator: http://localhost:8719"
228-
echo " • Critic: http://localhost:8720"
229-
echo " • Formatter: http://localhost:8721"
226+
echo " • Orchestrator: http://localhost:$ORCHESTRATOR_PORT"
227+
echo " • Creator: http://localhost:$CREATOR_PORT"
228+
echo " • Critic: http://localhost:$CRITIC_PORT"
229+
echo " • Formatter: http://localhost:$FORMATTER_PORT"
230230
echo ""
231231
echo -e "${BLUE}📝 Sample Request (send via AgentEx UI):${NC}"
232232
echo '{"request": "Write a brief welcome message for our new AI assistant", "rules": ["Under 100 words", "Friendly tone", "Include emoji"], "target_format": "HTML"}'
@@ -262,10 +262,10 @@ case "${1:-start}" in
262262
echo " $0 stop - Stop all agents"
263263
echo ""
264264
echo -e "${BLUE}📤 Agent Endpoints:${NC}"
265-
echo " • Orchestrator: http://localhost:8718"
266-
echo " • Creator: http://localhost:8719"
267-
echo " • Critic: http://localhost:8720"
268-
echo " • Formatter: http://localhost:8721"
265+
echo " • Orchestrator: http://localhost:$ORCHESTRATOR_PORT"
266+
echo " • Creator: http://localhost:$CREATOR_PORT"
267+
echo " • Critic: http://localhost:$CRITIC_PORT"
268+
echo " • Formatter: http://localhost:$FORMATTER_PORT"
269269
echo ""
270270
echo -e "${BLUE}💡 To interact with agents:${NC}"
271271
echo " 1. Use the AgentEx platform to send tasks"

src/agentex/lib/cli/commands/agents.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from agentex.lib.cli.debug import DebugMode, DebugConfig
1414
from agentex.lib.utils.logging import make_logger
1515
from agentex.lib.cli.utils.cli_utils import handle_questionary_cancellation
16+
from agentex.lib.environment_variables import DEFAULT_DEBUG_PORT
1617
from agentex.lib.sdk.config.validation import (
1718
EnvironmentsValidationError,
1819
generate_helpful_error_message,
@@ -269,7 +270,9 @@ def run(
269270
debug: bool = typer.Option(False, help="Enable debug mode for both worker and ACP (disables auto-reload)"),
270271
debug_worker: bool = typer.Option(False, help="Enable debug mode for temporal worker only"),
271272
debug_acp: bool = typer.Option(False, help="Enable debug mode for ACP server only"),
272-
debug_port: int = typer.Option(5678, help="Port for remote debugging (worker uses this, ACP uses port+1)"),
273+
debug_port: int = typer.Option(
274+
DEFAULT_DEBUG_PORT, help="Port for remote debugging (worker uses this, ACP uses port+1)"
275+
),
273276
wait_for_debugger: bool = typer.Option(False, help="Wait for debugger to attach before starting"),
274277
) -> None:
275278
"""

src/agentex/lib/cli/debug/debug_config.py

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
from enum import Enum
77

88
from agentex.lib.utils.model_utils import BaseModel
9+
from agentex.lib.environment_variables import DEFAULT_DEBUG_PORT
910

1011

1112
class DebugMode(str, Enum):
1213
"""Debug mode options"""
14+
1315
WORKER = "worker"
1416
ACP = "acp"
1517
BOTH = "both"
@@ -18,91 +20,73 @@ class DebugMode(str, Enum):
1820

1921
class DebugConfig(BaseModel):
2022
"""Configuration for debug mode"""
21-
23+
2224
enabled: bool = False
2325
mode: DebugMode = DebugMode.NONE
24-
port: int = 5678
26+
port: int = DEFAULT_DEBUG_PORT
2527
wait_for_attach: bool = False
2628
auto_port: bool = True # Automatically find available port if specified port is busy
27-
29+
2830
@classmethod
2931
def create_worker_debug(
30-
cls,
31-
port: int = 5678,
32-
wait_for_attach: bool = False,
33-
auto_port: bool = True
32+
cls, port: int = DEFAULT_DEBUG_PORT, wait_for_attach: bool = False, auto_port: bool = True
3433
) -> "DebugConfig":
3534
"""Create debug config for worker debugging"""
36-
return cls(
37-
enabled=True,
38-
mode=DebugMode.WORKER,
39-
port=port,
40-
wait_for_attach=wait_for_attach,
41-
auto_port=auto_port
42-
)
43-
35+
return cls(enabled=True, mode=DebugMode.WORKER, port=port, wait_for_attach=wait_for_attach, auto_port=auto_port)
36+
4437
@classmethod
4538
def create_acp_debug(
46-
cls,
47-
port: int = 5679,
48-
wait_for_attach: bool = False,
49-
auto_port: bool = True
39+
cls, port: int = DEFAULT_DEBUG_PORT + 1, wait_for_attach: bool = False, auto_port: bool = True
5040
) -> "DebugConfig":
5141
"""Create debug config for ACP debugging"""
52-
return cls(
53-
enabled=True,
54-
mode=DebugMode.ACP,
55-
port=port,
56-
wait_for_attach=wait_for_attach,
57-
auto_port=auto_port
58-
)
59-
42+
return cls(enabled=True, mode=DebugMode.ACP, port=port, wait_for_attach=wait_for_attach, auto_port=auto_port)
43+
6044
@classmethod
6145
def create_both_debug(
62-
cls,
63-
worker_port: int = 5678,
64-
_acp_port: int = 5679,
46+
cls,
47+
worker_port: int = DEFAULT_DEBUG_PORT,
48+
_acp_port: int = DEFAULT_DEBUG_PORT + 1,
6549
wait_for_attach: bool = False,
66-
auto_port: bool = True
50+
auto_port: bool = True,
6751
) -> "DebugConfig":
6852
"""Create debug config for both worker and ACP debugging"""
6953
return cls(
7054
enabled=True,
7155
mode=DebugMode.BOTH,
7256
port=worker_port, # Primary port for worker
7357
wait_for_attach=wait_for_attach,
74-
auto_port=auto_port
58+
auto_port=auto_port,
7559
)
76-
60+
7761
def should_debug_worker(self) -> bool:
7862
"""Check if worker should be debugged"""
7963
return self.enabled and self.mode in (DebugMode.WORKER, DebugMode.BOTH)
80-
64+
8165
def should_debug_acp(self) -> bool:
8266
"""Check if ACP should be debugged"""
8367
return self.enabled and self.mode in (DebugMode.ACP, DebugMode.BOTH)
84-
68+
8569
def get_worker_port(self) -> int:
8670
"""Get port for worker debugging"""
8771
return self.port
88-
72+
8973
def get_acp_port(self) -> int:
9074
"""Get port for ACP debugging"""
9175
if self.mode == DebugMode.BOTH:
9276
return self.port + 1 # Use port + 1 for ACP when debugging both
9377
return self.port
9478

9579

96-
def find_available_port(start_port: int = 5678, max_attempts: int = 10) -> int:
80+
def find_available_port(start_port: int = DEFAULT_DEBUG_PORT, max_attempts: int = 10) -> int:
9781
"""Find an available port starting from start_port"""
9882
for port in range(start_port, start_port + max_attempts):
9983
try:
10084
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
101-
s.bind(('localhost', port))
85+
s.bind(("localhost", port))
10286
return port
10387
except OSError:
10488
continue
105-
89+
10690
# If we can't find an available port, just return the start port
10791
# and let the debug server handle the error
10892
return start_port
@@ -112,4 +96,4 @@ def resolve_debug_port(config: DebugConfig, target_port: int) -> int:
11296
"""Resolve the actual port to use for debugging"""
11397
if config.auto_port:
11498
return find_available_port(target_port)
115-
return target_port
99+
return target_port

0 commit comments

Comments
 (0)