mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-01 10:53:14 +00:00
feat: persist sandbox_id to thread metadata via client.threads.update
This commit is contained in:
parent
7972ebf481
commit
0c59811ee4
1 changed files with 34 additions and 1 deletions
|
|
@ -63,11 +63,44 @@ def create_langsmith_sandbox(
|
|||
template_name, template_image = _get_sandbox_template_config()
|
||||
|
||||
provider = LangSmithProvider(api_key=api_key)
|
||||
return provider.get_or_create(
|
||||
backend = provider.get_or_create(
|
||||
sandbox_id=sandbox_id,
|
||||
template=template_name,
|
||||
template_image=template_image,
|
||||
)
|
||||
_update_thread_sandbox_metadata(backend.id)
|
||||
return backend
|
||||
|
||||
|
||||
def _update_thread_sandbox_metadata(sandbox_id: str) -> None:
|
||||
"""Update thread metadata with sandbox_id."""
|
||||
try:
|
||||
import asyncio
|
||||
|
||||
from langgraph.config import get_config
|
||||
from langgraph_sdk import get_client
|
||||
|
||||
config = get_config()
|
||||
thread_id = config.get("configurable", {}).get("thread_id")
|
||||
if not thread_id:
|
||||
return
|
||||
client = get_client()
|
||||
|
||||
async def _update() -> None:
|
||||
await client.threads.update(
|
||||
thread_id=thread_id,
|
||||
metadata={"sandbox_id": sandbox_id},
|
||||
)
|
||||
|
||||
try:
|
||||
loop = asyncio.get_running_loop()
|
||||
except RuntimeError:
|
||||
asyncio.run(_update())
|
||||
else:
|
||||
loop.create_task(_update())
|
||||
except Exception:
|
||||
# Best-effort: ignore failures (no config context, client unavailable, etc.)
|
||||
pass
|
||||
|
||||
|
||||
class SandboxProvider(ABC):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue