An AI application that can chat with any service

March 22, 2024 | 9 minute read
Andrii Kovalov
Principal Software Engineer, UGBU
Text Size 100%:

AI-driven services: Transforming customer engagement

The integration of artificial intelligence (AI) with direct service operations heralds a transformative era for customer interactions and business efficiency. By enabling AI to work directly with services, businesses can offer personalized, instant responses 24/7, that help enhance the customer experience and satisfaction. This shift not only streamlines operations, but also empowers companies to scale their customer support without corresponding increases in overhead. Customers can enjoy swift, helpful assistance, businesses benefit from operational efficiencies, and the overall customer experience becomes more seamless and intuitive. AI's direct interaction with services paves the way for a future where every interaction is tailored, efficient, and deeply integrated into the fabric of daily business operations, offering significant benefits across the board.

The business case for AI integration

Businesses today are data-rich, equipped with customer relationship management (CRM) systems and other proprietary solutions capable of generating detailed reports and eye-catching charts. But from a practical business standpoint, are these tools being utilized to their full potential

Let’s step into the shoes of a utility system operator charged with outage monitoring and the orchestration of recovery efforts. The priority is clear: identify and address the most critical facilities immediately and determine which areas are impacted most severely. Currently, utilities have access to extensive data on outages, affected homes, critical facilities, and the deployment of recovery teams. However, the manual coordination and prioritization of this information is a labor-intensive process requiring individuals to analyze outage data, pinpoint the location of recovery teams, and identify critical facilities in need of immediate attention. Funneling all relevant data into an AI system can streamline the entire recovery process by using the AI to prioritize actions swiftly and logically. This streamlining can help ensure that the individuals making the decisions can do so not only with speed, but also an enhanced level of efficacy.

However, AI’s importance in this context goes beyond efficiency to minimizing the inconvenience and stress during such disruptions. When the lights go out, swift and effective restoration isn’t a luxury. It’s a necessity. The reassurance of having AI backup in this situation can provide comfort to customers and assistance to utility workers.

The mechanics of AI integration

AI is evolving at breakneck speed, transforming how we approach everyday tasks and challenges. Consider the ordeal of sifting through an electricity bill, a task that may not always be straightforward. For insights into charges, you may need to navigate through your utility provider’s website and decipher jargon-laden documents, all while pondering how to mitigate these costs and questioning how various factors, like weather or electric vehicle charging, influence monthly expenses.

In this context, the rise of AI assistants, or agents, marks a significant development. These sophisticated tools are revolutionizing our ability to obtain personalized advice and savings, offering a glimmer of hope for those skeptical about finding nuanced assistance. By converting user queries into actionable tasks for generative AI components—from search tools to language models and response generation systems—they suggest a future where navigating through the complexities of an electricity bill can become more intuitive and tailored to individual needs.

Oracle has recently introduced the Oracle Cloud Infrastructure (OCI) Generative AI Agents, signaling another step forward in the availability of generative AI. But what's truly revolutionary is the newfound ability to craft prompts and create logic that directly interacts with your services. With a well-defined API, AI models are now adept at discerning which values to apply to path or query variables, determining the appropriate endpoint for a call, and even understanding service dependencies, allowing them to sequentially gather data from one service and input it into another.

This movement isn’t just the future. It’s the present. In this thrilling time, the barriers between AI capabilities and practical applications are rapidly dissolving.

Approaches to AI-driven service calls

In this blog post, we explore two distinct methods for integrating AI into the process of calling real services.

Prompt-like REST API documentation

