Skip to content

Tool Calling

Use Nova reasoning models to intelligently select and use tools to accomplish complex tasks.

System Prompt Template

  You are an expert {domain} assistant who can use available tools to {accomplish goal}.
  Use the appropriate tools to complete the requested task efficiently and provide comprehensive results.

User Prompt Template

  {task description}

  Ask clarifying questions if needed.

Example

Amazon Nova 2 Lite System Prompt

  You are an expert data analyst who can use available tools to analyze datasets and generate insights.
  Use the appropriate tools to complete the requested analysis efficiently and provide comprehensive results.

Amazon Nova 2 Lite User Prompt

  Analyze the sales performance for Q4 2024 and create a summary report with visualizations.

  The sales database contains tables: orders, customers, products, and sales_reps.
  Focus on revenue trends, top-performing products, and regional performance.

Tool Configuration

  Tools available via Bedrock toolConfig:
  - query_database: Execute SQL queries against the sales database
  - create_chart: Generate charts from data (bar, line, pie, scatter)
  - calculate_statistics: Calculate statistical measures (mean, median, growth rates)

Amazon Nova 2 Lite Sample Response

Response

I'll help you analyze the sales performance for Q4 2024. Let me start by gathering the relevant data from the sales database. First, I'll need to understand the structure and get the Q4 2024 sales data.

Let me begin by examining the tables to understand their structure and then query the relevant data for Q4 2024.

# First, let me check the table structures to understand what data is available
query_database("""
SELECT table_name, column_name, data_type 
FROM information_schema.columns 
WHERE table_name IN ('orders', 'customers', 'products', 'sales_reps')
ORDER BY table_name, ordinal_position;
""")

Let me now query the sales data for Q4 2024 (October, November, December 2024):

# Get Q4 2024 sales data
query_database("""
SELECT 
    o.order_id,
    o.order_date,
    o.total_amount AS revenue,
    o.quantity,
    c.region,
    c.customer_name,
    p.product_name,
    p.category,
    sr.rep_name,
    sr.territory
FROM 
    orders o
JOIN 
    customers c ON o.customer_id = c.customer_id
JOIN 
    products p ON o.product_id = p.product_id
JOIN 
    sales_reps sr ON o.rep_id = sr.rep_id
WHERE 
    o.order_date BETWEEN '2024-10-01' AND '2024-12-31'
ORDER BY 
    o.order_date;
""")

Let me also get some summary data to understand the overall performance:

# Get summary statistics for Q4 2024
query_database("""
SELECT 
    COUNT(*) AS total_orders,
    SUM(total_amount) AS total_revenue,
    AVG(total_amount) AS average_order_value,
    MIN(total_amount) AS min_order_value,
    MAX(total_amount) AS max_order_value
FROM 
    orders
WHERE 
    order_date BETWEEN '2024-10-01' AND '2024-12-31';
""")

Now let me get data for month-over-month revenue trends:

# Get monthly revenue trends for Q4 2024
query_database("""
SELECT 
    DATE_TRUNC('month', order_date) AS month,
    COUNT(*) AS total_orders,
    SUM(total_amount) AS total_revenue,
    AVG(total_amount) AS avg_order_value
FROM 
    orders
WHERE 
    order_date BETWEEN '2024-10-01' AND '2024-12-31'
GROUP BY 
    DATE_TRUNC('month', order_date)
ORDER BY 
    month;
""")

Let me also get top-performing products:

# Get top-performing products by revenue in Q4 2024
query_database("""
SELECT 
    p.product_name,
    p.category,
    COUNT(o.order_id) AS total_orders,
    SUM(o.total_amount) AS total_revenue,
    AVG(o.total_amount) AS avg_order_value
FROM 
    orders o
JOIN 
    products p ON o.product_id = p.product_id
WHERE 
    o.order_date BETWEEN '2024-10-01' AND '2024-12-31'
GROUP BY 
    p.product_name, p.category
ORDER BY 
    total_revenue DESC
LIMIT 10;
""")

