ASB
Merged
SA
9h ago+426+426+012345678901234567890123456789-3-3-0123456789
Adds logfire.agent_sandboxes(), which returns a pydantic_monty.AsyncMontyWebsocket pool connected to Logfire Agent Sandboxes.
async with logfire.agent_sandboxes() as pool:
async with pool.checkout() as session:
result = await session.feed_run('1 + 1')
- It's a plain
defreturning the pool, which is already an async context manager, soasync with logfire.agent_sandboxes()works without anawait. - The API key comes from the
api_keyargument, thenconfigure(api_key=...), thenLOGFIRE_API_KEY. Without one it raisesLogfireConfigError. - The URL is
wss://<region host>/monty-ws/, derived from the key's region throughadvanced.generate_base_url(), soadvanced.base_urlfor self-hosted is respected.url=overrides it. - It sends
Authorization: Bearer <key>. A user-suppliedconnect_headersis merged in and wins on conflicts. - It calls
instrument_monty()by default; passinstrument=Falseto skip it. - The other
AsyncMontyWebsocketkwargs are inlined with Monty's defaults. - Requires the new
agent-sandboxesextra (pydantic-monty-client>=1.0.0), which is also forwarded by thelogfiremeta package. - The
logfire-apishim raisesRuntimeError, because there's no no-op pool it could return.
Docs are in #2670 so this can be released for beta testing first. agent_sandboxes is filtered out of reference/api/logfire.md until then.
Tests in tests/test_agent_sandboxes.py use a local WebSocket relay to a real monty subprocess, so code actually runs end to end. I haven't run the full suite locally; CI will tell.
🤖 Generated with Claude Code