LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Client
  • AsyncClient
  • Run Helpers
  • Run Trees
  • Evaluation
  • Schemas
  • Utilities
  • Wrappers
  • Anonymizer
  • Testing
  • Expect API
  • Middleware
  • Pytest Plugin
  • Deployment SDK
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewClientAsyncClientRun HelpersRun TreesEvaluationSchemasUtilitiesWrappersAnonymizerTestingExpect APIMiddlewarePytest PluginDeployment SDK
Language
Theme
Pythonlangsmith_runtime_overridesset_runtime_overrides
Function●Since v0.7

set_runtime_overrides

Copy
set_runtime_overrides(
    aio_to_thread: Optional[AioToThread] = None,
) -> None
View source on GitHub

Parameters

NameTypeDescription
aio_to_threadOptional[AioToThread]
Default:None

Custom async function to run sync functions asynchronously. Should have signature: async def aio_to_thread( default_aio_to_thread, ctx, func, /, *args, **kwargs ). default_aio_to_thread is LangSmith's default implementation, which the override can call to fall back to default behavior. The implementation must invoke func inside ctx (e.g. ctx.run(func, *args, **kwargs)) so that LangSmith's tracing state, which is read back from ctx after the call, is visible to downstream code. Pass None to use the default implementation.

Set LangSmith runtime overrides.

This allows customizing LangSmith's async runtime behavior for environments with constrained async runtimes (e.g., Temporal, which doesn't support run_in_executor).

Example:

For Temporal or similar runtimes:

import langsmith

async def temporal_aio_to_thread(
    default_aio_to_thread, ctx, func, /, *args, **kwargs
):
    # Use the default implementation when not in a workflow
    if not temporalio.workflow.in_workflow():
        return await default_aio_to_thread(ctx, func, *args, **kwargs)
    with temporalio.workflow.unsafe.sandbox_unrestricted():
        return ctx.run(func, *args, **kwargs)

langsmith.set_runtime_overrides(aio_to_thread=temporal_aio_to_thread)

Reset to defaults:

langsmith.set_runtime_overrides()