
AI running it’s own code! : Agentic Code Interpreter
Public Preview: Code Interpreter for Agents for Amazon Bedrock - With sample code.

- Choose Your Model: We'll use the Claude 3 Sonnet model for this example.
- Set Agent Instructions: Provide detailed instructions for your agent, focusing on problem-solving, data analysis, and utilizing the Code Interpreter tool. (See example in the code below)
- Configure the Agent: In the Amazon Bedrock console, create a new agent and select the Claude 3 Sonnet model.
- Enable Code Interpreter: In the agent's settings, enable the Code Interpreter feature. This connects a Python execution sandbox to your agent.
You can find the full code used for this demo here: https://github.com/build-on-aws/agents-for-amazon-bedrock-sample-feature-notebooks/
- Parsing the provided data
- Writing Python code to analyze the data and create a bar graph
- Executing the code in its sandbox environment
- Generating the graph as an image file
- Providing an interpretation of the results

The bar chart shows the total spend amount for each product category based on the provided billing data. The x-axis displays the category names (Electronics, Home, and Clothing), and the y-axis represents the total spend amount in dollars.From the chart, we can observe that the Electronics category has the highest total spend at around $4,360. This is significantly higher than the other two categories, Home and Clothing, which have total spends of around $700 and $340, respectively.One notable observation is the large difference in spend between the Electronics category and the other two categories. This could indicate that the customer or business has a higher demand or preference for electronic products compared to home and clothing items during the given time period.Overall, the chart provides a clear visual representation of the spending patterns across different product categories, highlighting the dominance of the Electronics category in terms of total spend.
- Security: While the execution environment is sandboxed, always be mindful of the data you're processing.
- Performance: Complex computations may take some time, so plan your application architecture accordingly.
- User Experience: Think about how to present the results of code execution in a way that's meaningful to your end-users.
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.