mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-03 08:03:28 +00:00
Merge pull request #944 from langchain-ai/yogesh/resolve-circular-import
fix: resolve circular import in commit_and_open_pr
This commit is contained in:
commit
c173ff28dd
3 changed files with 50 additions and 51 deletions
|
|
@ -23,6 +23,54 @@ from deepagents.backends.sandbox import BaseSandbox
|
||||||
from langsmith.sandbox import Sandbox, SandboxClient, SandboxTemplate
|
from langsmith.sandbox import Sandbox, SandboxClient, SandboxTemplate
|
||||||
|
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
|
||||||
|
def _get_sandbox_template_config() -> tuple[str | None, str | None]:
|
||||||
|
"""Get sandbox template configuration from environment.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Tuple of (template_name, template_image) from environment variables.
|
||||||
|
Values are None if not set in environment.
|
||||||
|
"""
|
||||||
|
template_name = os.environ.get("DEFAULT_SANDBOX_TEMPLATE_NAME")
|
||||||
|
template_image = os.environ.get("DEFAULT_SANDBOX_TEMPLATE_IMAGE")
|
||||||
|
return template_name, template_image
|
||||||
|
|
||||||
|
|
||||||
|
def _create_langsmith_sandbox(
|
||||||
|
sandbox_id: str | None = None,
|
||||||
|
) -> SandboxBackendProtocol:
|
||||||
|
"""Create or connect to a LangSmith sandbox without automatic cleanup.
|
||||||
|
|
||||||
|
This function directly uses the LangSmithProvider to create/connect to sandboxes
|
||||||
|
without the context manager cleanup, allowing sandboxes to persist across
|
||||||
|
multiple agent invocations.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
sandbox_id: Optional existing sandbox ID to connect to.
|
||||||
|
If None, creates a new sandbox.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
SandboxBackendProtocol instance
|
||||||
|
"""
|
||||||
|
api_key = _get_langsmith_api_key()
|
||||||
|
template_name, template_image = _get_sandbox_template_config()
|
||||||
|
|
||||||
|
provider = LangSmithProvider(api_key=api_key)
|
||||||
|
return provider.get_or_create(
|
||||||
|
sandbox_id=sandbox_id,
|
||||||
|
template=template_name,
|
||||||
|
template_image=template_image,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SandboxProvider(ABC):
|
class SandboxProvider(ABC):
|
||||||
"""Interface for creating and deleting sandbox backends."""
|
"""Interface for creating and deleting sandbox backends."""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,56 +36,7 @@ from .middleware import (
|
||||||
)
|
)
|
||||||
from .prompt import construct_system_prompt
|
from .prompt import construct_system_prompt
|
||||||
from .tools import commit_and_open_pr, fetch_url, http_request
|
from .tools import commit_and_open_pr, fetch_url, http_request
|
||||||
|
from .integrations.langsmith import _create_langsmith_sandbox
|
||||||
|
|
||||||
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")
|
|
||||||
|
|
||||||
|
|
||||||
def _get_sandbox_template_config() -> tuple[str | None, str | None]:
|
|
||||||
"""Get sandbox template configuration from environment.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Tuple of (template_name, template_image) from environment variables.
|
|
||||||
Values are None if not set in environment.
|
|
||||||
"""
|
|
||||||
template_name = os.environ.get("DEFAULT_SANDBOX_TEMPLATE_NAME")
|
|
||||||
template_image = os.environ.get("DEFAULT_SANDBOX_TEMPLATE_IMAGE")
|
|
||||||
return template_name, template_image
|
|
||||||
|
|
||||||
|
|
||||||
def _create_langsmith_sandbox(
|
|
||||||
sandbox_id: str | None = None,
|
|
||||||
) -> SandboxBackendProtocol:
|
|
||||||
"""Create or connect to a LangSmith sandbox without automatic cleanup.
|
|
||||||
|
|
||||||
This function directly uses the LangSmithProvider to create/connect to sandboxes
|
|
||||||
without the context manager cleanup, allowing sandboxes to persist across
|
|
||||||
multiple agent invocations.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
sandbox_id: Optional existing sandbox ID to connect to.
|
|
||||||
If None, creates a new sandbox.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
SandboxBackendProtocol instance
|
|
||||||
"""
|
|
||||||
from .integrations.langsmith import LangSmithProvider
|
|
||||||
|
|
||||||
api_key = _get_langsmith_api_key()
|
|
||||||
template_name, template_image = _get_sandbox_template_config()
|
|
||||||
|
|
||||||
provider = LangSmithProvider(api_key=api_key)
|
|
||||||
return provider.get_or_create(
|
|
||||||
sandbox_id=sandbox_id,
|
|
||||||
template=template_name,
|
|
||||||
template_image=template_image,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
client = get_client()
|
client = get_client()
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ from typing import Any
|
||||||
from langgraph.config import get_config
|
from langgraph.config import get_config
|
||||||
|
|
||||||
from ..encryption import decrypt_token
|
from ..encryption import decrypt_token
|
||||||
from ..server import _create_langsmith_sandbox
|
from ..integrations.langsmith import _create_langsmith_sandbox
|
||||||
from ..utils.github import (
|
from ..utils.github import (
|
||||||
create_github_pr,
|
create_github_pr,
|
||||||
get_github_default_branch,
|
get_github_default_branch,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue