Team A: Host Agent 구현

분석 대상

a2a-collaborator-agent/agent.py — HostAgent 클래스 (860줄)

HostAgent 클래스 구조

class HostAgent:
    def __init__(self, bearer_token, memory_hook=None,
                 bedrock_model_id="global.anthropic.claude-sonnet-4-20250514-v1:0"):
        # Rate Limiting
        self._bedrock_semaphore = Semaphore(2)      # 동시 2개 API 호출
        self._last_api_call_time = 0
        self._min_delay_between_calls = 1.0         # 최소 1초 간격

        # 원격 에이전트 관리
        self.remote_agent_connections = {}           # name → RemoteAgentConnections
        self.cards = {}                              # name → AgentCard
        self.completed_requests = set()              # 중복 방지

        # 도구: current_time + send_message_tool
        @tool
        async def send_message_tool(agent_name: str, task: str) -> str:
            return await self._send_message_impl(agent_name, task)
        self.tools = [current_time, send_message_tool]

_async_init_components: 원격 에이전트 검색

Semaphore 기반 Rate Limiting

Rate Limiting 메커니즘 비교

메커니즘
구현
위치

asyncio.Semaphore(2)

동시 호출 제한

stream()

Min Delay

호출 간 1초 대기

stream()

Exponential Backoff

2s→4s→8s

stream() 재시도

Duplicate Prevention

completed_requests set

_send_message_impl()

BedrockAgentCoreApp 엔트리포인트

토론 질문

  1. Semaphore(2)Semaphore(5)로 변경하면 어떤 영향이 있나요?

  2. completed_requests가 메모리에서만 관리되므로, 컨테이너 재시작 시 어떻게 되나요?

  3. _async_init_components가 실패하면 에이전트가 어떻게 동작하나요?

마지막 업데이트