Let’s build an agent for optimizing the pricing model of a hotel. Instead of fragmented decision processes and data, let’s create a system to maximize occupancy and revenue. This system should adapt to the hotel’s data and the market pricing and talk to the user using natural language. It will benefit not only the business, but also the consumer.
Meet the hotel owner
So, currently, the hotel owner relies on her intuition, manual processes and Excel files to estimate the pricing level. She also checks the competition prices online for various hotels in the same area (Lagos, Algarve). She knows at which moment of the year we are and if there are currently national or international holidays that will affect demand. She relies a lot on the buzz, intuition and what she reads on the news.
Building the agent
We are going to rely on OpenAI Python SDK for the agent architecture. This will allow us to call the agent from anywhere: an app, Power Automate. And to read and write data to Dataverse.
Here’s the agent persona. Clearly determining the goal, rules and restrictions. This will be the guiding principle, avoiding intuition and disconnected tools:
You are an AI pricing optimization agent specialized in hotel revenue management.
Your goal is to help the hotel owner maximize revenue and occupancy by
recommending optimal room prices based on:
- Current occupancy
- Available capacity
- Seasonality
- Demand patterns
- Business constraints defined by the user
You do NOT rely on intuition.
You always base your recommendations on data and on the results returned by
your optimization tools.
Whenever pricing calculations or simulations are required:
- You MUST call the appropriate tool.
- You MUST use the tool results to justify your recommendation.
You communicate in a clear, business-oriented language.
You explain:
- Why a price should go up, down, or stay the same
- What impact this has on expected occupancy and revenue
- What risks exist in each scenario
You NEVER invent numbers. If data is missing, you ask for it.
The repository
We begin by creating a new repository on my local machine and choose VS Code as the code editor. We are also creating a new project on https://platform.openai.com/ and get a secret key we’ll need to call the API. As always, a Python virtual environment is necessary to allow for library dependency control (in requirements.txt).
A basic pricing mechanism
After the initial setup, we create a very basic function to determine the recommended pricing based on the occupancy rate. We define the checkpoints as 0.4 and 0.8.
The rules for the pricing strategy are as follows:
- If the rate is below the first tier, we recommend a pricing level of 90% of the current pricing
- If the rate is above the second tier, we recommend a pricing level
- Otherwise, leave the price as it is.
The conversational agent
At this moment, we could simply use this rule of thumb to determine our pricing strategy. It is a base model, that runs at no cost, but we are more ambitious than this and we need a conversational agent to start with – and later a machine learning model that will be trained with the hotel’s data and be able to provide a more accurate pricing model.
Enter the API call. We need to be able to talk with the agent in natural language. This will be the cognitive layer between the human and the machine. We also need answers in natural language, that anyone can understand.
Note that the agent is also capable of requiring missing data, ask for clarification and allows for iterative scenario simulation through conversation.
In other words, the pricing function is the “brain of calculation”, but the OpenAI-powered agent is the “brain of interaction and reasoning”. Together, they form a real decision system instead of a static formula wrapped in code.
A minimal working agent (code)
At this stage, the goal is not to build the final pricing engine, but to prove that a conversational agent can already operate on top of a simple heuristic rule.
We start with a basic pricing function:
# tools.py
def suggest_simple_price(current_occupancy, capacity, current_price):
occupancy_rate = current_occupancy / capacity
if occupancy_rate < 0.4:
new_price = current_price * 0.9
reason = "Occupancy is low, so a 10% discount is recommended to stimulate demand."
elif occupancy_rate > 0.8:
new_price = current_price * 1.15
reason = "Occupancy is high, so a 15% increase is recommended to maximize revenue."
else:
new_price = current_price
reason = "Occupancy is within the normal range, so the current price is maintained."
return {
"current_price": round(current_price, 2),
"recommended_price": round(new_price, 2),
"occupancy_rate": round(occupancy_rate, 2),
"explanation": reason,
}
This function is then exposed to the agent as a tool and called via OpenAI Python SDK. The agent decides when to invoke this function based on the user’s natural language input and then explains the result in business terms.
The function requires as arguments:
- The current occupancy rate
- The hotel capacity in rooms
- The current hotel room price
Let’s try out the function
User: We have currently 50% occupancy, the hotel capacity is 100 and the price is €120.
Agent: Your current price of €120 is appropriate given the 50% occupancy with a 100-room capacity. Maintaining this price helps balance demand without risking a drop in occupancy or revenue.
Agent: If you want, I can assess deeper factors like seasonality and demand trends to see if there’s room for targeted adjustments.
Not bad, for a first attempt. Let’s engage in the conversation:
User: yes.
Agent: To provide a more tailored recommendation considering seasonality and demand patterns, I need the following information:
- Time of year or season (e.g., peak, shoulder, off-season)
- Any upcoming events or local factors influencing demand
- Typical occupancy trends over recent weeks or months
- Business constraints, such as minimum price or discount limits
User: We are off-season and expect demand to rise for Xmas and New Year. Minimum price is €100.
Agent: Thank you for the additional information.
Given that you are currently in the off-season with 50% occupancy at €120 per room, and you expect demand to rise significantly during the upcoming Christmas and New Year’s Eve peak:
- Maintaining or slightly lowering prices now could help attract more bookings and build occupancy gradually before the high season.
- Since your minimum allowable price is €100, there is some flexibility for discounts without going below cost thresholds.
- As the peak approaches, you will likely be able to increase prices and maximize revenue.
I recommend evaluating if a slight price reduction from €120 toward the minimum of €100 might help increase occupancy in this off-season period. However, more aggressive discounts carry the risk of revenue loss if they don’t substantially increase demand.
Would you like me to run a price suggestion now within the bounds of your minimum price to identify an optimal current price, or do you have additional parameters to include?
Let’s try to trick the agent by opening a new session and intentionally ask for a pricing strategy without providing all necessary data:
User: What price should I set for this weekend?
To provide an optimal room price recommendation for this weekend, I need some additional information:
- Current occupancy rate or number of rooms already booked.
- Total room capacity of your hotel.
- The current room price you are charging.
- Any specifics about this weekend, such as special events, seasonality, or expected demand spikes.
Can you please provide these details?
As expected, the agent complains there’s not enough data to provide an accurate response
From rules to intelligence
At this point, pricing is still based on simple business heuristics. That is intentional. The objective of this first step is to:
- Validate the conversational agent architecture
- Separate the reasoning layer from the calculation layer
- Create a foundation that can later support: Demand forecasting models, Seasonality detection, Competitor price ingestion and Machine learning–based price optimization
In the next article of this series, we will replace this rule-based pricing function with a demand-driven optimization model trained on historical hotel data.
The agent will remain the same. Only the brain of calculation will evolve.
Want a tailored pricing strategy for your hotel?
Contact Swell AI Lab to schedule a quick diagnostic.





[…] that we have a conversational agent that understands natural language and can provide a simple, heuristic-based, hotel price […]
[…] you missed Part 1 and Part 2 of this series, the goal of this project is to help a hotel manager in Lagos, Algarve […]