And let me get regional performance data:

# Get regional performance for Q4 2024
query_database("""
SELECT 
    c.region,
    COUNT(o.order_id) AS total_orders,
    SUM(o.total_amount) AS total_revenue,
    AVG(o.total_amount) AS avg_order_value
FROM 
    orders o
JOIN 
    customers c ON o.customer_id = c.customer_id
WHERE 
    o.order_date BETWEEN '2024-10-01' AND '2024-12-31'
GROUP BY 
    c.region
ORDER BY 
    total_revenue DESC;
""")

Let me also check if there's any comparison data with previous quarters to provide context:

# Compare Q4 2024 with previous quarters
query_database("""
WITH quarterly_data AS (
    SELECT 
        DATE_TRUNC('quarter', order_date) AS quarter,
        COUNT(*) AS total_orders,
        SUM(total_amount) AS total_revenue,
        AVG(total_amount) AS avg_order_value
    FROM 
        orders
    WHERE 
        order_date BETWEEN '2024-01-01' AND '2024-12-31'
    GROUP BY 
        DATE_TRUNC('quarter', order_date)
    ORDER BY 
        quarter
)
SELECT 
    quarter,
    total_orders,
    total_revenue,
    avg_order_value,
    LAG(total_revenue) OVER (ORDER BY quarter) AS prev_quarter_revenue,
    (total_revenue - LAG(total_revenue) OVER (ORDER BY quarter)) / LAG(total_revenue) OVER (ORDER BY quarter) * 100 AS growth_rate
FROM 
    quarterly_data;
""")

Now I'll retrieve all this data and create visualizations and a comprehensive report.

Let me start by retrieving all the data:

# Retrieving all the data for analysis
q4_sales_data = query_database("""
SELECT 
    o.order_id,
    o.order_date,
    o.total_amount AS revenue,
    o.quantity,
    c.region,
    c.customer_name,
    p.product_name,
    p.category,
    sr.rep_name,
    sr.territory
FROM 
    orders o
JOIN 
    customers c ON o.customer_id = c.customer_id
JOIN 
    products p ON o.product_id = p.product_id
JOIN 
    sales_reps sr ON o.rep_id = sr.rep_id
WHERE 
    o.order_date BETWEEN '2024-10-01' AND '2024-12-31'
ORDER BY 
    o.order_date;
""")

q4_summary = query_database("""
SELECT 
    COUNT(*) AS total_orders,
    SUM(total_amount) AS total_revenue,
    AVG(total_amount) AS average_order_value,
    MIN(total_amount) AS min_order_value,
    MAX(total_amount) AS max_order_value
FROM 
    orders
WHERE 
    order_date BETWEEN '2024-10-01' AND '2024-12-31';
""")

monthly_trends = query_database("""
SELECT 
    DATE_TRUNC('month', order_date) AS month,
    COUNT(*) AS total_orders,
    SUM(total_amount) AS total_revenue,
    AVG(total_amount) AS avg_order_value
FROM 
    orders
WHERE 
    order_date BETWEEN '2024-10-01' AND '2024-12-31'
GROUP BY 
    DATE_TRUNC('month', order_date)
ORDER BY 
    month;
""")

top_products = query_database("""
SELECT 
    p.product_name,
    p.category,
    COUNT(o.order_id) AS total_orders,
    SUM(o.total_amount) AS total_revenue,
    AVG(o.total_amount) AS avg_order_value
FROM 
    orders o
JOIN 
    products p ON o.product_id = p.product_id
WHERE 
    o.order_date BETWEEN '2024-10-01' AND '2024-12-31'
GROUP BY 
    p.product_name, p.category
ORDER BY 
    total_revenue DESC
LIMIT 10;
""")

regional_performance = query_database("""
SELECT 
    c.region,
    COUNT(o.order_id) AS total_orders,
    SUM(o.total_amount) AS total_revenue,
    AVG(o.total_amount) AS avg_order_value
FROM 
    orders o
JOIN 
    customers c ON o.customer_id = c.customer_id
WHERE 
    o.order_date BETWEEN '2024-10-01' AND '2024-12-31'
GROUP BY 
    c.region
ORDER BY 
    total_revenue DESC;
""")

