Skip to content
This repository was archived by the owner on Nov 11, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion python/langsmith/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""LangSmith Client."""

from typing import TYPE_CHECKING, Any, Final
Expand Down Expand Up @@ -26,6 +26,9 @@
AgentAddress,
EvaluatorAddress,
ExperimentAddress,
agent_address,
evaluator_address,
experiment_address,
)
from langsmith.async_client import AsyncClient
from langsmith.client import Client, TracingMode
Expand Down Expand Up @@ -131,7 +134,15 @@

# `from langsmith import address` would re-enter this hook.
return importlib.import_module("langsmith.address")
elif name in ("Address", "AgentAddress", "EvaluatorAddress", "ExperimentAddress"):
elif name in (
"Address",
"AgentAddress",
"EvaluatorAddress",
"ExperimentAddress",
"agent_address",
"experiment_address",
"evaluator_address",
):
from langsmith import address

return getattr(address, name)
Expand Down Expand Up @@ -270,6 +281,9 @@
"AgentAddress",
"ExperimentAddress",
"EvaluatorAddress",
"agent_address",
"experiment_address",
"evaluator_address",
"get_current_run_tree",
"set_run_metadata",
"ContextThreadPoolExecutor",
Expand Down
18 changes: 9 additions & 9 deletions python/langsmith/_internal/_addressing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
to a project. This API may change without notice.

A run goes to exactly one destination: a project (`project_name`) or an
address (`langsmith.AgentAddress(id, environment)`), which
address (`ls.agent_address(id, environment)`), which
names an agent and one of its environments. The server resolves an address to
the agent environment's project, so traces follow the agent rather than a
project name. Project addressing keeps working alongside it.
Expand Down Expand Up @@ -69,7 +69,7 @@ def normalize_replicas(replicas: Optional[Any]) -> Optional[list]:
return None
normalized = []
for replica in replicas:
if not isinstance(replica, Mapping):
if not isinstance(replica, Mapping) or "kind" in replica:
normalized.append({"address": check_address(replica)})
continue
normalized_replica = dict(replica)
Expand Down Expand Up @@ -117,7 +117,7 @@ def resolve(*tiers: Tier) -> tuple[Optional[str], Optional[AgentAddress]]:
if address is not None:
return None, address
env_project = utils.get_tracer_project(return_default_value=False) or None
env_address = AgentAddress.from_env()
env_address = _address.address_from_env()
if env_project and env_address is not None:
raise EnvAddressError(
str(_both_at_one_level(env_project, env_address, "in the environment"))
Expand Down Expand Up @@ -162,8 +162,8 @@ def otlp_destination_headers(
"""
if address is not None:
return {
"Langsmith-Agent-Id": address.id,
"Langsmith-Agent-Environment": address.environment,
"Langsmith-Agent-Id": address["id"],
"Langsmith-Agent-Environment": address["environment"].lower(),
}
return {"Langsmith-Project": project} if project else {}

Expand Down Expand Up @@ -191,7 +191,7 @@ def warn_on_env() -> None:
if not present:
return
try:
address = AgentAddress.from_env()
address = _address.address_from_env()
except EnvAddressError as e:
warnings.warn(
f"{e} Calls that name no destination in code are not traced.",
Expand Down Expand Up @@ -254,7 +254,7 @@ def apply_to_payload(payload: dict, *, update: bool = False) -> None:
# Wire data already applied: a retried batch re-sends it. It is parsed
# again, so a malformed one cannot fail the whole batch in the backend.
try:
address = AgentAddress._from_lrn(address)
address = _address.address_from_lrn(address)
except utils.LangSmithUserError:
raise utils.LangSmithUserError(
"The run's `address` is not a valid agent address."
Expand All @@ -265,11 +265,11 @@ def apply_to_payload(payload: dict, *, update: bool = False) -> None:
payload.get("session_id") is not None or payload.get("session_name") is not None
)
if address is None and not (update or named_project):
address = AgentAddress.from_env()
address = _address.address_from_env()
if address is None:
return
warn_is_beta()
payload["address"] = address._lrn()
payload["address"] = _address.address_to_lrn(address)
if not named_project:
payload.pop("session_name", None)
payload.pop("session_id", None)
4 changes: 2 additions & 2 deletions python/langsmith/_internal/otel/_otel_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from langsmith import utils as ls_utils
from langsmith._internal import _addressing
from langsmith.address import AgentAddress, EnvAddressError
from langsmith.address import EnvAddressError, address_from_env


def _import_otel_client():
Expand Down Expand Up @@ -67,7 +67,7 @@ def _destination_headers() -> dict[str, str]:
there is nothing to address.
"""
try:
address = AgentAddress.from_env()
address = address_from_env()
except EnvAddressError:
return {}
if address is not None:
Expand Down
Loading
Loading