The REST API method involves using AI to interpret and call APIs based on a natural language description of the service. This example uses the Langchain library, which allows for integration with various large language models (LLMs).  below is an example of API documentation for the Open-Meteo archive weather data endpoint.

 

Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
OPEN_METEO_ARCHIVE_DOCS = """BASE URL: https://archive-api.open-meteo.com/

API Documentation
The API endpoint /v1/archive accepts a geographical coordinate, a list of weather variables and responds with a JSON weather history for specified period. Time always starts at 0:00 today and contains 168 hours. All URL parameters are listed below:

Parameter   Format Required   Default    Description
latitude, longitude Floating point Yes       Geographical WGS84 coordinate of the location
hourly  String array   No    A list of weather variables which should be returned. Values can be comma separated, or multiple &hourly= parameter in the URL can be used. Possible array values: temperature_2m, precipitation, weather_code...
daily   String array   No    A list of daily weather variable aggregations which should be returned. Values can be comma separated, or multiple &daily= parameter in the URL can be used. If daily weather variables are specified, parameter timezone is required. Possible array values: 'weather_code', 'temperature_2m_mean', 'precipitation_sum'...
temperature_unit    String No fahrenheit If celsius is set, all temperature values are converted to Celsius.
wind_speed_unit String No ms Possible values: kmh, ms, mph and kn
precipitation_unit  String No inch   Possible amount units: inch, mm
timezone    String No GMT    If timezone is set, all timestamps are returned as local-time and data is returned starting at 00:00 local-time. Any time zone name from the time zone database is supported. If auto is set as a time zone, the coordinates will be automatically resolved to the local time zone.
start_date  String (yyyy-mm-dd) Yes       The start data of an interval interval to get weather data. A day must be specified as an ISO8601 date (e.g. 2022-06-30).
end_date    String (yyyy-mm-dd)    Yes       The end date of an interval to get weather data. A day must be specified as an ISO8601 date (e.g. 2022-06-30).

Hourly Parameter Definition:
The parameter &hourly= accepts the following values. Most weather variables are given as an instantaneous value for the indicated hour. Some variables like precipitation are calculated from the preceding hour as and average or sum.

Variable    Valid time Unit   Description
temperature_2m  Instant    °C (°F)    Air temperature at 2 meters above ground, used for hourly data only
relative_humidity_2m    Instant    %  Relative humidity at 2 meters above ground
weather_code    Instant    WMO code   Weather condition as a numeric code. Follow WMO weather interpretation codes. See table below for details.
precipitation   Preceding hour sum mm (inch)  Total precipitation (rain, showers, snow) sum of the preceding hour. Data is stored with a 0.1 mm precision. If precipitation data is summed up to monthly sums, there might be small inconsistencies with the total precipitation amount.
rain    Preceding hour sum mm (inch)  Rain from large scale weather systems of the preceding hour in millimeter
snowfall    Preceding hour sum cm (inch)  Snowfall amount of the preceding hour in centimeters. For the water equivalent in millimeter, divide by 7. E.g. 7 cm snow = 10 mm precipitation water equivalent

Daily Parameter Definition:
Aggregations are a simple 24 hour aggregation from hourly values. The parameter &daily= accepts the following values:

Variable    Unit   Description
weather_code    WMO code   The most severe weather condition on a given day
temperature_2m_max  °C (°F) Maximum daily air temperature at 2 meters above ground
temperature_2m_min  °C (°F)    Minimum daily air temperature at 2 meters above ground
precipitation_sum   mm Sum of daily precipitation (including rain, showers and snowfall)
"""

The code using the Langchain library is simple. The Langchain function calls your API by itself, so you don’t have to implement anything.

