LemonAgent.AbortSignal (lemon_agent v0.1.0)

View Source

Cooperative, ETS-backed abort signalling for the agent loop and tools.

A signal is a plain reference/0. The loop checks it before each LLM call and tool batch; long-running tools should check it too and stop early when it is set, so cancellation is graceful rather than forced:

def execute(args, %{abort_signal: signal} = _ctx) do
  if LemonAgent.AbortSignal.aborted?(signal), do: throw(:aborted)
  # ...
end

Reads and writes go through a :public ETS table with read/write concurrency, so aborted?/1 is cheap to call in a hot loop. A long-lived owner process holds the table as its heir, so it survives a producer crash.

Summary

Functions

abort(ref)

@spec abort(reference()) :: :ok

aborted?(ref)

@spec aborted?(reference() | nil) :: boolean()

clear(ref)

@spec clear(reference() | nil) :: :ok

new()

@spec new() :: reference()