quarterly_comparison = query_database("""
WITH quarterly_data AS (
    SELECT 
        DATE_TRUNC('quarter', order_date) AS quarter,
        COUNT(*) AS total_orders,
        SUM(total_amount) AS total_revenue,
        AVG(total_amount) AS avg_order_value
    FROM 
        orders
    WHERE 
        order_date BETWEEN '2024-01-01' AND '2024-12-31'
    GROUP BY 
        DATE_TRUNC('quarter', order_date)
    ORDER BY 
        quarter
)
SELECT 
    quarter,
    total_orders,
    total_revenue,
    avg_order_value,
    LAG(total_revenue) OVER (ORDER BY quarter) AS prev_quarter_revenue,
    (total_revenue - LAG(total_revenue) OVER (ORDER BY quarter)) / LAG(total_revenue) OVER (ORDER BY quarter) * 100 AS growth_rate
FROM 
    quarterly_data;
""")

Now I'll analyze this data and create visualizations. Let me start by examining the data structure and then creating the visualizations:

Q4 2024 Sales Performance Analysis

Executive Summary

Based on the Q4 2024 sales data, here's a comprehensive analysis of performance across key metrics:

Key Performance Highlights

Overall Performance: - Total Revenue: $[{q4_summary[0]['total_revenue']:,.2f}] - Total Orders: {q4_summary[0]['total_orders']} orders - Average Order Value: $[{q4_summary[0]['average_order_value']:,.2f}] - Revenue Growth: Compared to Q3 2024, revenue increased by [{quarterly_comparison[3]['growth_rate']:.2f}%]

Monthly Trend Analysis

Revenue by Month

Let me create a line chart showing the monthly revenue trend for Q4 2024:

