Automate customer support with Amazon Bedrock, LangGraph, and Mistral models


AI brokers are reworking the panorama of shopper give a boost to by means of bridging the space between extensive language fashions (LLMs) and real-world packages. Those clever, self sustaining programs are poised to revolutionize customer support throughout industries, ushering in a brand new technology of human-AI collaboration and problem-solving. Through harnessing the facility of LLMs and integrating them with specialised gear and APIs, brokers can take on complicated, multistep buyer give a boost to duties that had been prior to now past the achieve of conventional AI programs.As we glance to the longer term, AI brokers will play a an important function within the following spaces:

  • Bettering decision-making – Offering deeper, context-aware insights to reinforce buyer give a boost to results
  • Automating workflows – Streamlining customer support processes, from preliminary touch to answer, throughout more than a few channels
  • Human-AI interactions – Enabling extra herbal and intuitive interactions between consumers and AI programs
  • Innovation and information integration – Producing new answers by means of combining various information resources and specialised wisdom to handle buyer queries extra successfully
  • Moral AI practices – Serving to supply extra clear and explainable AI programs to handle buyer issues and construct believe

Development and deploying AI agent programs for buyer give a boost to is a step towards unlocking the entire attainable of generative AI on this area. As those programs evolve, they’ll change into customer support, extend chances, and open new doorways for AI in improving buyer studies.

On this put up, we exhibit the best way to use Amazon Bedrock and LangGraph to construct a personalised buyer give a boost to enjoy for an ecommerce store. Through integrating the Mistral Large 2 and Pixtral Large fashions, we information you thru automating key buyer give a boost to workflows equivalent to price ticket categorization, order main points extraction, injury evaluate, and producing contextual responses. Those rules are appropriate throughout more than a few industries, however we use the ecommerce area as our number one instance to exhibit the end-to-end implementation and highest practices. This put up supplies a complete technical walkthrough that can assist you fortify your customer support functions and discover the most recent developments in LLMs and multimodal AI.

LangGraph is a formidable framework constructed on most sensible of LangChain that permits the introduction of cyclical, stateful graphs for complicated AI agent workflows. It makes use of a directed graph construction the place nodes constitute person processing steps (like calling an LLM or the use of a device), edges outline transitions between steps, and state is maintained and handed between nodes all the way through execution. This structure is especially treasured for buyer give a boost to automation involving workflows. LangGraph’s benefits come with integrated visualization, logging (strains), human-in-the-loop functions, and the facility to prepare complicated workflows in a extra maintainable means than conventional Python code.This put up supplies main points on the best way to do the next:

  • Use Amazon Bedrock and LangGraph to construct clever, context-aware buyer give a boost to workflows
  • Combine information in a helpdesk instrument, like JIRA, within the LangChain workflow
  • Use LLMs and imaginative and prescient language fashions (VLMs) within the workflow to accomplish context-specific duties
  • Extract data from photographs to assist in decision-making
  • Examine photographs to evaluate product injury claims
  • Generate responses for the buyer give a boost to tickets

Answer assessment

This answer comes to the purchasers beginning give a boost to requests thru e mail, which might be mechanically transformed into new give a boost to tickets in Atlassian Jira Service Management. The client give a boost to automation answer then takes over, figuring out the intent in the back of every question, categorizing the tickets, and assigning them to a bot consumer for additional processing. The answer makes use of LangGraph to orchestrate a workflow involving AI brokers to extracts key identifiers equivalent to transaction IDs and order numbers from the give a boost to price ticket. It analyzes the question and makes use of those identifiers to name related gear, extracting more information from the database to generate a complete and context-aware reaction. After the reaction is ready, it’s up to date in Jira for human give a boost to brokers to study prior to sending the reaction again to the buyer. This procedure is illustrated within the following determine. This answer is able to extracting data now not most effective from the price ticket frame and name but in addition from connected photographs like screenshots and exterior databases.

Solution Architecture

