Skip to content

Support LangSmith agent destinations and replica routing in Python - #115

Merged
patbeqo merged 9 commits into
mainfrom
feat/langsmith-agent-destinations
Nov 5, 2026
Merged

patbeqo merged 9 commits into
mainfrom
feat/langsmith-agent-destinations

Conversation

@brianstrauch

@brianstrauch brianstrauch commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Add agent/environment destinations and write replicas to the Python LangSmith adapter. Existing parent destinations take precedence; new roots use native LangSmith destination selection with the plugin configuration as a fallback.

  • Add an optional address to the plugin and interceptor, mutually exclusive with the project option. Propagate destinations through Activities, child Workflows, and Nexus, including when Temporal operation runs are disabled.
  • Preserve sanitized replica routing across process boundaries. Destination identifiers, routing flags, and permitted annotation updates propagate; credentials, ingestion URLs, and client objects stay local to each process.
  • Make native Python RunTree instances replay-safe within plugin workflows. Use deterministic IDs and workflow time, send writes through the worker executor, and suppress writes during replay. @traceable and sync/async trace() blocks create real roots and retain LangSmith's own routing rules.

Agent addressing requires Python LangSmith 0.14.4 and the LangSmith workspace-enabled beta feature. Project-based tracing remains compatible with LangSmith 0.12.6.

TypeScript companion: #314.

Validation:

  • Python 3.14 / LangSmith 0.14.4: lint and all 207 tests pass, including a fresh-worker replay that compares native root/child IDs, timestamps, and dotted ordering and verifies no duplicate writes.
  • LangSmith 0.12.6 compatibility: 162 tests pass; version-specific tests skip.
  • Python wheel/sdist build and content checks, and repository conventions pass.

Allow LangSmith versions below 0.15 in the Deep Agents and LangSmith plugins. Refresh all three Python LangSmith locks to 0.14.4 and update the LangChain dependencies required by Deep Agents 0.7.21.

Closes #105
Add optional agent/environment addresses to the LangSmith plugin and interceptor, preserve native decorator and tracing-context destination selection, and propagate destinations through Temporal boundaries.

Carry sanitized replica routing in headers when LangSmith omits it, inherit replicas on generated Temporal runs, and restore parent timestamps from persisted trace ordering for stable replay. Verify primary and secondary IDs, complete trace trees, matching updates, and silent parent/child history replay.
@brianstrauch
brianstrauch requested a review from a team as a code owner October 19, 2026 23:12
Base automatically changed from fix/langsmith-dependency-range to main October 20, 2026 15:55
Resolve LangSmith destination and replica routing conflicts while preserving startup destination resolution, native traceable overrides, and untraced workflow replay from main. Keep main's updated dependency locks.

@patbeqo patbeqo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we split the TypeScript changes into a separate PR? It'd be easier to review on its own, and some of the Python feedback will probably carry over.

Resolve LangSmith destination conflicts by retaining parent destination inheritance from main alongside agent address fallbacks and replica propagation.
Replace the placeholder root factory and trace setup override with scoped native RunTree lifecycle hooks. Use workflow time for reconstructed parents, keep Nexus defaults, and retain native destination and replica selection. Cover native tracing APIs, worker replay, background I/O, and local client fallback.

@patbeqo patbeqo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python looks good. Could we split TypeScript into its own PR and use the same install_run_tree_overrides approach there?