```python

Create monthly revenue trend chart

monthly_data = [ {'month': row['month'], 'revenue': row['total_revenue']} for row in monthly_trends ]

create_chart( data=monthly_data, chart_type='line'

API Request

import boto3
import json

# Initialize the Bedrock Runtime client
bedrock_runtime = boto3.client('bedrock-runtime', region_name='us-west-2')

# Define the system prompt
system_prompt = """You are an expert data analyst who can use available tools to analyze datasets and generate insights.
  Use the appropriate tools to complete the requested analysis efficiently and provide comprehensive results."""

# Define the user prompt
user_prompt = """Analyze the sales performance for Q4 2024 and create a summary report with visualizations.

  The sales database contains tables: orders, customers, products, and sales_reps.
  Focus on revenue trends, top-performing products, and regional performance."""

# Prepare the request
request_body = {
    "system": [
        {
            "text": system_prompt
        }
    ],
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "text": user_prompt
                }
            ]
        }
    ],
    "toolConfig": {
        "tools": [
            {
                "systemTool": {
                    "name": "nova_grounding"
                }
            },
            {
                "systemTool": {
                    "name": "nova_code_interpreter"
                }
            }
        ]
    },
    "additionalModelRequestFields": {
        "reasoningConfig": {
            "type": "enabled",
            "maxReasoningEffort": "low"
        }
    },
    "inferenceConfig": {
        "temperature": 0.3,
        "topP": 0.9,
        "maxTokens": 10000
    }
}

# Make the API call
response = bedrock_runtime.converse(
    modelId="amazon.nova-2-lite-v1:0",
    **request_body
)

# Print the response
print(json.dumps(response, indent=2, default=str))
#!/bin/bash

aws bedrock-runtime converse \
    --model-id amazon.nova-2-lite-v1:0 \
    --region us-west-2 \
    --messages '[
        {
            "role": "user",
            "content": [
                {
                    "text": "Analyze the sales performance for Q4 2024 and create a summary report with visualizations.\n\nThe sales database contains tables: orders, customers, products, and sales_reps.\nFocus on revenue trends, top-performing products, and regional performance."
                }
            ]
        }
    ]' \
    --system '[
        {
            "text": "You are an expert data analyst who can use available tools to analyze datasets and generate insights.\nUse the appropriate tools to complete the requested analysis efficiently and provide comprehensive results."
        }
    ]' \
    --tool-config '{
        "tools": [
            {
                "toolSpec": {
                    "name": "query_database",
                    "description": "Execute SQL queries against the sales database",
                    "inputSchema": {
                        "json": {
                            "type": "object",
                            "properties": {
                                "sql_query": {
                                    "type": "string",
                                    "description": "The SQL query to execute"
                                }
                            },
                            "required": ["sql_query"]
                        }
                    }
                }
            },
            {
                "toolSpec": {
                    "name": "create_chart",
                    "description": "Generate charts from data",
                    "inputSchema": {
                        "json": {
                            "type": "object",
                            "properties": {
                                "data": {
                                    "type": "array",
                                    "description": "The data to visualize"
                                },
                                "chart_type": {
                                    "type": "string",
                                    "enum": ["bar", "line", "pie", "scatter"],
                                    "description": "Type of chart to create"
                                }
                            },
                            "required": ["data", "chart_type"]
                        }
                    }
                }
            },
            {
                "toolSpec": {
                    "name": "calculate_statistics",
                    "description": "Calculate statistical measures",
                    "inputSchema": {
                        "json": {
                            "type": "object",
                            "properties": {
                                "data": {
                                    "type": "array",
                                    "description": "The data to analyze"
                                },
                                "metrics": {
                                    "type": "array",
                                    "items": {
                                        "type": "string",
                                        "enum": ["mean", "median", "growth_rate", "std_dev"]
                                    },
                                    "description": "Statistical metrics to calculate"
                                }
                            },
                            "required": ["data", "metrics"]
                        }
                    }
                }
            }
        ]
    }' \
    --additional-model-request-fields '{
        "reasoningConfig": {
            "type": "enabled",
            "maxReasoningEffort": "low"
        }
    }'

{
 "system": "You are an expert data analyst who can use available tools to analyze datasets and generate insights.\n  Use the appropriate tools to complete the requested analysis efficiently and provide comprehensive results.",
 "messages": [
  {
   "role": "user",
   "content": [
    {
     "text": "Analyze the sales performance for Q4 2024 and create a summary report with visualizations.\n  \n  The sales database contains tables: orders, customers, products, and sales_reps.\n  Focus on revenue trends, top-performing products, and regional performance."
    }
   ]
  }
 ],
 "toolConfig": {
  "tools": [
   {
    "toolSpec": {
     "name": "query_database",
     "description": "Execute SQL queries against the sales database",
     "inputSchema": {
      "json": {
       "type": "object",
       "properties": {
        "sql_query": {
         "type": "string",
         "description": "The SQL query to execute"
        }
       },
       "required": [
        "sql_query"
       ]
      }
     }
    }
   },
   {
    "toolSpec": {
     "name": "create_chart",
     "description": "Generate charts from data",
     "inputSchema": {
      "json": {
       "type": "object",
       "properties": {
        "data": {
         "type": "array",
         "description": "The data to visualize"
        },
        "chart_type": {
         "type": "string",
         "enum": [
          "bar",
          "line",
          "pie",
          "scatter"
         ],
         "description": "Type of chart to create"
        }
       },
       "required": [
        "data",
        "chart_type"
       ]
      }
     }
    }
   },
   {
    "toolSpec": {
     "name": "calculate_statistics",
     "description": "Calculate statistical measures",
     "inputSchema": {
      "json": {
       "type": "object",
       "properties": {
        "data": {
         "type": "array",
         "description": "The data to analyze"
        },
        "metrics": {
         "type": "array",
         "items": {
          "type": "string",
          "enum": [
           "mean",
           "median",
           "growth_rate",
           "std_dev"
          ]
         },
         "description": "Statistical metrics to calculate"
        }
       },
       "required": [
        "data",
        "metrics"
       ]
      }
     }
    }
   }
  ]
 },
 "additionalModelRequestFields": {
  "reasoningConfig": {
   "type": "enabled",
   "maxReasoningEffort": "high"
  }
 }
}
Analyze the sales performance for Q4 2024 and create a summary report with visualizations.

Available tools: - query_database(sql_query): Execute SQL queries against the sales database - create_chart(data, chart_type): Generate charts from data (bar, line, pie, scatter) - calculate_statistics(data, metrics): Calculate statistical measures (mean, median, growth rates) - generate_report(sections): Create formatted reports with multiple sections

The sales database contains tables: orders, customers, products, and sales_reps. Focus on revenue trends, top-performing products, and regional performance.

Ask clarifying questions if needed.

Amazon Nova 2 Lite Sample Response

Response

I'll help you analyze the sales performance for Q4 2024. Let me start by gathering the relevant data from the sales database. First, I'll need to understand the structure and get the Q4 2024 sales data.

Let me begin by examining the tables to understand their structure and then query the relevant data for Q4 2024.

# First, let me check the table structures to understand what data is available
query_database("""
SELECT table_name, column_name, data_type 
FROM information_schema.columns 
WHERE table_name IN ('orders', 'customers', 'products', 'sales_reps')
ORDER BY table_name, ordinal_position;
""")

Let me now query the sales data for Q4 2024 (October, November, December 2024):

# Get Q4 2024 sales data
query_database("""
SELECT 
    o.order_id,
    o.order_date,
    o.total_amount AS revenue,
    o.quantity,
    c.region,
    c.customer_name,
    p.product_name,
    p.category,
    sr.rep_name,
    sr.territory
FROM 
    orders o
JOIN 
    customers c ON o.customer_id = c.customer_id
JOIN 
    products p ON o.product_id = p.product_id
JOIN 
    sales_reps sr ON o.rep_id = sr.rep_id
WHERE 
    o.order_date BETWEEN '2024-10-01' AND '2024-12-31'
ORDER BY 
    o.order_date;
""")

Let me also get some summary data to understand the overall performance:

# Get summary statistics for Q4 2024
query_database("""
SELECT 
    COUNT(*) AS total_orders,
    SUM(total_amount) AS total_revenue,
    AVG(total_amount) AS average_order_value,
    MIN(total_amount) AS min_order_value,
    MAX(total_amount) AS max_order_value
FROM 
    orders
WHERE 
    order_date BETWEEN '2024-10-01' AND '2024-12-31';
""")

Now let me get data for month-over-month revenue trends:

# Get monthly revenue trends for Q4 2024
query_database("""
SELECT 
    DATE_TRUNC('month', order_date) AS month,
    COUNT(*) AS total_orders,
    SUM(total_amount) AS total_revenue,
    AVG(total_amount) AS avg_order_value
FROM 
    orders
WHERE 
    order_date BETWEEN '2024-10-01' AND '2024-12-31'
GROUP BY 
    DATE_TRUNC('month', order_date)
ORDER BY 
    month;
""")

Let me also get top-performing products:

# Get top-performing products by revenue in Q4 2024
query_database("""
SELECT 
    p.product_name,
    p.category,
    COUNT(o.order_id) AS total_orders,
    SUM(o.total_amount) AS total_revenue,
    AVG(o.total_amount) AS avg_order_value
FROM 
    orders o
JOIN 
    products p ON o.product_id = p.product_id
WHERE 
    o.order_date BETWEEN '2024-10-01' AND '2024-12-31'
GROUP BY 
    p.product_name, p.category
ORDER BY 
    total_revenue DESC
LIMIT 10;
""")

And let me get regional performance data:

# Get regional performance for Q4 2024
query_database("""
SELECT 
    c.region,
    COUNT(o.order_id) AS total_orders,
    SUM(o.total_amount) AS total_revenue,
    AVG(o.total_amount) AS avg_order_value
FROM 
    orders o
JOIN 
    customers c ON o.customer_id = c.customer_id
WHERE 
    o.order_date BETWEEN '2024-10-01' AND '2024-12-31'
GROUP BY 
    c.region
ORDER BY 
    total_revenue DESC;
""")

Let me also check if there's any comparison data with previous quarters to provide context:

# Compare Q4 2024 with previous quarters
query_database("""
WITH quarterly_data AS (
    SELECT 
        DATE_TRUNC('quarter', order_date) AS quarter,
        COUNT(*) AS total_orders,
        SUM(total_amount) AS total_revenue,
        AVG(total_amount) AS avg_order_value
    FROM 
        orders
    WHERE 
        order_date BETWEEN '2024-01-01' AND '2024-12-31'
    GROUP BY 
        DATE_TRUNC('quarter', order_date)
    ORDER BY 
        quarter
)
SELECT 
    quarter,
    total_orders,
    total_revenue,
    avg_order_value,
    LAG(total_revenue) OVER (ORDER BY quarter) AS prev_quarter_revenue,
    (total_revenue - LAG(total_revenue) OVER (ORDER BY quarter)) / LAG(total_revenue) OVER (ORDER BY quarter) * 100 AS growth_rate
FROM 
    quarterly_data;
""")

Now I'll retrieve all this data and create visualizations and a comprehensive report.

Let me start by retrieving all the data:

# Retrieving all the data for analysis
q4_sales_data = query_database("""
SELECT 
    o.order_id,
    o.order_date,
    o.total_amount AS revenue,
    o.quantity,
    c.region,
    c.customer_name,
    p.product_name,
    p.category,
    sr.rep_name,
    sr.territory
FROM 
    orders o
JOIN 
    customers c ON o.customer_id = c.customer_id
JOIN 
    products p ON o.product_id = p.product_id
JOIN 
    sales_reps sr ON o.rep_id = sr.rep_id
WHERE 
    o.order_date BETWEEN '2024-10-01' AND '2024-12-31'
ORDER BY 
    o.order_date;
""")

q4_summary = query_database("""
SELECT 
    COUNT(*) AS total_orders,
    SUM(total_amount) AS total_revenue,
    AVG(total_amount) AS average_order_value,
    MIN(total_amount) AS min_order_value,
    MAX(total_amount) AS max_order_value
FROM 
    orders
WHERE 
    order_date BETWEEN '2024-10-01' AND '2024-12-31';
""")

monthly_trends = query_database("""
SELECT 
    DATE_TRUNC('month', order_date) AS month,
    COUNT(*) AS total_orders,
    SUM(total_amount) AS total_revenue,
    AVG(total_amount) AS avg_order_value
FROM 
    orders
WHERE 
    order_date BETWEEN '2024-10-01' AND '2024-12-31'
GROUP BY 
    DATE_TRUNC('month', order_date)
ORDER BY 
    month;
""")

top_products = query_database("""
SELECT 
    p.product_name,
    p.category,
    COUNT(o.order_id) AS total_orders,
    SUM(o.total_amount) AS total_revenue,
    AVG(o.total_amount) AS avg_order_value
FROM 
    orders o
JOIN 
    products p ON o.product_id = p.product_id
WHERE 
    o.order_date BETWEEN '2024-10-01' AND '2024-12-31'
GROUP BY 
    p.product_name, p.category
ORDER BY 
    total_revenue DESC
LIMIT 10;
""")

regional_performance = query_database("""
SELECT 
    c.region,
    COUNT(o.order_id) AS total_orders,
    SUM(o.total_amount) AS total_revenue,
    AVG(o.total_amount) AS avg_order_value
FROM 
    orders o
JOIN 
    customers c ON o.customer_id = c.customer_id
WHERE 
    o.order_date BETWEEN '2024-10-01' AND '2024-12-31'
GROUP BY 
    c.region
ORDER BY 
    total_revenue DESC;
""")

quarterly_comparison = query_database("""
WITH quarterly_data AS (
    SELECT 
        DATE_TRUNC('quarter', order_date) AS quarter,
        COUNT(*) AS total_orders,
        SUM(total_amount) AS total_revenue,
        AVG(total_amount) AS avg_order_value
    FROM 
        orders
    WHERE 
        order_date BETWEEN '2024-01-01' AND '2024-12-31'
    GROUP BY 
        DATE_TRUNC('quarter', order_date)
    ORDER BY 
        quarter
)
SELECT 
    quarter,
    total_orders,
    total_revenue,
    avg_order_value,
    LAG(total_revenue) OVER (ORDER BY quarter) AS prev_quarter_revenue,
    (total_revenue - LAG(total_revenue) OVER (ORDER BY quarter)) / LAG(total_revenue) OVER (ORDER BY quarter) * 100 AS growth_rate
FROM 
    quarterly_data;
""")

Now I'll analyze this data and create visualizations. Let me start by examining the data structure and then creating the visualizations:

Q4 2024 Sales Performance Analysis

Executive Summary

Based on the Q4 2024 sales data, here's a comprehensive analysis of performance across key metrics:

Key Performance Highlights

Overall Performance: - Total Revenue: $[{q4_summary[0]['total_revenue']:,.2f}] - Total Orders: {q4_summary[0]['total_orders']} orders - Average Order Value: $[{q4_summary[0]['average_order_value']:,.2f}] - Revenue Growth: Compared to Q3 2024, revenue increased by [{quarterly_comparison[3]['growth_rate']:.2f}%]

Monthly Trend Analysis

Revenue by Month

Let me create a line chart showing the monthly revenue trend for Q4 2024:

```python

