feat(trace):LangGraph -> lead_agent and set custom agent_name to run_name (#3101)

* feat(trace):LangGraph -> lead_agent and set user custom agent name to run_name

* feat(trace):follow github copilot suggest

* feat(trace):Refactor run_name resolution and improve test coverage
This commit is contained in:
Airene Fang
2026-05-21 14:48:28 +08:00
committed by GitHub
parent 8b697245eb
commit 923f516deb
6 changed files with 162 additions and 0 deletions
@@ -0,0 +1,16 @@
"""Run naming helpers for LangChain/LangSmith tracing."""
from __future__ import annotations
from collections.abc import Mapping
from typing import Any
def resolve_root_run_name(config: Mapping[str, Any], assistant_id: str | None) -> str:
for container_name in ("context", "configurable"):
container = config.get(container_name)
if isinstance(container, Mapping):
agent_name = container.get("agent_name")
if isinstance(agent_name, str) and agent_name.strip():
return agent_name
return assistant_id or "lead_agent"
@@ -33,6 +33,7 @@ from deerflow.runtime.serialization import serialize
from deerflow.runtime.stream_bridge import StreamBridge
from .manager import RunManager, RunRecord
from .naming import resolve_root_run_name
from .schemas import RunStatus
logger = logging.getLogger(__name__)
@@ -224,6 +225,9 @@ async def run_agent(
if journal is not None:
config.setdefault("callbacks", []).append(journal)
# Resolve after runtime context installation so context/configurable reflect
# the agent name that this run will actually execute.
config.setdefault("run_name", resolve_root_run_name(config, record.assistant_id))
runnable_config = RunnableConfig(**config)
if ctx.app_config is not None and _agent_factory_supports_app_config(agent_factory):
agent = agent_factory(config=runnable_config, app_config=ctx.app_config)