Study guide

4.4 Tool Calling, FM API Resilience & Model Routing

AWS Certified Generative AI Developer - Professional AIP-C01

Track your progress as you read

Finished sections get a check mark.

1 Chapter 1: Exam Overview & Foundation Model Fundamentals

1.1 AIP-C01 Exam Structure, Logistics & Passing Strategy 1.2 AIP-C01 Scoring & Professional Decision Strategy 1.3 Foundation Model Landscape & Model Selection on Amazon Bedrock 1.4 Model Abstraction, Controlled Switching & Resilience 1.5 Customization Spectrum: Prompting vs RAG vs Fine-Tuning vs Continued Pre-training 1.6 Custom Model Deployment & Lifecycle Management

2 Chapter 2: Bedrock Knowledge Bases & RAG Architectures

2.1 Managed RAG Architecture with Bedrock Knowledge Bases 2.2 Knowledge Source Integration, Synchronization & Freshness 2.3 Data Ingestion, Parsing & Chunking Strategies 2.4 Embedding Models & Vector Representations 2.5 Vector Index Scale, Migration & Retrieval Evaluation 2.6 Vector Database Selection: OpenSearch Serverless vs Aurora pgvector vs Managed Stores 2.7 Vector Store Security, Multi-Tenancy & Connectivity

3 Chapter 3: Advanced Vector Search, Indexing & Data Compliance

3.1 Hybrid Search, Metadata Filtering & Semantic Reranking 3.2 Metadata Filtering, Reranking & Query Transformation 3.3 Fine-Tuning & Continued Pre-Training Data Pipeline Engineering 3.4 Data Validation, Multimodal Processing & Model Formatting 3.5 Data Privacy, Data Residency & Compliance Governance 3.6 Privacy Preservation, Source Lineage & Audit Evidence

4 Chapter 4: Prompt Engineering & Bedrock Runtime APIs

4.1 Advanced Prompt Engineering Techniques & Inference Parameters 4.2 Inference Parameters, Prompt Governance & Regression 4.3 Converse API vs InvokeModel API & Message Formatting 4.4 Tool Calling, FM API Resilience & Model Routing 4.5 Streaming Architectures & Asynchronous Event Processing 4.6 Resilient Streaming, Deployment & Asynchronous Processing

5 Chapter 5: Amazon Bedrock Agents & Tool Integration

5.1 Agentic Architecture, ReAct Reasoning Loops & Orchestration 5.2 Agent Frameworks, MCP & Lifecycle Management 5.3 Action Groups, OpenAPI Schemas & AWS Lambda Integration 5.4 Agent Memory, Session State & Multi-Agent Collaboration Patterns 5.5 Persistent State & Multi-Agent Coordination 5.6 Advanced Agent Prompt Templates & Flow Customization 5.7 Agent Safeguards, Tool Reliability & Cost Control

6 Chapter 6: Workflow Orchestration & Application Integration

6.1 Amazon Bedrock Prompt Flows & Visual Orchestration 6.2 Step Functions Orchestration & Human-in-the-Loop Workflows 6.3 Enterprise Integration: API Gateway, AppSync, and EventBridge 6.4 Hybrid Integration, GenAI Gateways & CI/CD Tooling

7 Chapter 7: AI Safety & Guardrails for Amazon Bedrock

7.1 Guardrails Architecture, Denied Topics & Content Filters 7.2 Content Safety, Defense in Depth & Threat Detection 7.3 Sensitive Information Filters & PII Redaction/Masking 7.4 Contextual Grounding Checks & Hallucination Prevention

8 Chapter 8: Security, Access Control & Network Architecture

8.1 IAM Least Privilege & Resource Policies for Bedrock 8.2 PrivateLink VPC Endpoints & Network Isolation 8.3 Encryption with AWS KMS & Cross-Account Access Patterns

9 Chapter 9: Governance, Auditing & Operational Logging

9.1 SageMaker Model Cards & AI Governance Frameworks 9.2 Lineage, Fairness, Transparency & Continuous Governance 9.3 Invocation Logging, CloudTrail Auditing & Observability 9.4 Responsible AI, Bias Mitigation & Red Teaming Methodologies

10 Chapter 10: Performance, Throughput & Cost Optimization

10.1 On-Demand vs Provisioned Throughput & Capacity Planning 10.2 Capacity Measurement, Scaling Patterns & Resilience 10.3 Batch Inference & Bedrock Intelligent Prompt Routing 10.4 Intelligent Prompt Routing & Application Eligibility 10.5 Prompt Caching, Token Optimization & Latency Reduction

11 Chapter 11: Testing, Evaluation & Troubleshooting GenAI Solutions

