Skip to main content
loushoAgent() for Svelte is the React hook as a store: the same sources, the same state and the same actions, over the same typed event stream. Read React for what each field means, the two kinds of source, how approvals work and the server side; this page covers what differs. It lives in the lousho/svelte subpath. The store implements Svelte’s store contract (subscribe(run) => unsubscribe) by hand, so it works with $agent in Svelte 4 and 5 and needs no svelte import: there is no peer dependency to install.
and in the component (a Svelte template, so not type-checked with the other snippets here):

What differs from React

  • State is the store value. $agent is the React hook’s state object: messages, status, pendingApproval, error, usage, finishReason, todos, partialObject and lastEvent. The commands (send, stop, approve, reject, answer) sit on the store itself with the React hook’s signatures; they do not need a subscriber.
  • reset() aborts the run in flight, forgets the in-process session ({ agent, sessionId } starts a new conversation; a remote { url } source gets a new generated chat id) and clears the state.
  • The source and options are plain values, read when a turn starts. To use another agent or url, create another store.
  • Cleanup is unsubscribing. stop() aborts the request in flight, and so does the last subscriber going away (the component using $agent is destroyed). There is no destroy(): this is how Svelte stores stop their work. A transient read that subscribes and unsubscribes in the same turn, like get(agent) from svelte/store, does not count, so it never aborts a run. The store cannot tell such a read from a component that is mounted and destroyed within the same microtask turn (for example created and torn down in one synchronous block, or by a {#if} that flips back before the next microtask): that component’s leaving does not abort the run either. A store nobody subscribes to still runs a turn you started with send(); call stop() yourself if you drop it or if you unmount that quickly.
The reducer and the stream parser are exported from this subpath too (reduceAgentEvents, initialAgentUIState, parseEventStream), the same ones as in lousho/react.

Todos

loushoTodos(agent) is a readable store derived from the loushoAgent() store: $plan is the todo view with todos, counts, current (the in_progress item, else the first pending one) and progress (completed / total). It shows the plan of an agent with the todo tools live, from the same stream as the chat, and notifies only when the list changes (see React).