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"
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",
)
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.