11.1 Amazon Bedrock Model Evaluation (Automatic & Human Workflows) 11.2 Human, RAG & Continuous Evaluation 11.3 Evaluation Metrics & RAG Quality Benchmarking (Ragas, ROUGE, BLEU) 11.4 RAG and Agent Performance Evaluation 11.5 CloudWatch Metrics, Throttling & Operational Observability 11.6 Quota Diagnosis, Retry Control & Operational Troubleshooting 11.7 Troubleshooting Common GenAI Failure Modes & Agent Traces 11.8 Prompt Maintenance, Content Handling & Deployment Validation

4.4 Tool Calling, FM API Resilience & Model Routing

Key Takeaways Explain This Topic AI

A tool request from a model is proposed data; application code validates and executes it.

Bound API calls with schema validation, deadlines, backoff with jitter, and total retry budgets.

Enforce modality, tenant, residency, and feature eligibility before dynamic model routing.

Last updated: September 2026

  • 4.4 Tool Calling, FM API Resilience & Model Routing
  • Tool / Function Calling with the Converse API

One of the most powerful features of the Converse API is its native, unified tool-calling interface . Tool calling allows a foundation model to recognize when external data or computation is required (e.g., checking database records, invoking a REST API, or running mathematical scripts) and emit structured parameters for external execution.

Important

Client-Side Tool Execution vs. Bedrock Agents : A vital exam distinction: In the Converse API, Amazon Bedrock does NOT execute the tool code . Bedrock merely determines which tool to call and outputs the validated JSON input parameters. The client application must intercept this request, execute the local code, database query, or Lambda function, and return the execution output back to Bedrock as a toolResult message. ┌─────────────────────────────────────────────────────────────────────────────┐

  • │ CONVERSE API TOOL USE CYCLE │
  • ├─────────────────────────────────────────────────────────────────────────────┤
  • │ 1. Client sends User Prompt + Tool Specifications (toolConfig) │
  • │ │ │
  • │ ▼ │
  • │ 2. Bedrock Model evaluates prompt and decides to invoke a tool │
  • │ │ │
  • │ ▼ │
  • │ 3. Bedrock returns Response: stopReason = 'tool_use' │
  • │ Payload: contentBlock containing toolUse (toolUseId, name, input) │
  • │ │ │
  • │ ▼ │
  • │ 4. Client application executes local tool logic (e.g. SQL Query) │
  • │ │ │
  • │ ▼ │
  • │ 5. Client calls Converse API again with 3 messages in history: │
  • │ - Original user prompt │
  • │ - Assistant response containing toolUse block │
  • │ - New user message containing toolResult block matching toolUseId │
  • │ │ │
  • │ ▼ │
  • │ 6. Bedrock Model synthesizes final grounded answer (stopReason = 'end_turn')│
  • └─────────────────────────────────────────────────────────────────────────────┘
  • Step 1: Defining the Tool Schema in toolConfig
  • Tools are declared using JSON Schema definitions inside the toolConfig structure: {
  • "toolConfig": {
  • "tools": [
  • {
  • "toolSpec": {
  • "name": "get_customer_account_balance",
  • "description": "Retrieves real-time checking and savings balance for a verified customer ID.",
  • "inputSchema": {
  • "json": {
  • "type": "object",
  • "properties": {
  • "customer_id": {
  • "type": "string",
  • "description": "The 8-digit alphanumeric customer identifier."
  • },
  • "account_type": {
  • "type": "string",
  • "enum": ["CHECKING", "SAVINGS", "INVESTMENT"],
  • "description": "The specific account category."
  • }
  • },
  • "required": ["customer_id", "account_type"]
  • }
  • }
  • }
  • }
  • ],
  • "toolChoice": {
  • "auto": {}
  • }
  • }
  • }
  • toolChoice Configuration Modes

auto : The model autonomously determines whether to call a tool or respond with regular conversational text.

any : Forces the model to call at least one of the provided tools, preventing direct conversational responses.

tool : Forces the model to invoke one specific, designated tool (e.g., "tool": {"name": "get_customer_account_balance"} ).

Step 2: Handling the Model's toolUse Response

When the model decides to invoke a tool, the HTTP response contains:

  • stopReason : "tool_use"
  • output.message.content : Contains a toolUse block with an auto-generated toolUseId : {
  • "stopReason": "tool_use",
  • "output": {
  • "message": {
  • "role": "assistant",
  • "content": [
  • {
  • "text": "Checking balance records for customer CUST-8492."
  • },
  • {
  • "toolUse": {
  • "toolUseId": "tooluse_01AB987XYZ",
  • "name": "get_customer_account_balance",
  • "input": {
  • "customer_id": "CUST-8492",
  • "account_type": "CHECKING"
  • }
  • }
  • }
  • ]
  • }
  • }
  • }
  • Step 3: Returning the toolResult to Converse