The answer makes use of two basis fashions (FMs) from Amazon Bedrock, every decided on in accordance with its particular functions and the complexity of the duties concerned. As an example, the Pixtral type is used for vision-related duties like symbol comparability and ID extraction, while the Mistral Huge 2 type handles plenty of duties like price ticket categorization, reaction era, and power calling. Moreover, the answer comprises fraud detection and prevention functions. It could actually establish fraudulent product returns by means of evaluating the inventory product symbol with the returned product symbol to ensure in the event that they fit and assess whether or not the returned product is in truth broken. This integration of complicated AI fashions with automation gear complements the potency and reliability of the buyer give a boost to procedure, facilitating well timed resolutions and safety towards fraudulent actions. LangGraph supplies a framework for orchestrating the ideas glide between brokers, that includes integrated state control and checkpointing to facilitate seamless procedure continuity. This capability permits the inclusion of preliminary price ticket summaries and outlines within the State object, with more information appended in next steps of the workflows. Through keeping up this evolving context, LangGraph allows LLMs to generate context-aware responses. See the next code:

# elegance to carry state data

elegance JiraAppState(MessagesState):
    key: str
    abstract: str
    description: str
    attachments: checklist
    class: str
    reaction: str
    transaction_id: str
    order_no: str
    utilization: checklist

The framework integrates without difficulty with Amazon Bedrock and LLMs, supporting task-specific diversification by means of the use of cost-effective fashions for more practical duties whilst decreasing the hazards of exceeding type quotas. Moreover, LangGraph gives conditional routing for dynamic workflow changes in accordance with intermediate effects, and its modular design facilitates the addition or elimination of brokers to increase device functions.

Accountable AI

It’s an important for buyer give a boost to automation packages to validate inputs and ensure LLM outputs are safe and accountable. Amazon Bedrock Guardrails can considerably fortify buyer give a boost to automation packages by means of offering configurable safeguards that track and clear out each consumer inputs and AI-generated responses, ensuring interactions stay protected, related, and aligned with organizational insurance policies. Through the use of options equivalent to content material filters, which locate and block damaging classes like hate speech, insults, sexual content material, and violence, in addition to denied subjects to lend a hand save you discussions on delicate or limited topics (for instance, criminal or clinical recommendation), buyer give a boost to packages can steer clear of producing or amplifying beside the point or defiant data. Moreover, guardrails can lend a hand redact individually identifiable data (PII) from dialog transcripts, protective consumer privateness and fostering believe. Those measures now not most effective scale back the chance of reputational hurt and regulatory violations but in addition create a extra certain and safe enjoy for purchasers, permitting give a boost to groups to concentrate on resolving problems successfully whilst keeping up prime requirements of protection and accountability.

The next diagram illustrates this structure.

Guardrails

Observability

In conjunction with Accountable AI, observability is important for buyer give a boost to packages to supply deep, real-time visibility into type efficiency, utilization patterns, and operational well being, enabling groups to proactively locate and get to the bottom of problems. With complete observability, you’ll be able to track key metrics equivalent to latency and token intake, and observe and analyze enter activates and outputs for high quality and compliance. This stage of perception is helping establish and mitigate dangers like hallucinations, recommended injections, poisonous language, and PII leakage, serving to make certain that buyer interactions stay protected, dependable, and aligned with regulatory necessities.

Must haves

On this put up, we use Atlassian Jira Carrier Control for instance. You’ll be able to use the similar normal strategy to combine with different provider control gear that supply APIs for programmatic get entry to. The configuration required in Jira comprises:

  • A Jira provider control challenge with API token to allow programmatic get entry to
  • The next custom fields:
    • Identify: Class, Sort: Make a selection Listing (a couple of alternatives)
    • Identify: Reaction, Sort: Textual content Box (multi-line)
  • A bot consumer to assign tickets

The next code presentations a pattern Jira configuration:

JIRA_API_TOKEN = ""
JIRA_USERNAME = ""
JIRA_INSTANCE_URL = "https://.atlassian.web/"
JIRA_PROJECT_NAME = ""
JIRA_PROJECT_KEY = ""
JIRA_BOT_USER_ID = ''

Along with Jira, the next services and products and Python programs are required:

  • A sound AWS account.
  • An AWS Identity and Access Management (IAM) function within the account that has enough permissions to create the important assets.
  • Access to the next models hosted on Amazon Bedrock:
    • Mistral Huge 2 (type ID: mistral.mistral-large-2407-v1:0).
    • Pixtral Huge (type ID: us.mistral.pixtral-large-2502-v1:0). The Pixtral Huge type is to be had in Amazon Bedrock beneath cross-Area inference profiles.
  • A LangGraph utility up and operating in the neighborhood. For directions, see Quickstart: Launch Local LangGraph Server.