Using the customer’s query with dates and location, the library called an endpoint that we needed to retrieve necessary information and provided a meaningful and understandable answer.

Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
> Entering new APICchain chain...
/Users/andriikotlov/PycharmProjects/ai_agents/venv/lib/python3.9/site-packages/langchain_core/api/deprecation.py:117: LangChainDeprecationWarning: The function 'run' was deprecated in LangChain 0.1.0 and will be removed in 0.2.0. Use 'invoke' instead.
warn_deprecated(
https://archive-api.open-meteo.com/v1/archive?latitude=38.8462&longitude=-77.3066&start_date=2023-01-22&end_date=2023-01-28&timezome=auto
{"latitude":38.84607,"longitude":-77.3066,"generationtime_ms":0.14603137969970703,"utc_offset_seconds":-18000,"timezone":"America/New_York","timezone_abbreviation":"EST","elevation":134.0,"daily_units":{"time":"iso8601","temperature_2m_max":"°C"},"daily":{"time":["2023-01-22","2023-01-23","2023-01-24","2023-01-25","2023-01-26","2023-01-27","2023-01-28"],"temperature_2m_max":[3.9,7.6,9.0,7.3,7.9,6.1,11.7]}}
> Finished chain.
Query: What was the hottest day for week 01-22-2023 - 01-28-2023 in Fairfax, Virginia?
Response: The hottest day in Fairfax, Virginia for the week of 01-22-2023 to 01-28-2023 was on 01-28-2023 with a maximum temperature of 11.7°C.

One advantage this method provides is that the process is straightforward and requires minimal programming. However, it lacks fine control over the API call parameters, which can lead to errors or unintended endpoint calls. Moreover, if multiple APIs are described, the AI model might not discern which to call without more context filtering.

A workaround employs another LLM prompt that verifies if the query context aligns with the API documentation. If not, it prevents unnecessary API calls. However, this workaround necessitates a map of API dependencies to ensure the correct sequencing of service calls.

Assistants-based approach

The assistants methodology is instructive and enables a more granular definition of actions or tools, facilitating precise control over the interaction. By defining individual tools for specific tasks, such as parameter determination for an API, making a call to the Cohere platform, or plotting a chart, we can direct the AI to run tasks in a particular order based on user queries.

This method allows you to create a singular assistant or multiple specialized ones to handle different tools. The assistant identifies which tool to use and the correct sequence of operations, helping to ensure an efficient process flow.

Below is an example of tool descriptions for an OpenAI assistant:

Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
tools = [

    {

        "type": "function",
        "function": {
            "name": "get_weather_forecast",
            "description": "Use this function to get all the parameters for the weather forecast API call or the current weather",
            "parameters": {
                "type": "object",
                "properties": {
                    "latitude": {
                        "type": "number",
                        "description": "Geographical WGS84 coordinate of the location. Infer this from the users location",
                    },
                    "longitude": {...},
                    "temperature_unit": {...},
                    "timezone": {...},
                },
                "required": ["latitude", "longitude", "temperature_unit", "timezone"],
            },
        }
    },
    {
        "type": "function",
        "function": {
            "name": "get_weather_history",
            "description": "Use this function to get all the parameters for the weather history API call",
            "parameters": {...},
        }
    },
    {
        "type": "function",
        "function": {
            "name": "get_usages_history",
            "description": "Use this function to get all the parameters for the usages history API call",
            "parameters": {...},
        }
    },
    {
        "type": "function",
        "function": {
            "name": "get_cohere_response",
            "description": "Use this function to get all the possible information about Utility or services this Utility provides",
            "parameters": {
                "type": "object",
                "properties": {
                    "utility_url": {
                        "type": "string",
                        "description": "Utility URL",
                    },
                    "question": {...},
                },
                "required": ["utility_url", "question"],
            },
        }
    },
    {
        "type": "function",
        "function": {
            "name": "plot_a_chart",
            "description": "Use this function to plot a chart based on the data and question provided",
            "parameters": {
                "type": "object",
                "properties": {
                    "data": {...},
                    "question": {...},
                },
                "required": ["data", "question"],
            },
        }
    },
]

The result is an assistant capable of managing numerous services simultaneously, only activating relevant ones based on the query context. Preliminary testing has shown remarkable precision in providing relevant, context-aware, intuitive responses.

Navigating the journey

In summary, while the advent of advanced AI offers tremendous capabilities to streamline operations, deliver cost savings, and enhance customer and employee satisfaction, the journey is just beginning.  The power at our disposal may seem immense, especially as AI continues to be embedded into more systems and functions. However, adopting a practical approach to identifying proper use cases is critical for enterprises, and personalized customer experience is one of the best starting points for companies looking to take the next step forward.

For more information, see the following resources:

 

Andrii Kovalov

Principal Software Engineer, UGBU


Previous Post

Transforming IT support: Introducing the generative AI-powered service desk

Sudhir Dureja | 8 min read

Next Post


Call wrap-up with AI automation

Oleg Kobchenko | 8 min read