watsonx Orchestrate

 View Only

 About create a new flow when adding tools for the agent build in Agent Builder

Himasha Semage's profile image
Himasha Semage posted Tue September 09, 2025 04:22 AM

I have a problem in "Code blocks" in Agent Builder when creating a new flow as a tool to add. The problem is that I have a build a tool to get a number of days from the user and a starting date for the leave from the user. Now I want to add the number of days to the starting date for the leave. I have been using the Code Blocks to calculate that, but I can figure out why it doesn't calculate and give me the new date. 

Dennis Parrott's profile image
Dennis Parrott

There are a number of code block examples using dates in the product docs.

https://www.ibm.com/docs/en/watsonx/watson-orchestrate/base?topic=flows-code-block-examples

Dates are represented as strings in Python, so you will first need to convert a date string to a date object. For example:

birthday_str = flow["User activity 1"]["Ask for date of birth"].output.value 

birthday_date = datetime.datetime.strptime(birthday_str, "%Y-%m-%d").date()

You will then need to use the datetime.timedelta() function to add or subtract days to the date object:

date_one_week_after_birthday = birthday_date + datetime.timedelta(days=7)

You will then need to convert the date object back to a string. For example:

my_date_str_isoformat = date_one_week_after_birthday.isoformat()

my_date_str = date_one_week_after_birthday.strftime("%a %d %B %Y") 

Dennis Parrott's profile image
Dennis Parrott

Looking at you screen shots. A couple of observations:

  • Remove the import statement. Code blocks include a number of standard python packages (as documented here)
  • You will need to set the value of our output variable: self.output.output_date_str = output_date_str