For this put up, we use the us-west-2 AWS Area. For main points on to be had Areas, see Amazon Bedrock endpoints and quotas.

The supply code of this answer is to be had within the GitHub repository. That is an instance code; you must habits your personal due diligence and cling to the principle of least privilege.

Implementation with LangGraph

On the core of shopper give a boost to automation is a collection of specialised gear and purposes designed to assemble, analyze, and combine information from provider control programs and a SQLite database. Those gear function the root of our device, empowering it to ship context-aware responses. On this segment, we delve into the crucial parts that energy our device.

BedrockClient elegance

The BedrockClient elegance is carried out within the cs_bedrock.py report. It supplies a wrapper for interacting with Amazon Bedrock services and products, particularly for managing language fashions and content material protection guardrails in buyer give a boost to packages. It simplifies the method of initializing language fashions with suitable configurations and managing content material protection guardrails. This elegance is utilized by LangChain and LangGraph to invoke LLMs on Amazon Bedrock.

This elegance additionally supplies the best way to create guardrails for accountable AI implementation. The next Amazon Bedrock Guardrails coverage filters sexual, violence, hate, insults, misconducts, and recommended assaults, and is helping save you fashions from producing inventory and funding recommendation, profanity, hate, violent and sexual content material. Moreover, it is helping save you exposing vulnerabilities in fashions by means of assuaging recommended assaults.

# guardrails coverage

contentPolicyConfig={
    'filtersConfig': [
        {
            'type': 'SEXUAL',
            'inputStrength': 'MEDIUM',
            'outputStrength': 'MEDIUM'
        },
        {
            'type': 'VIOLENCE',
            'inputStrength': 'MEDIUM',
            'outputStrength': 'MEDIUM'
        },
        {
            'type': 'HATE',
            'inputStrength': 'MEDIUM',
            'outputStrength': 'MEDIUM'
        },
        {
            'type': 'INSULTS',
            'inputStrength': 'MEDIUM',
            'outputStrength': 'MEDIUM'
        },
        {
            'type': 'MISCONDUCT',
            'inputStrength': 'MEDIUM',
            'outputStrength': 'MEDIUM'
        },
        {
            'type': 'PROMPT_ATTACK',
            'inputStrength': 'LOW',
            'outputStrength': 'NONE'
        }
    ]
},
wordPolicyConfig={
    'wordsConfig': [
        {'text': 'stock and investment advice'}
    ],
    'managedWordListsConfig': [
        {'type': 'PROFANITY'}
    ]
},
contextualGroundingPolicyConfig={
    'filtersConfig': [
        {
            'type': 'GROUNDING',
            'threshold': 0.65
        },
        {
            'type': 'RELEVANCE',
            'threshold': 0.75
        }
    ]
}

Database elegance

The Database elegance is outlined within the cs_db.py report. This elegance is designed to facilitate interactions with a SQLite database. It’s chargeable for growing an area SQLite database and uploading artificial information associated with consumers, orders, refunds, and transactions. Through doing so, it makes certain that the important information is instantly to be had for more than a few operations. Moreover, the category comprises handy wrapper purposes that simplify the method of querying the database.

JiraSM elegance

The JiraSM elegance is carried out within the cs_jira_sm.py report. It serves as an interface for interacting with Jira Carrier Control. It establishes a connection to Jira by means of the use of the API token, consumer identify, and example URL, all of which might be configured within the .env report. This setup supplies safe and versatile get entry to to the Jira example. The category is designed to maintain more than a few price ticket operations, together with studying tickets and assigning them to a preconfigured bot consumer. Moreover, it helps downloading attachments from tickets and updating customized fields as wanted.

CustomerSupport elegance

