Create an AI Agent for Jira Service Management
This endeavor involves not only designing algorithms that understand and respond to user requests but also integrating seamlessly with existing Jira workflows to automate repetitive tasks, prioritize tickets, and provide actionable insights for service improvement.
Easy for Jira allows you to scale OpenAI towards JSM with ease. Follow through our article to understand how to do so, and maybe even use our code example.
Functionality that will be used during this Article
Listeners, Console, Environment Variables & Code Repository
Context Libraries Used
Agent - For the AI functionality
Confluence - To work as a Knowledge Base for the AI.
How this functionality works in Easy for Jira
With our main goal of reducing complexity, we’ve been honing the ways you do work on Easy for Jira, that includes the long term goal of having as much value delivered with the most minimalist and direct code you can get. So you can develop faster and focus more on your consulting or administrative tasks.
For this process, we have created the Agent
Wrapper.
First, let’s create a Confluence page to host our knowledge base to the Agent
This part is important so you can edit and share edits for the knowledge of the agent, adapting it as needed, with more ease, without having to edit the code. Ideally, it would be better to have a Space on Confluence, focused on being the “brain” for all your agents, but you can use any page. In a future state, you can even think in a way to leverage your agent so it adds more knowledge to it’s own base.
Go to Confluence
Create a Page
Add the information the Agent should use as his knowledge
Save the page
Get the Page ID from the URL after saving the page, it’s an integer displayed in the URL
Something like this /wiki/spaces/spacekey/pages/page_id/long-page-nameSave this value, we’ll use it later
That provides the Agent a living knowledge base, that can be updated by users / administrators to increase the effectiveness of the Agent.
Second, let’s safely safe our credentials inside the “Environment Variables” section.
In the app, Go to “Settings“ then set your variables in the “Environment Variables” section.
Environment Variable | Value | Data Type |
---|---|---|
your user email | string | |
token | your Atlassian API token that you can get here | string |
OPENAI_AGENTS_APIKEY | the API KEY that you get in Open AI console. | string |
It’s nice to create an specific API Key for agents, so you can track costs more effectively.
Now lets create a mechanism to understand when our Agent needs help
This is not an ideal scenario but it certainly will happen from time to time, where your agent don’t have the entire data to answer a ticket and will require some help from a real agent.
To remediate that, we’ll create a custom field to hold the agent status.
Field Name | Agent State |
Field Description | Field used to track the state of an Automated JSM Agent. |
Field Key | Once you create your field, get the key and store it. |
The code! Let’s write it out
To start, go to your Console
The Code for main Agent
This agent will be saved in the code repository and can be reused later.
# Declare one Issue as Context
# This part is only needed in the console, while testing
# Once testing is done, you can remove or comment this "issue declaration".
issue = Issue('ACST-1')
# Declare your Agent
agent = Agent('Marco Lupino')
agent.set_token(env['OPENAI_AGENTS_APIKEY'])
agent.set_role('ITIL Specialized JSM Agent')
agent.set_state_field('customfield_10258') # Your field id comes here
# Pass him the context Issue
agent.issue = issue
# Set of Instructions
agent.add_instruction('The data you are requested is a ticket from a portal.')
agent.add_instruction('If your answer is definitive and surelye resolves the ticket, add the words "glad we could resolve it" into your response. preferrably at the end.')
agent.add_instruction('You always end your answer with "Regards, ${yourname}" where your name is your name.')
agent.add_instruction('On answering, you mention that if the user has more questions he can answer the same ticket.')
# Set of Rules
agent.add_rule('You always follow one or more of the instructions.')
agent.add_rule('IMPORTANT: The knowledge is your base to provide assertive answers. You follow it.')
agent.add_rule('When the requester dont provide you with full context, you ask for more information.')
# Connect to Confluence & Get Knowledge
confluence = Confluence(base_url, email=env['email'], token=env['token']) # base_url is a EFJ Variable that holds your instance url.
knowledge = confluence.get_page(53968897).storage # Your Page ID Comes here.
# Configure Knowledge
agent001.set_knowledge(knowledge)
response = agent001.process("can you say, balloon?")
logger.info(response)
We’ll give our agent a name, you can set any name, that will be used on responses.
Then we need to provide rules to our agent to follow and tied to that, the instructions for your agent.
The instructions will give your agent a line to follow on your responses and how it should treat customers, what type of data to send, etc.
The “Transition” logic, is a set of “word sets” that when they are in the response, you know where to send your ticket, so you know what’s the next transition, this is like an internal secret between you and your Agent.
Next you need to provide your agent with scoped data to what you need to resolve, that will be your “box” of data, this is a single string, so you need to pack your data in a string and pass as the argument. You can even use the “Confluence” package to have a living document of knowledge if you want.
The Code for the Moderator
This agent will also be saved in the code repository and can be reused later, this agent will be used to interpret the responses and get next actions.
# Declare one Issue as Context
# This part is only needed in the console, while testing
# Once testing is done, you can remove this "issue declaration".
issue = Issue('ACST-1')
# Declare your Agent
agent002 = Agent('Marco Lupino')
agent.set_token(env['OPENAI_AGENTS_APIKEY'])
agent.set_role('ITIL Specialized JSM Agent')
agent.set_state_field('customfield_10258') # Your field id comes here
# Pass him the context Issue
agent.issue = issue
# Set of Instructions
agent.add_instruction('The data you are requested is a ticket from a portal.')
# Set of Rules
agent.add_rule('You always follow one or more of the instructions.')
logger.info(response)
Easy for Jira - Python Automations, 2023