441. 대화 중 컴퓨터 사용 도구 요청 처리 (Handle computer use tool requests from agents in conversations)
- 원문: English
- 위치: Additional capabilities › Agents: Automate tasks › Configure an agent to use computer use tools › Handle computer use tool requests from agents in conversations
한 줄 요약
에이전트가 도구를 요청하면 InvokeAgent 응답에 returnControl 페이로드(도구·액션 포함)가 옵니다. 앱이 이를 실행하고 결과를 다음 InvokeAgent의 sessionState.returnControlInvocationResults로 돌려주며, returnControl이 더 이상 없으면 작업이 끝난 것입니다.
핵심 내용
요청 예 (screenshot 액션)
{
"returnControl": {
"invocationId": "invocationIdExample",
"invocationInputs": [{
"functionInvocationInput": {
"actionGroup": "my_computer",
"actionInvocationType": "RESULT",
"agentId": "agentIdExample",
"function": "computer",
"parameters": [{ "name": "action", "type": "string", "value": "screenshot" }]
}
}]
}
}
처리 루프 (원문 Python 예제 구조)
| 함수 | 역할 |
|---|---|
manage_computer_interaction | InvokeAgent 호출 → completion 이벤트 처리(chunk 출력, returnControl 파싱) → 결과를 sessionState에 담아 재호출. returnControl이 없으면 종료. 후속 호출의 inputText는 빈 문자열 |
handle_computer_action | action 값(screenshot, mouse_move, left_click, right_click)을 목(mock) 구현에 매핑 |
결과 반환 형식(핵심):
"sessionState": {
"invocationId": "<invocationId>",
"returnControlInvocationResults": [{
"functionResult": {
"actionGroup": "<actionGroup>",
"agentId": "<agentId>",
"function": "computer",
"responseState": "REPROMPT",
"responseBody": { "IMAGES": { "images": [ { "format": "png", "source": { "bytes": "<이미지 바이트>" } } ] } }
}
}]
}
- 텍스트 결과는
responseBody에{"TEXT": {"body": "..."}}형식으로 넣습니다. - 실제 도구 구현 예: GitHub
anthropics/anthropic-quickstarts의computer-use-demo. - 관련: 409 Return control
SA 관점
- 이 루프는 앱 측에서 여러 번 왕복하므로, 전체 작업 시간·호출 횟수 상한(타임아웃, 최대 반복 수)을 앱에 넣어 무한 루프와 비용 폭증을 막아야 합니다.