The CustomerSupport elegance is carried out within the cs_cust_support_flow.py report. This elegance encapsulates the buyer give a boost to processing good judgment by means of the use of LangGraph and Amazon Bedrock. The use of LangGraph nodes and gear, this elegance orchestrates the buyer give a boost to workflow. The workflow first of all determines the class of the price ticket by means of examining its content material and classifying it as associated with transactions, deliveries, refunds, or different problems. It updates the give a boost to price ticket with the class detected. Following this, the workflow extracts pertinent data equivalent to transaction IDs or order numbers, which may contain examining each textual content and photographs, and queries the database for related main points. Your next step is reaction era, which is context-aware and adheres to content material protection pointers whilst keeping up a certified tone. In any case, the workflow integrates with Jira, assigning classes, updating responses, and managing attachments as wanted.

The LangGraph orchestration is carried out within the build_graph serve as, as illustrated within the following code. This serve as additionally generates a visible illustration of the workflow the use of a Mermaid graph for higher readability and figuring out. This setup helps an effective and structured strategy to dealing with buyer give a boost to duties.

def build_graph(self):
    """
    This serve as prepares LangGraph nodes, edges, conditional edges, compiles the graph and presentations it 
    """

    # create StateGraph object
    graph_builder = StateGraph(JiraAppState)

    # upload nodes to the graph
    graph_builder.add_node("Decide Price ticket Class", self.determine_ticket_category_tool)
    graph_builder.add_node("Assign Price ticket Class in JIRA", self.assign_ticket_category_in_jira_tool)
    graph_builder.add_node("Extract Transaction ID", self.extract_transaction_id_tool)
    graph_builder.add_node("Extract Order Quantity", self.extract_order_number_tool)
    graph_builder.add_node("To find Transaction Main points", self.find_transaction_details_tool)
    
    graph_builder.add_node("To find Order Main points", self.find_order_details_tool)
    graph_builder.add_node("Generate Reaction", self.generate_response_tool)
    graph_builder.add_node("Replace Reaction in JIRA", self.update_response_in_jira_tool)

    graph_builder.add_node("gear", ToolNode([StructuredTool.from_function(self.assess_damaged_delivery), StructuredTool.from_function(self.find_refund_status)]))
    
    # upload edges to glue nodes
    graph_builder.add_edge(START, "Decide Price ticket Class")
    graph_builder.add_edge("Decide Price ticket Class", "Assign Price ticket Class in JIRA")
    graph_builder.add_conditional_edges("Assign Price ticket Class in JIRA", self.decide_ticket_flow_condition)
    graph_builder.add_edge("Extract Order Quantity", "To find Order Main points")
    
    graph_builder.add_edge("Extract Transaction ID", "To find Transaction Main points")
    graph_builder.add_conditional_edges("To find Order Main points", self.order_query_decision, ["Generate Response", "tools"])
    graph_builder.add_edge("gear", "Generate Reaction")
    graph_builder.add_edge("To find Transaction Main points", "Generate Reaction")
    
    graph_builder.add_edge("Generate Reaction", "Replace Reaction in JIRA")
    graph_builder.add_edge("Replace Reaction in JIRA", END)

    # bring together the graph
    checkpoint = MemorySaver()
    app = graph_builder.bring together(checkpointer=checkpoint)
    self.graph_app = app
    self.util.log_data(information="Workflow compiled effectively", ticket_id='NA')

    # Visualize the graph
    show(Symbol(app.get_graph().draw_mermaid_png(draw_method=MermaidDrawMethod.API)))

    go back app

LangGraph generates the next Mermaid diagram to visually constitute the workflow.

Mermaid diagram

Application elegance

The Application elegance, carried out within the cs_util.py report, supplies crucial purposes to give a boost to the buyer give a boost to automation. It encompasses utilities for logging, report dealing with, utilization metric monitoring, and symbol processing operations. The category is designed as a central hub for more than a few helper strategies, streamlining commonplace duties around the utility. Through consolidating those operations, it promotes code reusability and maintainability inside the device. Its capability makes certain that the automation framework stays environment friendly and arranged.

A key characteristic of this elegance is its complete logging functions. It supplies the best way to log informational messages, mistakes, and demanding occasions without delay into the cs_logs.log report. Moreover, it tracks Amazon Bedrock LLM token utilization and latency metrics, facilitating detailed efficiency tracking. The category additionally logs the execution glide of application-generated activates and LLM generated responses, assisting in troubleshooting and debugging. Those log recordsdata may also be seamlessly built-in with usual log pusher brokers, making an allowance for computerized switch to most popular log tracking programs. This integration makes certain that device task is carefully monitored and temporarily out there for research.

