

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

# 제어 에이전트 세션 컨텍스트
<a name="agents-session-state"></a>

세션 컨텍스트를 더 효과적으로 제어하려면 에이전트에서 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_SessionState.html#bedrock-Type-agent-runtime_SessionState](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_SessionState.html#bedrock-Type-agent-runtime_SessionState) 객체를 수정하면 됩니다. [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_SessionState.html#bedrock-Type-agent-runtime_SessionState](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_SessionState.html#bedrock-Type-agent-runtime_SessionState) 객체에는 대화 턴을 통틀어 유지할 수 있는 정보가 포함되어 있습니다(별도의 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html) 요청 및 응답). 이 정보를 사용하여 사용자 대화 중에 에이전트에 대화 컨텍스트를 제공할 수 있습니다.

[https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_SessionState.html#bedrock-Type-agent-runtime_SessionState](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_SessionState.html#bedrock-Type-agent-runtime_SessionState) 객체의 일반적인 형식은 다음과 같습니다.

```
{
    "sessionAttributes": {
        "{{<attributeName1>}}": "{{<attributeValue1>"}},
        "{{<attributeName2>}}": "{{<attributeValue2>"}},
        ...
    },
     "conversationHistory": {
          "messages": [{
              "role": "user | assistant",
              "content": [{
                  "text": "string"
              }]
          }],
               },
    "promptSessionAttributes": {
        "{{<attributeName3>}}": "{{<attributeValue3>"}},
        "{{<attributeName4>}}": "{{<attributeValue4>"}},
        ...
    },
    "invocationId": "string",
    "returnControlInvocationResults": [
        [ApiResult](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_ApiResult.html) or [FunctionResult](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_FunctionResult.html),
        ...
    ],
    "knowledgeBases": [
       {
        "knowledgeBaseId": "string",
        "retrievalConfiguration": {
            "vectorSearchConfiguration": {
                "overrideSearchType": "HYBRID | SEMANTIC",
                "numberOfResults": int,
                "filter": [RetrievalFilter](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RetrievalFilter.html) object
            }
        }
       },
       ...
    ]
}
```

관련 주제를 선택하여 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_SessionState.html#bedrock-Type-agent-runtime_SessionState](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_SessionState.html#bedrock-Type-agent-runtime_SessionState) 객체의 필드에 대해 자세히 알아보세요.

**Topics**
+ [세션 및 프롬프트 세션 속성](#session-state-attributes)
+ [세션 속성 예제](#session-attribute-ex)
+ [프롬프트 세션 속성 예제](#prompt-session-attribute-ex)
+ [작업 그룹 간접 호출 결과](#session-state-return-control)
+ [지식 기반 검색 구성](#session-state-kb)

## 세션 및 프롬프트 세션 속성
<a name="session-state-attributes"></a>

Amazon Bedrock Agents를 사용하면 세션의 일부에 걸쳐 지속되는 다음과 같은 유형의 컨텍스트 속성을 정의할 수 있습니다.
+ **sessionAttributes** - 사용자와 에이전트 간의 한 [세션](advanced-prompts.md#advanced-prompts-terminology) 동안 지속되는 속성입니다. 동일한 `sessionId`로 이루어진 모든 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html) 요청은 세션 시간 제한(`idleSessionTTLinSeconds`)을 초과하지 않는 한 동일한 세션에 속합니다.
+ **conversationHistory** - 다중 에이전트 협업의 경우 `conversationalHistorySharing`이 공동 작업자 에이전트에 대해 활성화된 경우 실행 시간 요청을 처리하기 위한 추가 컨텍스트를 수락합니다. 기본적으로 이 필드는 공동 작업자 에이전트를 간접 호출할 때 감독자 에이전트에 의해 자동으로 구성됩니다. 필요에 따라 이 필드를 사용하여 추가 컨텍스트를 제공할 수 있습니다. 자세한 내용은 [Amazon Bedrock Agents에서 다중 에이전트 협업 사용](agents-multi-agent-collaboration.md) 단원을 참조하십시오.
+ **promptSessionAttributes** - 하나의 [턴](advanced-prompts.md#advanced-prompts-terminology)(한 번의 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html) 직접 호출) 동안 지속되는 속성입니다. 오케스트레이션 기본 프롬프트 템플릿을 편집할 때 $prompt\_session\_attributes$ [자리 표시자](prompt-placeholders.md)를 사용할 수 있습니다. 이 자리 표시자는 런타임 시 `promptSessionAttributes` 필드에 지정한 속성으로 채워집니다.

세션 상태 속성은 두 가지 단계로 정의할 수 있습니다.
+ 작업 그룹을 설정하고 [Lambda 함수를 작성](agents-lambda.md)할 때 Amazon Bedrock으로 반환되는 [응답 이벤트](agents-lambda.md#agents-lambda-response)에 `sessionAttributes` 또는 `promptSessionAttributes`를 포함합니다.
+ 런타임 중에 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html) 요청을 보낼 때 요청 본문에 `sessionState` 객체를 포함시켜 대화 중간에 세션 상태 속성을 동적으로 변경합니다.

## 세션 속성 예제
<a name="session-attribute-ex"></a>

다음 예제에서는 세션 속성을 사용하여 사용자에 대한 메시지를 개인화합니다.

1. 사용자에게 자신의 이름과 에이전트에게 전달하고자 하는 요청을 입력하도록 요청하고, 그 답변을 변수 {{<first\_name>}} 및 {{<request>}}로 저장하는 애플리케이션 코드를 작성합니다.

1. 다음과 같은 본문으로 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html) 요청을 보내는 애플리케이션 코드를 작성합니다.

   ```
   {
       "inputText": "{{<request>}}",
       "sessionState": {
           "sessionAttributes": {
               "firstName": "{{<first_name>}}"
           }
       }
   }
   ```

1. 사용자가 애플리케이션을 사용하고 이름을 제공하면 코드는 이름을 세션 속성으로 전송하고 에이전트는 [세션](advanced-prompts.md#advanced-prompts-terminology) 기간 동안 이름을 저장합니다.

1. 세션 속성은 [Lambda 입력 이벤트](agents-lambda.md#agents-lambda-input)에서 전송되므로 Lambda 함수에서 작업 그룹에 대해 이러한 세션 속성을 참조할 수 있습니다. 예를 들어, 작업 [API 스키마](agents-api-schema.md)의 요청 본문에 이름이 필요한 경우, 작업 그룹에 대한 Lambda 함수 작성 시 `firstName` 세션 속성을 사용하여 API 요청을 보낼 때 해당 필드를 자동으로 채울 수 있습니다.

## 프롬프트 세션 속성 예제
<a name="prompt-session-attribute-ex"></a>

다음 일반 예제에서는 프롬프트 세션 속성을 사용하여 에이전트에 대한 시간 컨텍스트를 제공합니다.

1. {{<request>}}라는 변수에 사용자 요청을 저장하는 애플리케이션 코드를 작성합니다.

1. 사용자가 {{<request>}}에서 상대적 시간을 나타내는 단어(예: '내일')를 사용하는 경우 사용자의 위치에서 시간대를 검색하고 {{<timezone>}}이라는 변수에 저장하는 애플리케이션 코드를 작성합니다.

1. 다음과 같은 본문으로 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html) 요청을 보내는 애플리케이션 코드를 작성합니다.

   ```
   {
       "inputText": "{{<request>}}",
       "sessionState": {
           "promptSessionAttributes": {
               "timeZone": "{{<timezone>}}"
           }
       }
   }
   ```

1. 사용자가 상대적 시간을 나타내는 단어를 사용하는 경우 코드는 `timeZone` 프롬프트 세션 속성을 전송하고 에이전트는 해당 [턴](advanced-prompts.md#advanced-prompts-terminology) 기간 동안 이를 저장합니다.

1. 예를 들어, 사용자가 **I need to book a hotel for tomorrow**라고 요청하는 경우 코드는 사용자의 시간대를 에이전트에 전송하고 에이전트는 'tomorrow'가 참조하는 정확한 날짜를 판단할 수 있습니다.

1. 프롬프트 세션 속성은 다음 단계에서 사용할 수 있습니다.
   + 오케스트레이션 프롬프트 템플릿에 $prompt\_session\_attributes$ [자리 표시자](prompt-placeholders.md)를 포함하면 파운데이션 모델에 대한 오케스트레이션 프롬프트에 프롬프트 세션 속성이 포함됩니다.
   + 프롬프트 세션 속성은 [Lambda 입력 이벤트](agents-lambda.md#agents-lambda-input)에서 전송되며 API 요청을 채우거나 [응답](agents-lambda.md#agents-lambda-response)에 반환하는 데 사용할 수 있습니다.

## 작업 그룹 간접 호출 결과
<a name="session-state-return-control"></a>

[[https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html) 응답에서 제어를 반환](agents-returncontrol.md)하도록 작업 그룹을 구성한 경우, 다음 필드를 포함하여 후속 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html) 응답의 `sessionState`에서 작업 그룹을 간접 호출한 결과를 보낼 수 있습니다.
+ `invocationId` – 이 ID는 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html) 응답에서 `returnControl` 필드의 [ReturnControlPayload](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_ReturnControlPayload.html) 객체에서 반환된 `invocationId`와 일치해야 합니다.
+ `returnControlInvocationResults` - 작업을 간접 호출하여 얻은 결과를 포함합니다. [ReturnControlPayload](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_ReturnControlPayload.html) 객체를 전달하여 API 요청을 수행하거나 정의한 함수를 직접 호출하도록 애플리케이션을 설정할 수 있습니다. 그런 다음 여기에 해당 작업의 결과를 제공할 수 있습니다. `returnControlInvocationResults` 목록의 각 멤버는 다음 중 하나입니다.
  + 에이전트가 예측한 API 작업을 이전 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html) 시퀀스에서 직접 호출하고 시스템에서 작업을 간접 호출한 결과를 포함하는 [ApiResult](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_ApiResult.html) 객체. 일반적인 형식은 다음과 같습니다.

    ```
    {
        "actionGroup": "string",
        "agentId" : :string",
        "apiPath": "string",
        "confirmationState" : "CONFIRM | DENY",
        "httpMethod": "string",
        "httpStatusCode": integer,
        "responseBody": {
            "TEXT": {
                "body": "string"
            }
        }
    }
    ```
  + 에이전트가 예측한 함수를 이전 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html) 시퀀스에서 직접 호출하고 시스템에서 작업을 간접 호출한 결과를 포함하는 [FunctionResult](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_FunctionResult.html) 객체. 일반적인 형식은 다음과 같습니다.

    ```
    {
        "actionGroup": "string",
        "agentId" : :string",
        "confirmationState" : "CONFIRM | DENY",
        "function": "string",
        "responseBody": {
            "TEXT": {
                "body": "string"
            }
        }
    }
    ```

제공된 결과는 추가 오케스트레이션을 위한 컨텍스트로 사용하거나, 에이전트가 응답을 포맷할 수 있도록 사후 처리로 전송하거나, 에이전트의 사용자 응답에 직접 사용할 수 있습니다.

## 지식 기반 검색 구성
<a name="session-state-kb"></a>

에이전트에 연결된 지식 기반 검색 구성을 수정하려면 구성을 지정하려는 각 지식 기반에 대한 구성 목록이 포함된 `knowledgeBaseConfigurations` 필드를 포함합니다. `knowledgeBaseId`를 지정합니다. `vectorSearchConfiguration` 필드에서 다음 쿼리 구성을 지정할 수 있습니다(이러한 구성에 대한 자세한 내용은 [쿼리와 응답 생성 구성 및 사용자 지정](kb-test-config.md) 참조).
+ **검색 유형** - 지식 기반이 벡터 임베딩(`SEMANTIC`)만 검색할지 아니면 벡터 임베딩과 원시 텍스트(`HYBRID`)를 모두 검색할지 여부입니다. `overrideSearchType` 필드를 사용하세요.
+ **검색된 결과의 최대 수** - 응답에 사용할 쿼리 검색 결과의 최대 개수입니다.
+ **메타데이터 및 필터링** - 데이터 소스 파일의 메타데이터 속성을 기반으로 결과를 필터링하도록 구성할 수 있는 필터입니다.