How to retrieve the current conversation ID inside a tool function in LangGraph?

Is there any built-in way for a LangGraph tool function to access the current conversation (session/thread) ID at runtime? I need this ID for logging and external service correlation, but I can’t find it in the function signature or documentation. Any guidance would be appreciated—thanks!

from langchain_core.tools import tool
from pydantic import BaseModel

class UserAuthStatusInput(BaseModel):
    xxx: str

@tool(args_schema=UserAuthStatusInput)
def xxx_func(xxx: str) -> str:
    # business logic here...
    # TODO: how to retrieve the current conversation/thread ID at this point?
    return "some result"

Related discussion: How to retrieve the current conversation ID inside a tool function in LangGraph? · langchain-ai/langgraph · Discussion #6076 · GitHub

Hey @JIeJaitt you can get the thread_id by doing something like this:

@tool
def dummy_tool(config: RunnableConfig) -> str:
    thread_id = config["configurable"]["thread_id"]
    print(f"Thread ID: {thread_id}")
    return thread_id

Here’s some relevant docs: How to access the RunnableConfig from a tool | 🦜️🔗 LangChain

How to access this thread_id from >1.0.0 in the middleware / tool functions, as the RunnableConfig is replaced by Runtime? Thanks

Hey @alpha-xone! You can access the thread_id through the runtime like this:

from langchain.tools import tool, ToolRuntime
from langchain.agents import create_agent

@tool
def get_thread_id(runtime: ToolRuntime) -> str:
    """Get the thread ID for the current conversation."""
    thread_id = runtime.config["configurable"]["thread_id"]
    return thread_id

agent = create_agent(
    tools=[get_thread_id],
    system_prompt="You are a helpful assistant that can get the thread ID for the current conversation.",
    model="openai:gpt-5-nano",
)
3 Likes

It’s working. Thanks a lot.

Is the ToolRuntime the only place to access this configurable? Can we access it in after_model overrides? Currently we cannot pass the ToolRuntime into the decorated function.

@victor hi Victor, is this achievable? Thanks