langchain
langchain copied to clipboard
Community GitHub toolkit tool names are invalid
Checked other resources
- [x] I added a very descriptive title to this issue.
- [x] I searched the LangChain documentation with the integrated search.
- [x] I used the GitHub search to find a similar question and didn't find it.
- [x] I am sure that this is a bug in LangChain rather than my code.
- [x] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
from langchain_community.agent_toolkits.github.toolkit import GitHubToolkit from langchain_community.utilities.github import GitHubAPIWrapper from langchain_openai import ChatOpenAI from langgraph.prebuilt import create_react_agent
from dotenv import load_dotenv
load_dotenv()
Initialize GitHub API Wrapper
github = GitHubAPIWrapper()
Instantiate GitHub Toolkit
toolkit = GitHubToolkit.from_github_api_wrapper(github)
llm = ChatOpenAI(model="gpt-4o", temperature=0)
This works, but it should just work out of the box
tools = [setattr(tool, "name", tool.mode) or tool for tool in toolkit.get_tools()]
This doesn't work because tool names contain spaces, and that is not supported by OpenAI
tools = toolkit.get_tools()
agent_executor = create_react_agent(llm, tools)
events = agent_executor.stream( {"messages": [("user", "Get me some GitHub issues")]}, stream_mode="values", )
Error Message and Stack Trace (if applicable)
File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/langgraph/pregel/runner.py", line 231, in tick run_with_retry( File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/langgraph/pregel/retry.py", line 40, in run_with_retry return task.proc.invoke(task.input, config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/langgraph/utils/runnable.py", line 462, in invoke input = step.invoke(input, config, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/langgraph/utils/runnable.py", line 218, in invoke ret = context.run(self.func, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/langgraph/prebuilt/chat_agent_executor.py", line 628, in call_model response = model_runnable.invoke(state, config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 3024, in invoke input = context.run(step.invoke, input, config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 5360, in invoke return self.bound.invoke( ^^^^^^^^^^^^^^^^^^ File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py", line 284, in invoke self.generate_prompt( File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py", line 860, in generate_prompt return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py", line 690, in generate self._generate_with_cache( File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py", line 925, in _generate_with_cache result = self._generate( ^^^^^^^^^^^^^^^ File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/langchain_openai/chat_models/base.py", line 790, in _generate response = self.client.create(**payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/openai/_utils/_utils.py", line 279, in wrapper return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/openai/resources/chat/completions.py", line 850, in create return self._post( ^^^^^^^^^^^ File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1283, in post return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 960, in request return self._request( ^^^^^^^^^^^^^^ File "/Users/yason/breba/GitHub-api-LangGraph-demo/server/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1064, in _request raise self.make_status_error_from_response(err.response) from None openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid 'tools[0].function.name': string does not match pattern. Expected a string that matches the pattern '^[a-zA-Z0-9-]+$'.", 'type': 'invalid_request_error', 'param': 'tools[0].function.name', 'code': 'invalid_value'}} During task with name 'agent' and id '9b4c98e5-2bdc-538d-54c6-acaa17b57e1f'
Description
Looks like this is a know issue since the documentation is providing an awkward workaround here:
from langgraph.prebuilt import create_react_agent
tools = [tool for tool in toolkit.get_tools() if tool.name == "Get Issue"]
assert len(tools) == 1
tools[0].name = "get_issue"
agent_executor = create_react_agent(llm, tools)
I'm trying to load tools without doing the strange tools[0].name = "get_issue"
I found some tool kits that use names that are correct (no whitespace in the name), but for GitHub Toolkit, the name field always has a space.
Wanted to create a PR to change the names in the toolkit file , but figured it's worth reporting the issue to get guidance first.
System Info
System Information
OS: Darwin OS Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000 Python Version: 3.12.4 (main, Jul 29 2024, 13:31:11) [Clang 15.0.0 (clang-1500.3.9.4)]
Package Information
langchain_core: 0.3.36 langsmith: 0.3.8
Optional packages not installed
langserve
Other Dependencies
httpx: 0.27.0 jsonpatch<2.0,>=1.33: Installed. No version info available. langsmith-pyo3: Installed. No version info available. langsmith<0.4,>=0.1.125: Installed. No version info available. orjson: 3.10.15 packaging<25,>=23.2: Installed. No version info available. pydantic: 2.8.2 pydantic<3.0.0,>=2.5.2;: Installed. No version info available. pydantic<3.0.0,>=2.7.4;: Installed. No version info available. pytest: Installed. No version info available. PyYAML>=5.3: Installed. No version info available. requests: 2.32.3 requests-toolbelt: 1.0.0 rich: 13.8.1 tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. typing-extensions>=4.7: Installed. No version info available. zstandard: 0.23.0 22:39:28:~/breba/GitHub-api-LangGraph-demo/server % poetry run python -m langchain_core.sys_info
System Information
OS: Darwin OS Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000 Python Version: 3.12.6 (main, Sep 6 2024, 19:03:47) [Clang 15.0.0 (clang-1500.3.9.4)]
Package Information
langchain_core: 0.3.36 langchain: 0.3.19 langchain_community: 0.3.17 langsmith: 0.3.1 langchain_openai: 0.3.1 langchain_text_splitters: 0.3.6 langgraph_sdk: 0.1.51
Optional packages not installed
langserve
Other Dependencies
aiohttp<4.0.0,>=3.8.3: Installed. No version info available. async-timeout<5.0.0,>=4.0.0;: Installed. No version info available. dataclasses-json<0.7,>=0.5.7: Installed. No version info available. httpx: 0.28.1 httpx-sse<1.0.0,>=0.4.0: Installed. No version info available. jsonpatch<2.0,>=1.33: Installed. No version info available. langchain-anthropic;: Installed. No version info available. langchain-aws;: Installed. No version info available. langchain-cohere;: Installed. No version info available. langchain-community;: Installed. No version info available. langchain-core<1.0.0,>=0.3.34: Installed. No version info available. langchain-core<1.0.0,>=0.3.35: Installed. No version info available. langchain-deepseek;: Installed. No version info available. langchain-fireworks;: Installed. No version info available. langchain-google-genai;: Installed. No version info available. langchain-google-vertexai;: Installed. No version info available. langchain-groq;: Installed. No version info available. langchain-huggingface;: Installed. No version info available. langchain-mistralai;: Installed. No version info available. langchain-ollama;: Installed. No version info available. langchain-openai;: Installed. No version info available. langchain-text-splitters<1.0.0,>=0.3.6: Installed. No version info available. langchain-together;: Installed. No version info available. langchain-xai;: Installed. No version info available. langchain<1.0.0,>=0.3.18: Installed. No version info available. langsmith-pyo3: Installed. No version info available. langsmith<0.4,>=0.1.125: Installed. No version info available. langsmith<0.4,>=0.1.17: Installed. No version info available. numpy<2,>=1.26.4;: Installed. No version info available. numpy<3,>=1.26.2;: Installed. No version info available. openai: 1.60.0 orjson: 3.10.15 packaging<25,>=23.2: Installed. No version info available. pydantic: 2.10.5 pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available. pydantic<3.0.0,>=2.5.2;: Installed. No version info available. pydantic<3.0.0,>=2.7.4: Installed. No version info available. pydantic<3.0.0,>=2.7.4;: Installed. No version info available. pytest: Installed. No version info available. PyYAML>=5.3: Installed. No version info available. requests: 2.32.3 requests-toolbelt: 1.0.0 requests<3,>=2: Installed. No version info available. rich: Installed. No version info available. SQLAlchemy<3,>=1.4: Installed. No version info available. tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available. tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. tiktoken: 0.8.0 typing-extensions>=4.7: Installed. No version info available. zstandard: 0.23.0