Jira toolkit을 사용하는 방법을 다룹니다.
Jira toolkit은 agent가 주어진 Jira 인스턴스와 상호작용하여 이슈 검색 및 이슈 생성과 같은 작업을 수행할 수 있게 해줍니다. 이 도구는 atlassian-python-api 라이브러리를 래핑하며, 자세한 내용은 다음을 참조하세요: atlassian-python-api.readthedocs.io/jira.html
설치 및 설정
이 도구를 사용하려면 먼저 다음을 환경 변수로 설정해야 합니다: JIRA_INSTANCE_URL, JIRA_CLOUD 두 가지 인증 방법 중 하나를 선택할 수 있습니다:- API token 인증: JIRA_API_TOKEN (필요한 경우 JIRA_USERNAME) 환경 변수를 설정합니다
- OAuth2.0 인증: JIRA_OAUTH2 환경 변수를 “client_id”와 최소한 “access_token” 및 “token_type”을 포함하는 “token” dict를 필드로 가지는 dict로 설정합니다
Copy
pip install -qU atlassian-python-api
Copy
pip install -qU langchain-community langchain-openai
Copy
import os
from langchain.agents import AgentType, initialize_agent
from langchain_community.agent_toolkits.jira.toolkit import JiraToolkit
from langchain_community.utilities.jira import JiraAPIWrapper
from langchain_openai import OpenAI
Copy
os.environ["JIRA_API_TOKEN"] = "abc"
os.environ["JIRA_USERNAME"] = "123"
os.environ["JIRA_INSTANCE_URL"] = "https://jira.atlassian.com"
os.environ["OPENAI_API_KEY"] = "xyz"
os.environ["JIRA_CLOUD"] = "True"
Copy
os.environ["JIRA_OAUTH2"] = (
'{"client_id": "123", "token": {"access_token": "abc", "token_type": "bearer"}}'
)
os.environ["JIRA_INSTANCE_URL"] = "https://jira.atlassian.com"
os.environ["OPENAI_API_KEY"] = "xyz"
os.environ["JIRA_CLOUD"] = "True"
Copy
llm = OpenAI(temperature=0)
jira = JiraAPIWrapper()
toolkit = JiraToolkit.from_jira_api_wrapper(jira)
Tool 사용법
Jira toolkit에 어떤 개별 tool들이 있는지 살펴보겠습니다:Copy
[(tool.name, tool.description) for tool in toolkit.get_tools()]
Copy
[('JQL Query',
'\n This tool is a wrapper around atlassian-python-api\'s Jira jql API, useful when you need to search for Jira issues.\n The input to this tool is a JQL query string, and will be passed into atlassian-python-api\'s Jira `jql` function,\n For example, to find all the issues in project "Test" assigned to the me, you would pass in the following string:\n project = Test AND assignee = currentUser()\n or to find issues with summaries that contain the word "test", you would pass in the following string:\n summary ~ \'test\'\n '),
('Get Projects',
"\n This tool is a wrapper around atlassian-python-api's Jira project API, \n useful when you need to fetch all the projects the user has access to, find out how many projects there are, or as an intermediary step that involv searching by projects. \n there is no input to this tool.\n "),
('Create Issue',
'\n This tool is a wrapper around atlassian-python-api\'s Jira issue_create API, useful when you need to create a Jira issue. \n The input to this tool is a dictionary specifying the fields of the Jira issue, and will be passed into atlassian-python-api\'s Jira `issue_create` function.\n For example, to create a low priority task called "test issue" with description "test description", you would pass in the following dictionary: \n {{"summary": "test issue", "description": "test description", "issuetype": {{"name": "Task"}}, "priority": {{"name": "Low"}}}}\n '),
('Catch all Jira API call',
'\n This tool is a wrapper around atlassian-python-api\'s Jira API.\n There are other dedicated tools for fetching all projects, and creating and searching for issues, \n use this tool if you need to perform any other actions allowed by the atlassian-python-api Jira API.\n The input to this tool is a dictionary specifying a function from atlassian-python-api\'s Jira API, \n as well as a list of arguments and dictionary of keyword arguments to pass into the function.\n For example, to get all the users in a group, while increasing the max number of results to 100, you would\n pass in the following dictionary: {{"function": "get_all_users_from_group", "args": ["group"], "kwargs": {{"limit":100}} }}\n or to find out how many projects are in the Jira instance, you would pass in the following string:\n {{"function": "projects"}}\n For more information on the Jira API, refer to https://atlassian-python-api.readthedocs.io/jira.html\n '),
('Create confluence page',
'This tool is a wrapper around atlassian-python-api\'s Confluence \natlassian-python-api API, useful when you need to create a Confluence page. The input to this tool is a dictionary \nspecifying the fields of the Confluence page, and will be passed into atlassian-python-api\'s Confluence `create_page` \nfunction. For example, to create a page in the DEMO space titled "This is the title" with body "This is the body. You can use \n<strong>HTML tags</strong>!", you would pass in the following dictionary: {{"space": "DEMO", "title":"This is the \ntitle","body":"This is the body. You can use <strong>HTML tags</strong>!"}} ')]
Copy
agent = initialize_agent(
toolkit.get_tools(), llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
)
Copy
agent.run("make a new issue in project PW to remind me to make more fried rice")
Copy
> Entering new AgentExecutor chain...
I need to create an issue in project PW
Action: Create Issue
Action Input: {"summary": "Make more fried rice", "description": "Reminder to make more fried rice", "issuetype": {"name": "Task"}, "priority": {"name": "Low"}, "project": {"key": "PW"}}
Observation: None
Thought: I now know the final answer
Final Answer: A new issue has been created in project PW with the summary "Make more fried rice" and description "Reminder to make more fried rice".
> Finished chain.
Copy
'A new issue has been created in project PW with the summary "Make more fried rice" and description "Reminder to make more fried rice".'
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.