Svelte
The samai-sdk/svelte subpath exports useAgent(client, agent) as a Svelte store — subscribe with $agent in a .svelte file.
SupportChat.svelte
<script>
import { createClient, anthropic, defineAgent } from "samai-sdk";
import { useAgent } from "samai-sdk/svelte";
const client = createClient({ provider: anthropic({ apiKey: import.meta.env.VITE_ANTHROPIC_API_KEY }) });
const supportAgent = defineAgent({ name: "support_agent", instructions: "...", model: "claude-sonnet-4-6" });
const agent = useAgent(client, supportAgent);
</script>
<button on:click={() => agent.run("How do I add a handoff?")} disabled={$agent.isRunning}>Ask</button>
<p>{$agent.text}</p>
{#if $agent.error}<p>Error: {$agent.error.message}</p>{/if}
{#if $agent.result}<p>Done — final agent: {$agent.result.finalAgent}</p>{/if}Store shape
agent.run()/agent.reset() are called directly on the store object; every other field comes through the $agent subscription. svelte is an optional peer dependency. See examples/svelte-usage-mock-test.ts, which exercises this against a real store subscription.All three framework hooks (React/Vue/Svelte) are thin wrappers around runAgentStream() — none of them own any agent-loop logic themselves.