Run the agentic workflow

Now that the buyer give a boost to workflow is outlined, it may be done for more than a few price ticket varieties. The next purposes use the supplied price ticket key to fetch the corresponding Jira price ticket and obtain to be had attachments. Moreover, they initialize the State object with main points such because the price ticket key, abstract, description, attachment report trail, and a device recommended for the LLM. This State object is used all through the workflow execution.

def generate_response_for_ticket(ticket_id: str):
    
    llm, vision_llm, llm_with_guardrails = bedrock_client.init_llms(ticket_id=ticket_id)
    cust_support = CustomerSupport(llm=llm, vision_llm=vision_llm, llm_with_guardrails=llm_with_guardrails)
    app   = cust_support.build_graph()
    
    state = cust_support.get_jira_ticket(key=ticket_id)
    state = app.invoke(state, thread)
    
    util.log_usage(state['usage'], ticket_id=ticket_id)
    util.log_execution_flow(state["messages"], ticket_id=ticket_id)
    

The next code snippet invokes the workflow for the Jira price ticket with key AS-6:

# initialize categories and create bedrock guardrails
bedrock_client = BedrockClient()
util = Application()
guardrail_id = bedrock_client.create_guardrail()

# procedure a JIRA price ticket
generate_response_for_ticket(ticket_id='AS-6')

The next screenshot presentations the Jira price ticket prior to processing. Realize that the Reaction and Class fields are empty, and the price ticket is unassigned.

Support Ticket - Initial

The next screenshot presentations the Jira price ticket after processing. The Class box is up to date as Refunds and the Reaction box is up to date by means of the AI-generated content material.

Support Ticket - updated

This logs LLM utilization data as follows:

Style                              Enter Tokens  Output Tokens Latency 
mistral.mistral-large-2407-v1:0      385               2         653  
mistral.mistral-large-2407-v1:0      452              27         884      
mistral.mistral-large-2407-v1:0     1039              36        1197   
us.mistral.pixtral-large-2502-v1:0  4632             425        5952   
mistral.mistral-large-2407-v1:0     1770             144        4556  

Blank up

Delete any IAM roles and insurance policies created particularly for this put up. Delete the native reproduction of this put up’s code.

In the event you now not want get entry to to an Amazon Bedrock FM, you’ll be able to take away get entry to from it. For directions, see Add or remove access to Amazon Bedrock foundation models.

Delete the transient recordsdata and guardrails used on this put up with the next code:

shutil.rmtree(util.get_temp_path())
bedrock_client.delete_guardrail()

Conclusion

On this put up, we advanced an AI-driven buyer give a boost to answer the use of Amazon Bedrock, LangGraph, and Mistral fashions. This complicated agent-based workflow successfully handles various buyer queries by means of integrating a couple of information resources and extracting related data from tickets or screenshots. It additionally evaluates injury claims to mitigate fraudulent returns. The answer is designed with flexibility, permitting the addition of recent stipulations and knowledge resources as companies want to evolve. With this multi-agent way, you’ll be able to construct tough, scalable, and clever programs that redefine the functions of generative AI in buyer give a boost to.

Wish to discover additional? Take a look at the next GitHub repo. There, you’ll be able to practice the code in motion and experiment with the answer your self. The repository comprises step by step directions for putting in and operating the multi-agent device, together with code for interacting with information resources and brokers, routing information, and visualizing workflows.


Concerning the authors

Deepesh DhapolaDeepesh Dhapola is a Senior Answers Architect at AWS India, that specialize in serving to monetary services and products and fintech purchasers optimize and scale their packages at the AWS Cloud. With a robust focal point on trending AI applied sciences, together with generative AI, AI brokers, and the Style Context Protocol (MCP), Deepesh makes use of his experience in device finding out to design leading edge, scalable, and safe answers. the transformative attainable of AI, he actively explores state-of-the-art developments to pressure potency and innovation for AWS consumers. Outdoor of labor, Deepesh enjoys spending high quality time together with his circle of relatives and experimenting with various culinary creations.



Source link

Leave a Comment