Create monthly revenue trend chart

monthly_data = [ {'month': row['month'], 'revenue': row['total_revenue']} for row in monthly_trends ]

create_chart( data=monthly_data, chart_type='line'

API Request

import boto3
import json

# Initialize the Bedrock Runtime client
bedrock_runtime = boto3.client('bedrock-runtime', region_name='us-west-2')

# Define the system prompt
system_prompt = """You are an expert data analyst who can use available tools to analyze datasets and generate insights.
  Use the appropriate tools to complete the requested analysis efficiently and provide comprehensive results."""

# Define the user prompt
user_prompt = """Analyze the sales performance for Q4 2024 and create a summary report with visualizations.

  The sales database contains tables: orders, customers, products, and sales_reps.
  Focus on revenue trends, top-performing products, and regional performance."""

# Prepare the request
request_body = {
    "system": [
        {
            "text": system_prompt
        }
    ],
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "text": user_prompt
                }
            ]
        }
    ],
    "toolConfig": {
        "tools": [
            {
                "systemTool": {
                    "name": "nova_grounding"
                }
            },
            {
                "systemTool": {
                    "name": "nova_code_interpreter"
                }
            }
        ]
    },
    "additionalModelRequestFields": {
        "reasoningConfig": {
            "type": "enabled",
            "maxReasoningEffort": "low"
        }
    },
    "inferenceConfig": {
        "temperature": 0.3,
        "topP": 0.9,
        "maxTokens": 10000
    }
}

