From 3e64399d133064573cb4e405dbaf8e02571d6fd9 Mon Sep 17 00:00:00 2001 From: Palash Shah <35114859+Palashio@users.noreply.github.com> Date: Tue, 17 Mar 2026 13:49:32 -0400 Subject: [PATCH] feat: inject LANGSMITH_AGENT_VERSION metadata into all run creation calls (#1066) Reads LANGCHAIN_REVISION_ID env var (set by LSD from LANGSMITH_LANGGRAPH_GIT_REF_SHA) and injects it as LANGSMITH_AGENT_VERSION metadata on every runs.create() call. This enables the agent_deployments sync job to track which agent version produced each trace. Co-authored-by: Claude Sonnet 4.6 --- agent/webapp.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/agent/webapp.py b/agent/webapp.py index c07a7270..7564d55e 100644 --- a/agent/webapp.py +++ b/agent/webapp.py @@ -66,6 +66,12 @@ LANGGRAPH_URL = os.environ.get("LANGGRAPH_URL") or os.environ.get( "LANGGRAPH_URL_PROD", "http://localhost:2024" ) +_AGENT_VERSION_METADATA: dict[str, str] = ( + {"LANGSMITH_AGENT_VERSION": os.environ["LANGCHAIN_REVISION_ID"]} + if os.environ.get("LANGCHAIN_REVISION_ID") + else {} +) + ALLOWED_GITHUB_ORGS: frozenset[str] = frozenset( org.strip().lower() for org in os.environ.get("ALLOWED_GITHUB_ORGS", "").split(",") @@ -683,7 +689,7 @@ async def process_linear_issue( # noqa: PLR0912, PLR0915 thread_id, "agent", input={"messages": [{"role": "user", "content": content_blocks}]}, - config={"configurable": configurable}, + config={"configurable": configurable, "metadata": _AGENT_VERSION_METADATA}, if_not_exists="create", ) logger.info("LangGraph run created successfully for thread %s", thread_id) @@ -798,7 +804,7 @@ async def process_slack_mention(event_data: dict[str, Any], repo_config: dict[st thread_id, "agent", input={"messages": [{"role": "user", "content": content_blocks}]}, - config={"configurable": configurable}, + config={"configurable": configurable, "metadata": _AGENT_VERSION_METADATA}, if_not_exists="create", multitask_strategy="interrupt", ) @@ -1150,7 +1156,8 @@ async def _trigger_or_queue_run( "github_login": github_login, "repo": repo_config, "pr_number": pr_number, - } + }, + "metadata": _AGENT_VERSION_METADATA, }, if_not_exists="create", ) @@ -1373,7 +1380,7 @@ async def process_github_issue(payload: dict[str, Any], event_type: str) -> None thread_id, "agent", input={"messages": [{"role": "user", "content": prompt}]}, - config={"configurable": configurable}, + config={"configurable": configurable, "metadata": _AGENT_VERSION_METADATA}, if_not_exists="create", ) logger.info("LangGraph run created for thread %s from GitHub issue", thread_id)