@brianstrauch brianstrauch changed the title Support LangSmith agent destinations and replica routing in Python and TypeScript Support LangSmith agent destinations and replica routing in Python Oct 30, 2026
@brianstrauch
brianstrauch requested a review from patbeqo November 2, 2026 22:47
patbeqo
patbeqo previously approved these changes Nov 3, 2026
tracing_args: dict[str, Any] = {
"client": self._config._client,
"parent": parent,
**_destination(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plugin's project_name/address should act as a default, so @traceable(address=...) wins over it like upstream LangSmith (and like the TypeScript plugin in #314). Putting it in tracing_context makes it override the decorator instead.

Could we drop it from tracing_args here (and in the activity/Nexus interceptors) and instead patch run_helpers._resolve_traceable_addressing to use the plugin's destination after the decorator, before configure/env? Same approach as _resolveAddressing in TypeScript.

@patbeqo
patbeqo dismissed their stale review November 3, 2026 16:42

Found 1 more discrepancy between our integration and upstream Langsmith

@patbeqo patbeqo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last change.

@brianstrauch
brianstrauch requested a review from patbeqo November 5, 2026 22:07
@patbeqo
patbeqo merged commit bfa245e into main Nov 5, 2026
15 checks passed
@patbeqo
patbeqo deleted the feat/langsmith-agent-destinations branch November 5, 2026 22:18
campoy added a commit that referenced this pull request Nov 13, 2026
## What was changed

- `LangSmithPlugin` and `LangSmithInterceptor` take an `AgentAddress`
and check it with `langsmith.address.ensure_agent`. On LangSmith older
than 0.14.10, `address=` raises a clear error. Project-based tracing
still works there.
- The plugin now needs LangSmith 0.14 or later. The floor is
`langsmith>=0.14.2`, since 0.14.0 and 0.14.1 were already excluded.
Every release from 0.14.2 on has `_resolve_traceable_addressing`,
`_addressing_tiers` and `RunTree.address`, so the plugin uses them
directly. That drops the `_setup_run` and `_get_project_name` fallback
for older releases, and the tests that faked them. CI doesn't run any
release before 0.14, so only those fakes checked that code.
- Replica addresses now survive a hop across Temporal. LangSmith still
leaves replicas out of `to_headers()`, so the plugin writes them itself,
but it wrote each address as a JSON dict. LangSmith only reads a replica
address back in its `lrn:` form (`lrn:agents/<id>/environments/<env>`,
the same form it writes for a run's own address), so it logged "Ignoring
an unusable address in a `baggage` header" and dropped it. The plugin
now writes that `lrn:` form itself, without importing anything from
`langsmith._internal`. Two existing tests read it back with the public
`RunTree.from_headers`, so if LangSmith ever changes the format, CI
tells us.
- `uv.lock` moves LangSmith from 0.14.4 to 0.14.12. Tests and the README
build addresses with `agent_address`.

`address=` came in with #115 and hasn't been released yet (the last
release, 0.1.1, came out on 10-28), so nobody depends on the string
form.

## Why?

The langsmith nightly has been red since #115 merged. Why? LangSmith
changed what an agent address is, and the plugin still speaks the old
format.

In LangSmith 0.14.4, the version we lock, an address is a string like
`"lrn:agents/support/environments/staging"`, and
`langsmith.address.parse` reads it. From 0.14.10 on, the string and
`parse` are gone. An address is now an `AgentAddress` dict that you
build with `langsmith.agent_address("support", "staging")`, and
LangSmith rejects strings. The nightly installs 0.14.12, so `address=`
fails with 7 pyright errors and 22 failing tests.

The other two nightly failures already have fixes: google_adk in #446
and openai_agents in #447.

## Checklist

1. Fixes #413.

2. How was this tested:

I ran `make lint` and `make test` with four sets of dependencies:

| Dependencies | LangSmith | Lint | Tests |
|---|---|---|---|
| This lock | 0.14.12 | pass | 295 passed |
| Latest allowed (nightly) | 0.14.16 | pass | 295 passed |
| Latest, plus newest LangSmith | 0.14.17 | pass | 295 passed |
| Lowest allowed LangSmith | 0.14.2 | not run | 173 passed |

On 0.14.2, I skipped the 3 test files that build addresses with
`agent_address`, since it only came in 0.14.9. Everything else passes
there.

0.14.17 comes out of the 2-week cooldown in 3 days, and it doesn't break
this again.

3. Any docs updates needed? Done here: the `python/langsmith` README
builds addresses with `agent_address`.

Let me know what you think!

---------

Co-authored-by: Brian Strauch <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants