SDK 통합을 사용하여 AWS Strands Agent를 AgentCore Runtime에 통합하는 가이드
Source: Dev.to
사전 요구 사항
AgentCore에는 두 가지 배포 접근 방식이 있습니다:
- SDK 통합 – 자동 HTTP 설정 및 내장 배포 옵션 제공.
- 맞춤형 – 수동 구성.
SDK 통합
SDK를 사용하여 AWS Strands Agent를 AgentCore 런타임에 통합합니다.
설치
pip install bedrock-agentcore
에이전트 생성
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from strands import Agent
app = BedrockAgentCoreApp()
agent = Agent()
@app.entrypoint
def invoke(payload):
"""Process user input and return a response."""
user_message = payload.get("prompt", "Hello")
result = agent(user_message)
return {"result": result.message}
if __name__ == "__main__":
app.run()
에이전트 테스트
스크립트를 로컬에서 실행합니다:
python my_agent.py
curl을 사용해 엔드포인트를 테스트합니다:
curl -X POST http://localhost:8080/invocations \
-H "Content-Type: application/json" \
-d '{"prompt": "Hello world!"}'
배포 방법 선택
StarterToolkit 사용 (방법 1 – 빠른 프로토타이핑)
디렉터리 구조:
your_project_directory/
│ __init__.py # Makes the directory a Python package
│ requirements.txt
Note:
agentcore launch --local명령은 로컬 테스트를 위해 컨테이너 엔진(Docker, Finch, 또는 Podman)이 필요합니다. 이 단계는 선택 사항이며, 로컬 테스트가 필요하지 않은 경우 바로agentcore launch를 사용해 AWS에 배포할 수 있습니다.
Boto3 사용 (방법 2 – 수동 배포)
배포 과정을 더 세밀하게 제어하려면:
- 코드를 컨테이너 이미지로 패키징합니다.
- 이미지를 Amazon Elastic Container Registry (ECR)에 푸시합니다.
- Boto3 스크립트 또는 AWS SDK 호출을 사용해 배포합니다.