diff --git a/libs/langchain/langchain/tools/github/tool.py b/libs/langchain/langchain/tools/github/tool.py index ec67fd2b3357b..8cf4d8003b21d 100644 --- a/libs/langchain/langchain/tools/github/tool.py +++ b/libs/langchain/langchain/tools/github/tool.py @@ -1,5 +1,5 @@ """ -This tool allows agents to interact with the pygithub library +This tool allows agents to interact with the pygithub library and operate on a GitHub repository.\n\nTo use this tool, you must first set as environment variables:\n GITHUB_API_TOKEN\n GITHUB_REPOSITORY -> format: {owner}/{repo} and operate on a GitHub repository. To use this tool, you must first set as environment variables: @@ -11,17 +11,20 @@ from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.pydantic_v1 import Field -from langchain.tools.base import BaseTool +from langchain.pydantic_v1 import Field +import logging +import traceback +from langchain.tools.base import BaseTool, ToolRunFailed from langchain.utilities.github import GitHubAPIWrapper class GitHubAction(BaseTool): """Tool for interacting with the GitHub API.""" - api_wrapper: GitHubAPIWrapper = Field(default_factory=GitHubAPIWrapper) - mode: str - name: str = "" - description: str = "" + api_wrapper: GitHubAPIWrapper = Field() + + name: str = "GitHubAction" + description: str = "Provides an interface for interacting with the GitHub API." def _run( self, @@ -29,4 +32,9 @@ def _run( run_manager: Optional[CallbackManagerForToolRun] = None, ) -> str: """Use the GitHub API to run an operation.""" - return self.api_wrapper.run(self.mode, instructions) + try: + return self.api_wrapper.run(instructions) + except Exception as e: + logging.error(f'An error occurred while running the API: {e}') + logging.error(traceback.format_exc()) + raise ToolRunFailed('Failed to run the API')