useAllemAgent

Agent hook with status tracking, step history, and tool call awareness. Built on the Vercel AI SDK.

import { useAllemAgent } from "@allem-sdk/agents";

Options

PropTypeDefaultDescription
apistringOverride API endpoint from AllemAIProvider
modelstringModel identifier (e.g. "gemini-2.0-flash")
provider"google" | "anthropic" | "openai"Provider name
systemPromptstringSystem prompt sent with requests
headersRecord<string, string>Extra headers merged with provider headers
experimental_throttlenumberThrottle wait in ms for updates

Returns

All properties from UseChatHelpers, plus:

PropertyTypeDescription
agentStatusAgentStatus"idle" | "thinking" | "calling-tool" | "done"
stepsAgentStep[]Ordered list of steps taken in the current turn
currentToolCallsAgentToolCall[]Tool calls from the most recent step
isAgentRunningbooleanWhether the agent is actively processing
messagesUIMessage[]Array of chat messages
sendMessage({ text }): PromiseSend a message to the agent
status"ready" | "submitted" | "streaming"Underlying chat status
stop() => voidStop the agent

Usage

import { AllemAIProvider } from "@allem-sdk/ai";
import { useAllemAgent } from "@allem-sdk/agents";

function App() {
  return (
    <AllemAIProvider api="/api/agent" provider="google">
      <Agent />
    </AllemAIProvider>
  );
}

function Agent() {
  const {
    messages,
    sendMessage,
    agentStatus,
    steps,
    currentToolCalls,
    isAgentRunning,
  } = useAllemAgent();

  return (
    <div>
      {agentStatus === "calling-tool" && (
        <p>Using tool: {currentToolCalls[0]?.toolName}</p>
      )}
      {messages.map((m) => (
        <div key={m.id}>
          {m.parts?.filter((p) => p.type === "text").map((p) => p.text).join("")}
        </div>
      ))}
      <p>Steps taken: {steps.length}</p>
    </div>
  );
}