LangGraph version: 1.0.9
I have an async tool that uses InjectedState to inject a namespace from graph state, and returns a Command to update state alongside the tool message. When the tool is called by the LLM, I consistently get the following ToolMessage:
Error invoking tool 'knowledge_search' with kwargs {'query': '...'} with error:
Please fix the error and try again.
Notice the {error} slot is empty — which means the underlying exception has no message (str(e) == ""). The generic message comes from TOOL_INVOCATION_ERROR_TEMPLATE in the LangGraph source.
Tool definition
@tool
async def knowledge_search(
query: Annotated[str, "The search query to find relevant knowledge"],
namespace: Annotated[str, InjectedState("namespace")],
tool_call_id: Annotated[str, InjectedToolCallId],
) -> str | Command:
"""Search the business knowledge base."""
if not namespace:
return "Knowledge base is not available."
results = await knowledge_similarity_search(namespace=namespace, query=query, n=3)
if not results:
return "No relevant information found in the knowledge base."
sources = [doc.get("metadata", {}).get("title") or doc.get("metadata", {}).get("source") for doc in results]
content = "\n\n".join([doc["content"] for doc in results])
return Command(
update={
"knowledge_source": sources,
"messages": [ToolMessage(content=content, tool_call_id=tool_call_id)],
}
)
What is the possible reason for this error? Any help appreciated. Happy to share more context.