AI 에이전트 구축
Amazon Nova 모델은 Amazon Nova Act를 사용하여 AI 에이전트를 빌드하는 데 최적화되어 있습니다. 이 모델을 사용하면 도구 사용을 개선하고 여러 단계의 태스크에 대한 추론을 개선하며 여러 복잡한 에이전트 워크플로에서 컨텍스트를 유지 관리하는 기능을 향상시키고 원격 MCP 도구를 지원할 수 있습니다.
에이전트 생성
Nova로 빌드된 AI 에이전트는 여러 도구 직접 호출을 오케스트레이션하고, 확장된 여러 상호 작용에서 컨텍스트를 유지 관리하며, 필요한 경우 과정을 수정할 수 있습니다. 확장된 사고는 복잡한 목표를 통해 체계적 추론을 지원하여 에이전트 워크플로를 변환합니다. 에이전트 시스템의 계획 및 실행 프로세스를 보다 견고하게 만들려면 Strands Agents와 같은 계획 프레임워크 SDK를 사용하는 방법을 고려합니다.
에이전트 설계 패턴
Nova를 사용하여 에이전트를 설계하는 경우:
-
계획 및 확인이 필요한 복잡한 여러 단계의 워크플로에서 최상의 결과를 얻으려면 중간 또는 높은 수준의 추론 활성화
-
여러 에이전트 상호 작용에서 유연한 도구 선택을 위해 도구 선택
auto구현 -
에이전트가 수정된 접근 방식으로 복구하고 재시도할 수 있도록 설계 오류 처리
-
대화 기록을 유지 관리하여 여러 에이전트 상호 작용에서 컨텍스트 보존
-
에이전트 시스템이 사용하는 제어되지 않는 여러 콘텐츠에서 강력한 콘텐츠 필터링 및 조정 메커니즘을 구현합니다. 예를 들어 Amazon은 여러 파운데이션 모델, 지식 베이스 및 에이전트에서 보호 기능을 적용하도록 설계된 기능인 Amazon Bedrock 가드레일을 제공합니다. 이러한 가드레일은 유해한 콘텐츠를 필터링하고, 거부된 주제를 차단하며, 개인 식별 정보와 같은 민감한 정보를 삭제할 수 있습니다.
다중 도구 에이전트 예제
tool_config = { "tools": [ { "toolSpec": { "name": "calculator", "description": "Perform mathematical calculations", "inputSchema": { "json": { "type": "object", "properties": { "expression": { "type": "string", "description": "Mathematical expression to evaluate" } }, "required": ["expression"] } } } }, { "toolSpec": { "name": "database_query", "description": "Query financial database for historical data", "inputSchema": { "json": { "type": "object", "properties": { "query": { "type": "string", "description": "SQL query to execute" } }, "required": ["query"] } } } } ] } response = client.converse( modelId=" us.amazon.nova-2-lite-v1:0", messages=[{ "role": "user", "content": [{ "text": "Analyze our Q3 financial performance across all business units, calculate year-over-year growth rates with statistical significance testing, and recommend budget allocation strategies for Q4." }] }], toolConfig=tool_config, inferenceConfig={"maxTokens": 10000, "temperature": 1, “topP”: 0.9}, additionalModelRequestFields={ "reasoningConfig": { "type": "enabled", "maxReasoningEffort": "low" } } )
에이전트 간접 호출
에이전트 간접 호출에는 대화 흐름 관리, 도구 직접 호출 처리, 여러 상호 작용에서 상태 유지 관리가 포함됩니다.
에이전트 응답 스트리밍
응답을 스트리밍하여 에이전트의 추론 및 작업에 대한 실시간 가시성을 제공합니다.
import boto3 response = client.converse_stream( modelId=" us.amazon.nova-2-lite-v1:0", messages=[{ "role": "user", "content": [{ "text": "Design a scalable microservices architecture for an e-commerce platform handling 1M+ daily transactions. Consider data consistency, fault tolerance, performance, security, and cost optimization." }] }], inferenceConfig={"maxTokens": 10000, "temperature": 10}, additionalModelRequestFields={ "reasoningConfig": { "type": "enabled", "maxReasoningEffort": "low" } } ) # Process the streaming response reasoning_complete = False for event in response["stream"]: if "contentBlockDelta" in event: delta = event["contentBlockDelta"]["delta"] if "reasoningContent" in delta: reasoning_text = delta["reasoningContent"]["reasoningText"]["text"] print(f"{reasoning_text}", end="", flush=True) elif "text" in delta: if not reasoning_complete: print(f" Final Architecture Design: ") reasoning_complete = True print(f"{delta['text']}", end="", flush=True)
에이전트 상태 관리
대화 기록과 도구 결과를 유지 관리하여 컨텍스트를 보존합니다. 아래 예제에서는 싱글턴에서 이를 보여주지만 개발자는 워크플로 요구 사항에 따라 전체 에이전트 시스템을 오케스트레이션하는 방법을 결정할 수 있습니다. 또한 Strands와 같은 Amazon Web Services 도구는 개발자를 대신하여 에이전트 컨텍스트 및 도구 상태를 관리합니다.
messages = [] messages = [] # Initial user query messages.append({ "role": "user", "content": [{"text": user_query}] }) # Get agent response response = client.converse( modelId=" us.amazon.nova-2-lite-v1:0", messages=messages, toolConfig=tool_config, inferenceConfig=inf_params ) # Add assistant response to history messages.append(response["output"]["message"]) # Process tool calls and add results if response["stopReason"] == "tool_use": tool = next( block["toolUse"] for block in response["output"]["message"]["content"] if "toolUse" in block ) # Execute tool result = execute_tool(tool["name"], tool["input"]) # Add tool result to conversation messages.append({ "role": "user", "content": [{ "toolResult": { "toolUseId": tool["toolUseId"], "content": [{"json": result}], "status": "success" } }] }) # Continue conversation response = client.converse( modelId=" us.amazon.nova-2-lite-v1:0", messages=messages, toolConfig=tool_config, inferenceConfig=inf_params )
에이전트 모범 사례
에이전트 모범 사례에 대한 자세한 내용은 일반 모범 사례 섹션을 참조하세요.
대화형 AI 에이전트 개발에 대한 지침은 음성-음성(Amazon Nova 2 Sonic) 섹션을 참조하세요.