Agent creation, ownership, and cancellation
An agent is not a while loop; it is a live object with identity, session, inbox, context, and quiescence
create/resume → setup transaction → publish → disposeWho may destroy an agent, and how does a half-failed creation roll back?
AgentHandle is like the key and lease contract for a vehicle. The registry can locate it, but only the owner holding the contract can terminate the lease and complete teardown.
Mechanism
ctx.agents.create/resume returns an AgentHandle. setup builds agent.ctx before agent and session publication and may return a synchronous commit; failure rolls both identities back.
cancel requests convergence of current activity; whenIdle follows replacement work until true quiescence; dispose stops the loop, unregisters, removes the in-memory session, then unwinds local context.
Allocate identity
AgentId and SessionId share one branded identity.
What extensions must preserve
- Agent and session identities publish together or not at all
- Cancellation cause is first-wins and never arms future work
- Holding dispose authority is itself a capability
The tempting wrong turns
- ×Treating a bare Agent from ctx.agents.get() as disposal authority
- ×Treating whenIdle as acknowledgement for one message
- ×Removing provider services immediately after cancellation
Do not trust the conclusion—verify it
These anchors are pinned to official deepseek-harness@47f9438; account for later breaking changes when reading current upstream.
Pause for ten seconds before revealing
How do Agent.cancel() and AgentHandle.dispose() differ?
An agent's durable identity depends on its session. Next we unpack SessionEvent as the system's source of truth.