feat: add LANGSMITH_API_KEY_PROD fallback for LangGraph Cloud

Add helper function to check LANGSMITH_API_KEY first, then fall back to
LANGSMITH_API_KEY_PROD for LangGraph Cloud deployments where
LANGSMITH_API_KEY is reserved by the platform.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
aran-yogesh 2026-02-05 17:36:05 -08:00
parent 9c29e3c9e0
commit db2a755463

View file

@ -42,9 +42,21 @@ from deepagents_cli.tools import fetch_url, http_request, web_search
from .encryption import decrypt_token
def _get_langsmith_api_key() -> str | None:
"""Get LangSmith API key from environment.
Checks LANGSMITH_API_KEY first, then falls back to LANGSMITH_API_KEY_PROD
for LangGraph Cloud deployments where LANGSMITH_API_KEY is reserved.
"""
return os.environ.get("LANGSMITH_API_KEY") or os.environ.get("LANGSMITH_API_KEY_PROD")
@asynccontextmanager
async def create_sandbox_async(provider: str, **kwargs):
"""Async wrapper around create_sandbox for compatibility."""
# For langsmith provider, pass the API key explicitly
if provider == "langsmith" and "api_key" not in kwargs:
kwargs["api_key"] = _get_langsmith_api_key()
with create_sandbox(provider, **kwargs) as sandbox:
yield sandbox