#346

Implement ai.workers: Worker, WorkerProvider and Session

Draftanbuzinwants to merge intofrom

One of two competing drafts for ai.workers. The other is #347.

A worker is one session of a coding-agent CLI (Codex, Claude Code, Pi). In this draft it has the shape of an ai.Model: plain data and a provider.

  • Worker: the settings and the state (session_id, messages).
  • WorkerProvider: name, executable, env, and the stream() that ai.stream and ai.Agent.run call.
  • Session: direct control (start, send, events, interrupt, close).
worker = workers.Codex(cwd=".")
async with worker.session() as session:
    async with agent.run(worker, messages) as run: ...
    await session.send(ai.user_message("And the tests?"))

Compared with #347

  • Core changes less. ai.stream still calls model.provider.stream(model, ...); the diff outside ai/workers is Model -> ModelLike annotations, one aclosing block in api.py, the Context.model annotation, and a new models/core/model_like.py with the two protocols. model.py, hooks.py and ai/__init__.py are as on main.
  • Direct control is on a separate Session, not on the worker. The CLI starts on first use inside async with worker.session(), and a model call outside that block raises.
  • Not here, and in #347: approvals through hooks, output_type, fork() and sync().

Status

  • Offline tests, ruff, mypy (src tests) and ty pass locally.
  • The live tests (AI_WORKERS_LIVE=1 uv run pytest tests/workers/test_live.py) were not run on the last commit.

Activity

10
A
e299fef
vercel[bot]2d ago

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated
ai-python ReadyPreview, v0Nov 10, 2026 10:45pm UTC
socket-security[bot]2d ago

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

DiffPackageSupply Chain
Security
VulnerabilityQualityMaintenanceLicense
pypi/​claude-agent-sdk@​0.2.179

View full report

vercel-internal-security-reviewer[bot]2d ago

This pull request is a draft

Merging is unavailable until it is marked ready for review.