Skip to content

StrandsAgent support for exceptions in system prompt

0

Hi,

Recently we deploy some ai agents using stands SDK to shutdown some of ec2 instances after office hours. The ai agent will run daily but on some days we want to set exception not shutting ec2 instances on certain days.

====================================================== We set the exception on prompt like this below but it is not working.

prompt

user_input=("Please startup ec2 instance. Do not startup the following instance with instance id from 21-Oct-2025 to 23-Oct-2025")

system prompt

promptdesc = """ You are snooze agent who can startup ec2 instance after office hours. All actions performed in ap-southeast-1 region only. Use ccapi mcp server to verify the ec2 instance exists and check the tags "AutoStartStop=True" whether it exists on the ec2 instance. If it exists, continue,else inform user and exit the program. Check the current health status. Exclude those instances as per request to be shut down for that particular date. Using start_ec2_instance tool,provide instance id,startup the instance. After completing the activity, write down summary of the actions perform and ec2 instance health status. '''

========================= Output

EC2 Instance Startup Summary - 03 Nov 2025

Instances started: aaa, bbb, cccc, dddd, eeee, ffff, gggg Instances not started (excluded): zzzz,dddd,yyyy,www

The instructions is to set exception not to start up instances from 21-Oct-2025 to 23-Oct-2025 but it did not startup instances after the 23 Oct 2025.

Thank you Regards Ross

asked 12 days ago24 views
1 Answer
0

It appears that your Strands agent isn't correctly processing the date-based exceptions in your prompt. The issue likely stems from how the agent is interpreting the temporal conditions in your instructions.

When working with Strands Agents SDK for time-sensitive operations like your EC2 startup/shutdown scenario, you need to ensure that:

  1. The system prompt clearly defines how to handle date-based exceptions
  2. The agent has access to the current date for comparison
  3. The logic for date comparison is explicitly stated

I recommend modifying your system prompt to include more explicit date handling instructions:

You are a snooze agent who can startup EC2 instances after office hours.
All actions performed in ap-southeast-1 region only.

Follow these steps:
1. Use ccapi mcp server to verify the EC2 instance exists and check the tags "AutoStartStop=True"
2. If the tag exists, continue; else inform user and exit the program
3. Check the current health status of the instances
4. IMPORTANT: Check today's date. If today's date falls within any exception periods specified by the user, do not start those specific instances mentioned in the exception
5. For instances not in the exception list or outside exception dates, use start_ec2_instance tool to startup the instances
6. After completing the activity, write a summary of actions performed and EC2 instance health status

When processing date exceptions:
- Parse the date range explicitly (e.g., "from 21-Oct-2025 to 23-Oct-2025")
- Only apply exceptions during the specified date range
- Resume normal operations immediately after the exception period ends

Additionally, consider adding a tool that provides the current date to your agent, so it can make accurate date comparisons. This will help ensure that your agent correctly processes the temporal aspects of your instructions and only applies exceptions during the specified date ranges.

For production deployments, you might also want to implement more robust error handling and monitoring to catch these types of issues, such as wrapping the agent invocation in retry logic and setting up CloudWatch alerts to monitor for unexpected behaviors.
Sources
Strands Agents SDK: A technical deep dive into agent architectures and observability | Artificial Intelligence
Amazon Strands Agents SDK: A technical deep dive into agent architectures and observability | Artificial Intelligence

answered 12 days ago
EXPERT
reviewed 12 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.