

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 세션에 대화 기록 및 컨텍스트 저장
<a name="sessions-store-coversation"></a>

세션을 생성한 후 [CreateInvocation](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_CreateInvocation.html) API를 사용하여 세션 내에서 상호 작용 그룹화를 생성합니다. 각 그룹화에 대해 [PutInvocationStep](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_PutInvocationStep.html) API 작업을 사용하여 각 상호 작용에 대해 텍스트 및 이미지를 포함한 상태 체크포인트를 저장합니다.

간접 호출 내에서 간접 호출 단계를 구성하는 방법은 사용 사례에 따라 다릅니다. 예를 들어, 고객이 여행을 예약할 수 있도록 도와주는 에이전트가 있는 경우 간접 호출 및 간접 호출 단계는 다음과 같을 수 있습니다.
+ 간접 호출은 에이전트가 특정 호텔 내 다른 숙박일 동안의 객실 가용성을 확인하는 고객과 나눈 대화의 텍스트에 대한 그룹화 역할을 할 수 있습니다.
+ 각 간접 호출 단계는 에이전트와 사용자 간에 나눈 각 메시지일 수 있으며, 에이전트가 가용성을 검색하기 위해 수행하는 각 단계일 수 있습니다.

[PutInvocationStep](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_PutInvocationStep.html) API에서 대화와 연결된 이미지를 가져올 수 있습니다.
+ 최대 20개의 이미지를 포함시킬 수 있습니다. 각 이미지의 크기, 높이 및 너비는 각각 3.75MB, 8000px 및 8000px 이하여야 합니다.
+ 다음 유형의 이미지를 가져올 수 있습니다.
  + PNG
  + JPEG
  + GIF
  + WEBP

**Topics**
+ [CreateInvocation 예제](#session-create-invocation)
+ [PutInvocationSteps 예제](#session-put-invocation-step)

## CreateInvocation 예제
<a name="session-create-invocation"></a>

다음 코드 예제에서는 AWS SDK for Python (Boto3)을 사용하여 활성 세션에 간접 호출을 추가하는 방법을 보여줍니다. `sessionIdentifier`의 경우 세션의 sessionId 또는 Amazon 리소스 이름(ARN)을 지정할 수 있습니다. API에 대한 자세한 내용은 [CreateInvocation](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_CreateInvocation.html)을 참조하세요.

```
def create_invocation(session_identifier):
try:
    invocationId = client.create_invocation(
        sessionIdentifier=session_identifier,
        description="User asking about weather in Seattle",
        invocationId="12345abc-1234-abcd-1234-abcdef123456"
    )["invocationId"]
    print("invocation created")
    return invocationId
except ClientError as e:
    print(f"Error: {e}")
```

## PutInvocationSteps 예제
<a name="session-put-invocation-step"></a>

다음 코드 예제에서는 AWS SDK for Python (Boto3)을 사용하여 활성 세션에 간접 호출 단계를 추가하는 방법을 보여줍니다. 코드는 작업 디렉터리에서 텍스트와 이미지를 추가합니다. `sessionIdentifier`의 경우 세션의 sessionId 또는 Amazon 리소스 이름(ARN)을 지정할 수 있습니다. 간접 호출 식별자의 경우 간접 호출 단계를 추가할 간접 호출의 고유 식별자(UUID 형식)를 지정합니다. API에 대한 자세한 내용은 [PutInvocationStep](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_PutInvocationStep.html)을 참조하세요.

```
def put_invocation_step(invocation_identifier, session_identifier):
with open('weather.png', 'rb') as image_file:
    weather_image = image_file.read()

try:
    client.put_invocation_step(
        sessionIdentifier=session_identifier,
        invocationIdentifier=invocation_identifier,
        invocationStepId="12345abc-1234-abcd-1234-abcdef123456",
        invocationStepTime="2023-08-08T12:00:00Z",
        payload={
            'contentBlocks': [
                {
                    'text': 'What\'s the weather in Seattle?',

                },
                {
                    'image': {
                        'format': 'png',
                        'source': {'bytes': weather_image}
                    }
                }

            ]
        }
    )
    print("invocation step created")
except ClientError as e:
    print(f"Error: {e}")
```