unregisterAgent method

Future<bool> unregisterAgent(
  1. String id
)

Removes the agent registered under id and cleans up its state: its live sequence (multi-sequence mode), its RAM stash entry, and its disk snapshot. Returns false when no such agent was registered.

The handle (and any agent built on its AgentHandle.chatClient) stops working: its next request would re-register nothing and throws through sessionFor.

Implementation

Future<bool> unregisterAgent(String id) => _tasks.run(() async {
  final handle = _agents.remove(id);
  if (handle == null) return false;
  _lastUsed.remove(id);
  final session = _session;
  if (session != null) {
    final seq = _agentSequence.remove(id);
    if (seq != null) {
      await session.clearSequence(seq);
      _freeSequences.add(seq);
    }
    await _dropStash(session, id);
  } else {
    _stashBytes -= _stashed.remove(id)?.bytes ?? 0;
  }
  final spec = _spec;
  if (spec != null) await _snapshots.invalidate(spec.id, id);
  if (_activeAgentId == id) _activeAgentId = null;
  _logger.logDebug('Agent "$id" unregistered.');
  _emit(AgentUnregisteredEvent(agentId: id));
  return true;
});