Agents
Query, create, update, publish, version, and generate prompts for AI voice agents using the React SDK.
Agents are the core resource in ScaleAI. Each agent encapsulates a voice personality, prompt, tool configuration, and deployment status. The SDK exposes a full set of TanStack Query hooks for listing, mutating, versioning, and AI-assisted prompt generation.
Fetching agents
useAgents
useAgents(params?) fetches a paginated list of AgentListItem records. All parameters are optional — call it with no arguments to load the first page of all agents.
import { useAgents } from "@scalereal/sr-voice-engine-react-sdk/hooks";
export function AgentList() {
const { data, isPending, isError } = useAgents({
status: "published",
sort_by: "-updated_at",
page: 1,
size: 20,
});
if (isPending) return <p>Loading agents…</p>;
if (isError) return <p>Failed to load agents.</p>;
return (
<ul>
{data.results.map((agent) => (
<li key={agent.id}>{agent.name}</li>
))}
</ul>
);
}Parameters — ListAgentsParams
| Parameter | Type | Description |
|---|---|---|
page | number | 1-based page number. |
size | number | Number of records per page. |
search | string | Free-text search across agent names. |
agent_type | "single_prompt" | "workflow" | Filter to a specific agent type. |
status | "draft" | "published" | Filter by publish status. |
is_active | boolean | true returns only active agents; false returns archived agents. |
language | string | Filter by language code (e.g. "en"). |
workflow_id | string | Filter agents attached to a specific workflow. |
knowledgebase_id | string | Filter agents that use a specific knowledge base. |
sort_by | string | Sort field: created_at, updated_at, or name. Prefix with - for descending (e.g. -updated_at). |
Return type
PaginatedResponse<AgentListItem> — includes results, total, page, and size.
useAgentDetails
useAgentDetails(agentId, enabled?) fetches the full AgentDetail for a single agent. The query is automatically disabled when agentId is an empty string, so it's safe to call before you have an ID.
import { useAgentDetails } from "@scalereal/sr-voice-engine-react-sdk/hooks";
export function AgentDetail({ agentId }: { agentId: string }) {
const { data, isPending } = useAgentDetails(agentId);
if (isPending) return <p>Loading…</p>;
return <h1>{data?.name}</h1>;
}| Parameter | Type | Description |
|---|---|---|
agentId | string | The agent's ID. Pass an empty string to keep the query idle. |
enabled | boolean | Explicitly disable the query without changing agentId. Optional. |
Creating and updating agents
useCreateAgent
Creates a new agent and returns the full Agent object. After a successful mutation, the agents list cache is automatically invalidated.
import { useCreateAgent } from "@scalereal/sr-voice-engine-react-sdk/hooks";
export function CreateAgentButton() {
const { mutate, isPending } = useCreateAgent();
return (
<button
type="button"
disabled={isPending}
onClick={() =>
mutate({
name: "Support Assistant",
agent_type: "single_prompt",
})
}
>
{isPending ? "Creating…" : "Create agent"}
</button>
);
}| Parameter | Type | Description |
|---|---|---|
name | string | Display name of the agent. |
agent_type | "single_prompt" | "workflow" | The agent's execution model. Cannot be changed after creation. |
useUpdateAgent
Sends a partial (PATCH) update — only the fields you include are changed. Automatically invalidates both the agent detail and list caches on success.
useUpdateAgent is the multi-purpose mutation for configuration changes. It also handles publishing and deactivation via the same call.
import { useUpdateAgent } from "@scalereal/sr-voice-engine-react-sdk/hooks";
export function UpdateAgentForm({ agentId }: { agentId: string }) {
const { mutate, isPending } = useUpdateAgent();
const handleSave = () => {
mutate({
agentId,
welcome_message: "Thanks for calling. How can I help?",
language: "en",
});
};
return (
<button type="button" onClick={handleSave} disabled={isPending}>
Save changes
</button>
);
}| Parameter | Type | Description |
|---|---|---|
agentId | string | Required. The agent to update. |
...UpdateAgentRequest | Partial<UpdateAgentRequest> | Any subset of the agent's configuration fields. |
status | "draft" | "published" | Set to "published" to publish the agent atomically with other changes. |
is_active | boolean | Set to false to deactivate (soft-delete) the agent. |
Publishing with or without changes. useUpdateAgent with status: "published" saves your changes and publishes in one request. usePublishAgent publishes the last-saved state with no changes. Use useUpdateAgent when you want the user's current edits to go live; use usePublishAgent for a "publish" button that commits what's already saved.
Cloning, archiving, and publishing
useCloneAgent
Duplicates an existing agent with a new name. Returns { agent_id } for the new clone. The cloned agent starts as a draft.
import { useCloneAgent } from "@scalereal/sr-voice-engine-react-sdk/hooks";
export function CloneButton({ agentId }: { agentId: string }) {
const { mutate, isPending } = useCloneAgent();
return (
<button
type="button"
disabled={isPending}
onClick={() => mutate({ agentId, name: "My Agent (copy)" })}
>
Clone
</button>
);
}| Parameter | Type | Description |
|---|---|---|
agentId | string | The agent to clone. |
name | string | Display name for the cloned agent. |
useDeleteAgent
useDeleteAgent is a soft delete. It sets is_active: false on the agent — it does not erase the agent, its configuration, or any call history. You can restore the agent by calling useUpdateAgent with is_active: true.
import { useDeleteAgent } from "@scalereal/sr-voice-engine-react-sdk/hooks";
export function ArchiveButton({ agentId }: { agentId: string }) {
const { mutate, isPending } = useDeleteAgent();
return (
<button type="button" disabled={isPending} onClick={() => mutate({ agentId })}>
Archive
</button>
);
}usePublishAgent
Publishes the agent's last-saved configuration without making any other changes.
import { usePublishAgent } from "@scalereal/sr-voice-engine-react-sdk/hooks";
export function PublishButton({ agentId }: { agentId: string }) {
const { mutate, isPending } = usePublishAgent();
return (
<button type="button" disabled={isPending} onClick={() => mutate({ agentId })}>
{isPending ? "Publishing…" : "Publish"}
</button>
);
}Managing versions
Every time you save an agent, a new version snapshot is created. You can list, inspect, annotate, and restore versions to roll back to a previous configuration.
useAgentVersions
import { useAgentVersions } from "@scalereal/sr-voice-engine-react-sdk/hooks";
export function VersionList({ agentId }: { agentId: string }) {
const { data } = useAgentVersions(agentId, { page: 1, size: 10 });
return (
<ul>
{data?.results.map((v) => (
<li key={v.version}>
v{v.version} — {v.version_title ?? "Untitled"}
</li>
))}
</ul>
);
}useAgentVersion
Fetches a single stored version. Pass enabled: false to defer loading.
const { data } = useAgentVersion(agentId, "42");useUpdateAgentVersionMetadata
Annotates a version with a human-readable title and description without modifying the configuration.
import { useUpdateAgentVersionMetadata } from "@scalereal/sr-voice-engine-react-sdk/hooks";
const { mutate } = useUpdateAgentVersionMetadata();
mutate({
agentId: "agent-id",
version: "42",
version_title: "Stability release",
version_description: "Fixed greeting loop and reduced latency.",
});| Parameter | Type | Description |
|---|---|---|
agentId | string | The agent whose version to annotate. |
version | string | Version identifier. |
version_title | string | Short label for this version. Optional. |
version_description | string | Longer notes about this version. Optional. |
useRestoreAgentVersion
Restoring a version replaces the current draft configuration with the restored snapshot. Any unsaved changes to the current draft are lost. The restore does not auto-publish — the agent remains a draft until you explicitly publish it.
import { useRestoreAgentVersion } from "@scalereal/sr-voice-engine-react-sdk/hooks";
const { mutate } = useRestoreAgentVersion();
mutate({ agentId: "agent-id", version: "42" });AI prompt generation
useGenerateAgentPrompt
Sends a plain-language description to the platform AI and returns an enhanced_prompt — a fully structured system prompt optimized for voice.
useGenerateAgentPrompt does not save the result. It only returns the enhanced text. You must pass the result to useUpdateAgent to apply it to the agent.
import {
useGenerateAgentPrompt,
useUpdateAgent,
} from "@scalereal/sr-voice-engine-react-sdk/hooks";
export function PromptGenerator({ agentId }: { agentId: string }) {
const generate = useGenerateAgentPrompt();
const update = useUpdateAgent();
const handleGenerate = async () => {
const result = await generate.mutateAsync({
agentId,
userPrompt: "A friendly support agent for a SaaS product that helps with billing issues.",
});
// Apply the enhanced prompt to the agent
update.mutate({ agentId, system_prompt: result.enhanced_prompt });
};
return (
<button type="button" onClick={handleGenerate} disabled={generate.isPending || update.isPending}>
{generate.isPending ? "Generating…" : "Generate prompt"}
</button>
);
}| Parameter | Type | Description |
|---|---|---|
agentId | string | The agent context used to seed generation. |
userPrompt | string | Plain-language description of the agent's role, tone, and responsibilities. |
Returns: { enhanced_prompt: string }
Creating from a template
useCreateAgentFromTemplate provisions a fully configured agent from a pre-built template. Returns { agent_id } for the new agent.
import { useCreateAgentFromTemplate } from "@scalereal/sr-voice-engine-react-sdk/hooks";
const { mutate } = useCreateAgentFromTemplate();
mutate({ template_id: "tpl_inbound_support_v1" });Calendar integration
useGetCalendarIntegration(provider, apiKeyId, timezoneSearch?, enabled?) loads scheduling metadata for Calendly or Cal.com integrations attached to an agent. The query stays idle if either provider or apiKeyId is empty.
import { useGetCalendarIntegration } from "@scalereal/sr-voice-engine-react-sdk/hooks";
const calendar = useGetCalendarIntegration("calendly", credentialId, "America/New_York");| Parameter | Type | Description |
|---|---|---|
provider | string | "calendly" or "calcom". |
apiKeyId | string | The integration credential ID. See Integration Credentials. |
timezoneSearch | string | Filter available event types by timezone. Optional. |
enabled | boolean | Explicitly disable the query. Optional. |
Prompt variables
useAgentPromptVariables(agentId, enabled?) loads the prompt variable templates defined for an agent (e.g. {{customer_name}}). Use this to populate a UI that lets callers fill in dynamic values before initiating a call.
const { data } = useAgentPromptVariables(agentId);Cache keys
agentKeys is a factory object that produces stable TanStack Query cache keys for all agent-related queries. Use it to manually invalidate or prefetch from outside a hook.
import { agentKeys } from "@scalereal/sr-voice-engine-react-sdk/hooks";
import { useQueryClient } from "@tanstack/react-query";
const qc = useQueryClient();
qc.invalidateQueries({ queryKey: agentKeys.lists() });
qc.invalidateQueries({ queryKey: agentKeys.detail(agentId) });Related pages
- Calls — Initiate telephony and SIP calls with an agent.
- Function Tools — Configure tools attached to agents.
- Integration Credentials — Manage provider keys used by agent features.
- Knowledge Bases — Manage knowledge sources attached to agents.
- Types — Full type reference for agent request and response models.