Team A: 에이전트 코드

분석 대상

agent_config/agent.py — TroubleshootingAgent 클래스

TroubleshootingAgent 클래스 전체 구조

from strands import Agent
from strands.models import BedrockModel
from strands.tools.mcp import MCPClient

class TroubleshootingAgent:
    def __init__(self, bearer_token, memory_hook=None,
                 bedrock_model_id="global.anthropic.claude-sonnet-4-20250514-v1:0",
                 system_prompt=None):

초기화 단계 (라인별 분석)

단계
코드
설명

1. 모델 초기화

self.model = BedrockModel(model_id=self.model_id)

Claude Sonnet 4 모델 설정

2. 시스템 프롬프트

self.system_prompt = system_prompt if system_prompt else """..."""

기본 프롬프트 또는 커스텀 프롬프트

3. Gateway URL

gateway_url = get_ssm_parameter("/app/troubleshooting/agentcore/gateway_url")

SSM에서 Gateway 엔드포인트 조회

4. MCP 클라이언트

MCPClient(lambda: streamablehttp_client(gateway_url, headers=...))

HTTP 스트리밍 기반 MCP 연결

5. 도구 등록

self.gateway_client.start()list_tools_sync()

Gateway에서 사용 가능한 도구 목록 조회

6. Agent 생성

Agent(model=self.model, system_prompt=..., tools=..., hooks=...)

Strands Agent 인스턴스 생성

BedrockModel 설정

MCP 클라이언트 초기화

MCP 프로토콜 동작:

  1. start() — Gateway와 HTTP 세션 수립

  2. list_tools_sync() — Gateway에 등록된 Lambda 도구 목록 조회

  3. 에이전트가 도구 호출 시 — MCP 클라이언트가 Gateway를 통해 Lambda 함수 실행

Agent 생성자 파라미터

파라미터
타입
설명

model

BedrockModel

LLM 모델 (Claude Sonnet 4)

system_prompt

str

에이전트 행동 규칙

tools

list

[current_time] + MCP 도구들

hooks

list

[memory_hook] (Module 3에서 추가)

스트리밍 응답

토론 질문

  1. bearer_token이 "dummy"일 때 MCP 클라이언트를 초기화하지 않는 이유는?

  2. list_tools_sync()가 반환하는 도구 목록은 어디서 정의되나요?

  3. stream_async의 이벤트 루프가 멈추는 조건은?

마지막 업데이트