# Make the API call
response = bedrock_runtime.converse(
    modelId="amazon.nova-2-lite-v1:0",
    **request_body
)

# Print the response
print(json.dumps(response, indent=2, default=str))
#!/bin/bash

aws bedrock-runtime converse \
    --model-id amazon.nova-2-lite-v1:0 \
    --region us-west-2 \
    --messages '[
        {
            "role": "user",
            "content": [
                {
                    "text": "Analyze the sales performance for Q4 2024 and create a summary report with visualizations.\n\nThe sales database contains tables: orders, customers, products, and sales_reps.\nFocus on revenue trends, top-performing products, and regional performance."
                }
            ]
        }
    ]' \
    --system '[
        {
            "text": "You are an expert data analyst who can use available tools to analyze datasets and generate insights.\nUse the appropriate tools to complete the requested analysis efficiently and provide comprehensive results."
        }
    ]' \
    --tool-config '{
        "tools": [
            {
                "toolSpec": {
                    "name": "query_database",
                    "description": "Execute SQL queries against the sales database",
                    "inputSchema": {
                        "json": {
                            "type": "object",
                            "properties": {
                                "sql_query": {
                                    "type": "string",
                                    "description": "The SQL query to execute"
                                }
                            },
                            "required": ["sql_query"]
                        }
                    }
                }
            },
            {
                "toolSpec": {
                    "name": "create_chart",
                    "description": "Generate charts from data",
                    "inputSchema": {
                        "json": {
                            "type": "object",
                            "properties": {
                                "data": {
                                    "type": "array",
                                    "description": "The data to visualize"
                                },
                                "chart_type": {
                                    "type": "string",
                                    "enum": ["bar", "line", "pie", "scatter"],
                                    "description": "Type of chart to create"
                                }
                            },
                            "required": ["data", "chart_type"]
                        }
                    }
                }
            },
            {
                "toolSpec": {
                    "name": "calculate_statistics",
                    "description": "Calculate statistical measures",
                    "inputSchema": {
                        "json": {
                            "type": "object",
                            "properties": {
                                "data": {
                                    "type": "array",
                                    "description": "The data to analyze"
                                },
                                "metrics": {
                                    "type": "array",
                                    "items": {
                                        "type": "string",
                                        "enum": ["mean", "median", "growth_rate", "std_dev"]
                                    },
                                    "description": "Statistical metrics to calculate"
                                }
                            },
                            "required": ["data", "metrics"]
                        }
                    }
                }
            }
        ]
    }' \
    --additional-model-request-fields '{
        "reasoningConfig": {
            "type": "enabled",
            "maxReasoningEffort": "low"
        }
    }'
{
 "system": "You are an expert data analyst who can use available tools to analyze datasets and generate insights.\n  Use the appropriate tools to complete the requested analysis efficiently and provide comprehensive results.",
 "messages": [
  {
   "role": "user",
   "content": [
    {
     "text": "Analyze the sales performance for Q4 2024 and create a summary report with visualizations.\n  \n  The sales database contains tables: orders, customers, products, and sales_reps.\n  Focus on revenue trends, top-performing products, and regional performance."
    }
   ]
  }
 ],
 "toolConfig": {
  "tools": [
   {
    "toolSpec": {
     "name": "query_database",
     "description": "Execute SQL queries against the sales database",
     "inputSchema": {
      "json": {
       "type": "object",
       "properties": {
        "sql_query": {
         "type": "string",
         "description": "The SQL query to execute"
        }
       },
       "required": [
        "sql_query"
       ]
      }
     }
    }
   },
   {
    "toolSpec": {
     "name": "create_chart",
     "description": "Generate charts from data",
     "inputSchema": {
      "json": {
       "type": "object",
       "properties": {
        "data": {
         "type": "array",
         "description": "The data to visualize"
        },
        "chart_type": {
         "type": "string",
         "enum": [
          "bar",
          "line",
          "pie",
          "scatter"
         ],
         "description": "Type of chart to create"
        }
       },
       "required": [
        "data",
        "chart_type"
       ]
      }
     }
    }
   },
   {
    "toolSpec": {
     "name": "calculate_statistics",
     "description": "Calculate statistical measures",
     "inputSchema": {
      "json": {
       "type": "object",
       "properties": {
        "data": {
         "type": "array",
         "description": "The data to analyze"
        },
        "metrics": {
         "type": "array",
         "items": {
          "type": "string",
          "enum": [
           "mean",
           "median",
           "growth_rate",
           "std_dev"
          ]
         },
         "description": "Statistical metrics to calculate"
        }
       },
       "required": [
        "data",
        "metrics"
       ]
      }
     }
    }
   }
  ]
 },
 "additionalModelRequestFields": {
  "reasoningConfig": {
   "type": "enabled",
   "maxReasoningEffort": "high"
  }
 }
}