The client application executes the backend function and submits the conversation history back to the Converse API. Crucially, the tool result must be encapsulated inside a user role turn : import boto3

bedrock_runtime = boto3.client("bedrock-runtime", region_name="us-east-1")

  • messages = [
  • {"role": "user", "content": [{"text": "What is the checking balance for customer CUST-8492?"}]},
  • {"role": "assistant", "content": [
  • {"text": "Checking balance records for customer CUST-8492."},
  • {"toolUse": {
  • "toolUseId": "tooluse_01AB987XYZ",
  • "name": "get_customer_account_balance",
  • "input": {"customer_id": "CUST-8492", "account_type": "CHECKING"}
  • }}
  • ]},
  • {"role": "user", "content": [
  • {"toolResult": {
  • "toolUseId": "tooluse_01AB987XYZ",
  • "content": [{"json": {"balance": 14850.75, "currency": "USD", "status": "ACTIVE"}}],
  • "status": "success"
  • }}
  • ]}
  • ]
  • response = bedrock_runtime.converse(
  • modelId="anthropic.claude-3-5-sonnet-20241022-v2:0",
  • messages=messages
  • )
  • # Final response: "The checking account balance for customer CUST-8492 is $14,850.75 USD."
  • InvokeModel vs. Converse API Comparison

Architectural Dimension InvokeModel API Converse API

Model Portability Low. Payloads tightly coupled to vendor parameters. High. Unified request and response schemas across all models.

Multi-turn Chat Manual string manipulation or model-specific message arrays. Native messages array with strict role validation.

System Prompts Model-specific (e.g. Anthropic system , Titan inputText ). Standardized top-level system block across all models.

Inference Config Disparate keys ( max_tokens , max_gen_len , maxTokenCount ). Unified inferenceConfig ( maxTokens , temperature , topP , stopSequences ).

Tool / Function Calling Requires bespoke formatting per model family. Standardized toolConfig ( toolSpec , toolChoice , toolUse , toolResult ).

Multimodal Ingestion Custom base64 JSON wrappers per provider. Standardized content blocks ( image , document , text ).

  • Streaming Variant InvokeModelWithResponseStream ConverseStream
  • Exam Scenarios & Common Traps
  • Real-World Exam Scenario

A multinational insurance firm maintains a customer service orchestration engine on AWS Lambda. The application currently routes claims inquiries to Anthropic Claude 3.5 Sonnet using InvokeModel . The engineering team decides to implement dynamic model routing to send simple questions to Meta Llama 3 8B and complex policy queries to Claude 3.5 Sonnet. When changing the modelId to Llama 3, the Lambda function throws execution exceptions because Llama rejects the anthropic_version and messages payload syntax.

Architecture Solution :

Refactor the Lambda integration to utilize the Amazon Bedrock Converse API ( bedrock_runtime.converse ). The standardized payload structure allows the Lambda function to dynamically set modelId to either meta.llama3-8b-instruct-v1:0 or anthropic.claude-3-5-sonnet-20241022-v2:0 with zero changes to request serialization, system prompts, inference parameters, or response parsing logic.

Common Architectural Traps

Trap 1: Placing System Prompts in the messages Array : In the Converse API, attempting to pass {"role": "system", "content": ...} inside the messages array results in an immediate ValidationException . System prompts must always be defined in the dedicated top-level system parameter.

Trap 2: Consecutive Same-Role Messages : Sending two user messages back-to-back will cause Bedrock to fail the request. All inputs for a single turn must be aggregated as elements of the content list in a single user turn.

Trap 3: Expecting Bedrock to Invoke External Code : Assuming that defining a tool in toolConfig causes Bedrock to execute an AWS Lambda function automatically. The Converse API only emits the structured toolUse JSON. Autonomous serverless execution is the responsibility of Amazon Bedrock Agents, not the raw Converse API.

FM API resilience and model routing

Treat the foundation-model call as a distributed dependency. Validate request size and schema, set connect and read deadlines, classify retryable errors, use exponential backoff with jitter, and bound total attempts. Streaming clients must handle an error after partial output without presenting an incomplete structure as final.

Static routing maps known request classes to eligible targets. Dynamic routing can use Step Functions, application metrics, or a Bedrock prompt router for supported model pairs. The eligibility layer must run first: modality, tenant entitlement, residency, tool support, and safety policy are not optional quality preferences. AWS X-Ray can trace the surrounding API Gateway, Lambda, queue, and tool calls, while Bedrock request IDs and CloudWatch metrics support correlation at the managed service boundary.