| 1 |
"""Self-hosted environment runner helpers. |
| 2 |
|
| 3 |
- `anthropic.resources.beta.environments.work.AsyncWork.poller` |
| 4 |
(`client.beta.environments.work.poller(...)`) — control-plane only: claims |
| 5 |
work items, ack's each one, and hands back the work item. Async only (lives on |
| 6 |
`AsyncWork`, not the sync `Work`). The underlying generators are |
| 7 |
`iter_work` / `aiter_work`. |
| 8 |
- `SessionToolRunner` (`client.beta.sessions.events.tool_runner(...)`) |
| 9 |
— the sessions-side counterpart to `client.beta.messages.tool_runner`: |
| 10 |
dispatches local tools against a session's `agent.tool_use` events. |
| 11 |
- `EnvironmentWorker` |
| 12 |
(`client.beta.environments.work.worker(...)`) — the full composition: poll → |
| 13 |
set up the workdir + download the session agent's skills → run a |
| 14 |
`SessionToolRunner` while heartbeating the work-item lease → force-stop |
| 15 |
on exit (unless the lease was lost to another holder) → loop. Build it with |
| 16 |
`client.beta.environments.work.worker(...)` or |
| 17 |
construct it directly: `EnvironmentWorker(client, ...)`; use |
| 18 |
`EnvironmentWorker.handle_item` for the per-item flow when you already |
| 19 |
hold a claimed work item. |
| 20 |
|
| 21 |
The tool implementations themselves (`beta_agent_toolset` and the per-tool |
| 22 |
factories) live next to the other tool helpers — import them from |
| 23 |
`anthropic.lib.tools.agent_toolset`. |
| 24 |
""" |
| 25 |
|
| 26 |
from ._poller import ( |
| 27 |
POLL_BLOCK_MS, |
| 28 |
iter_work, |
| 29 |
aiter_work, |
| 30 |
) |
| 31 |
from ._worker import ( |
| 32 |
MEMORY_FLUSH_TIMEOUT, |
| 33 |
MIN_MEMORY_SYNC_INTERVAL, |
| 34 |
DEFAULT_MEMORY_SYNC_INTERVAL, |
| 35 |
EnvironmentWorker, |
| 36 |
EnvironmentWorkerTools, |
| 37 |
) |
| 38 |
from ..tools._skills import download_session_skills |
| 39 |
from ..tools._beta_session_runner import ( |
| 40 |
DEFAULT_MAX_IDLE, |
| 41 |
MANAGED_AGENTS_BETA, |
| 42 |
SessionToolRunner, |
| 43 |
DispatchedToolCall, |
| 44 |
BetaAnyRunnableTool, |
| 45 |
DispatchedToolUseEvent, |
| 46 |
DispatchedToolResultParams, |
| 47 |
) |
| 48 |
|
| 49 |
__all__ = [ |
| 50 |
"iter_work", |
| 51 |
"aiter_work", |
| 52 |
"POLL_BLOCK_MS", |
| 53 |
"EnvironmentWorker", |
| 54 |
"EnvironmentWorkerTools", |
| 55 |
"DEFAULT_MEMORY_SYNC_INTERVAL", |
| 56 |
"MIN_MEMORY_SYNC_INTERVAL", |
| 57 |
"MEMORY_FLUSH_TIMEOUT", |
| 58 |
"SessionToolRunner", |
| 59 |
"DispatchedToolCall", |
| 60 |
"DispatchedToolUseEvent", |
| 61 |
"DispatchedToolResultParams", |
| 62 |
"BetaAnyRunnableTool", |
| 63 |
"download_session_skills", |
| 64 |
"MANAGED_AGENTS_BETA", |
| 65 |
"DEFAULT_MAX_IDLE", |
| 66 |
] |