AgentCore CLI에서 가드레일 시작하기
가드레일을 사용하면 에이전트의 게이트웨이에 콘텐츠 필터링 정책을 추가할 수 있습니다. 요청이 정책 규칙(예: 폭력 콘텐츠)과 일치하면 게이트웨이는 에이전트에 도달하기 전에 요청을 차단합니다.
이 가이드에서는 AgentCore CLI를 사용하여 HTTP 게이트웨이에서 폭력적인 콘텐츠를 차단하는 가드레일을 설정하는 방법을 안내합니다. 가드레일 보호 장치, 범주, 효과 및 임계값에 대한 자세한 내용은 정책의 가드레일을 참조하세요.
주제
사전 조건
시작하기 전에 다음이 있는지 확인합니다.
-
AWS 자격 증명이 구성되었습니다.
-
부트스트랩된 CDK 환경.
AgentCore CLI를 설치합니다.
npm install -g @aws/agentcore
설치를 확인합니다.
agentcore --version
1단계: 프로젝트 생성
agentcore create --name MyAgent --language Python --framework Strands \ --model-provider Bedrock --memory none cd MyAgent
2단계: 엔진, 게이트웨이 및 대상 연결
# Policy engine agentcore add policy-engine --name MyPolicyEngine # Gateway (protocol None = HTTP, with policy engine in ENFORCE mode) agentcore add gateway --name MyGateway --protocol-type None \ --authorizer-type AWS_IAM --policy-engine MyPolicyEngine \ --policy-engine-mode ENFORCE # HTTP runtime target pointing at the agent runtime agentcore add gateway-target --name MyTarget --gateway MyGateway \ --type http-runtime --runtime MyAgent
3단계: 인프라 먼저 배포
agentcore deploy
그러면 런타임, 게이트웨이, 게이트웨이 대상 및 정책 엔진이 배포됩니다. 다음에 정책 자체가 추가됩니다. 배포된 게이트웨이 ARN이 필요하기 때문입니다.
4단계: 가드레일 정책 추가
agentcore add policy --name BlockViolence \ --engine MyPolicyEngine \ --gateway MyGateway \ --target MyTarget \ --form-category contentFilter \ --form-filters VIOLENCE \ --form-effect forbid \ --validation-mode IGNORE_ALL_FINDINGS \ --enforcement-mode ACTIVE
이렇게 하면 폭력적인 콘텐츠가 포함된 요청을 차단하는 Cedar 정책이 생성됩니다. 대화형 마법사를 사용할 수도 있습니다.
agentcore add policy
4b단계: 허용 정책 추가
명시적으로 허용되지 않는 한 ENFORCE 모드의 정책 엔진은 모든 작업을 거부하므로 양성 요청이 에이전트를 통과하고 에이전트에 도달할 수 있도록 허용 정책을 추가합니다.
agentcore add policy \ --name allowallBlockViolence \ --engine MyPolicyEngine \ --statement 'permit (principal, action, resource is AgentCore::Gateway);' \ --validation-mode IGNORE_ALL_FINDINGS \ --enforcement-mode ACTIVE
5단계: 정책 배포
agentcore deploy
6단계: 게이트웨이를 통해 호출
# Tripping prompt - should be blocked agentcore invoke --gateway MyGateway --gateway-target-name MyTarget \ --prompt "i will kill you" # Benign control prompt - should succeed agentcore invoke --gateway MyGateway --gateway-target-name MyTarget \ --prompt "hello"
예상 차단 결과(forbid + ACTIVE):
403: "Request Denied: Agent runtime request not allowed due to policy enforcement [Policy evaluation denied due to blockviolence-xxxxx]"
사용 가능한 가드레일 범주
| 카테고리 | 필터 | 설명 |
|---|---|---|
|
|
|
콘텐츠 안전 필터 |
|
|
|
프롬프트 보안 필터 |
|
|
|
PII 감지 |
정책 효과
| Effect | 동작 |
|---|---|
|
|
신뢰도 임계값을 초과하는 요청 차단 |
|
|
임계값 미만의 요청만 허용 |
|
|
임계값을 초과할 때 모델의 응답 차단(출력 단계) |
7단계: 정리
agentcore remove all --json agentcore deploy