API Reference
import { Agent } from "@schift-io/sdk";Constructor
Section titled “Constructor”new Agent(options: AgentOptions)| Option | Type | Default | Required |
|---|---|---|---|
name | string | — | Yes |
instructions | string | — | Yes |
model | ModelId | string | "gpt-4o-mini" | No |
transport | Transport | — | One of transport or baseUrl |
baseUrl | string | — | One of transport or baseUrl |
apiKey | string | — | No |
tools | AgentTool[] | [] | No |
rag | RAG | — | No |
memory | MemoryConfig | — | No |
maxSteps | number | 10 | No |
toolTimeoutMs | number | 30000 | No |
maxToolCalls | number | maxSteps * 5 | No |
parallelToolExecution | boolean | false | No |
skills | SkillsConfig | — | No |
extensions | Array<ExtensionInitFn | string> | — | No |
mcp | MCPServerConfig[] | — | No |
Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
run(input, options?) | Promise<AgentRunResult> | Run the agent with a user message |
on(type, handler) | () => void | Subscribe to events. Returns unsubscribe fn |
off(type, handler) | void | Unsubscribe from events |
toolCount | number | Number of registered tools (getter) |
import { RAG } from "@schift-io/sdk";Constructor
Section titled “Constructor”new RAG(config: RAGConfig, transport: Transport)| Option | Type | Default |
|---|---|---|
bucket | string | required |
topK | number | 7 |
Static Properties
Section titled “Static Properties”| Property | Type | Value |
|---|---|---|
MAX_QUERY_LENGTH | number | 8000 |
Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
search(query: string) | Promise<SearchResultItem[]> | Semantic search over bucket |
chat(query: string) | Promise<ChatResult> | Search + LLM answer |
asTool(name?: string) | AgentTool | Convert to agent tool |
WebSearch
Section titled “WebSearch”import { WebSearch } from "@schift-io/sdk";Constructor
Section titled “Constructor”new WebSearch(config?: WebSearchConfig, transport?: Transport)| Option | Type | Default |
|---|---|---|
maxResults | number | 5 |
provider | WebSearchProvider | "schift" |
providerApiKey | string | — |
Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
search(query: string) | Promise<WebSearchResultItem[]> | Search the web |
asTool(name?: string) | AgentTool | Convert to agent tool |
DeepResearch
Section titled “DeepResearch”import { DeepResearch } from "@schift-io/sdk";Constructor
Section titled “Constructor”new DeepResearch(config?: DeepResearchConfig, llm: LLMFn, transport?: Transport)| Option | Type | Default |
|---|---|---|
maxIterations | number | 3 |
resultsPerSearch | number | 5 |
queriesPerIteration | number | 2 |
queryModel | ModelId | string | "gpt-4o-mini" |
synthesisModel | ModelId | string | "gpt-4o-mini" |
webSearch | WebSearchConfig | — |
Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
run(question: string) | Promise<ResearchReport> | Run deep research |
asTool(name?: string) | AgentTool | Convert to agent tool |
ConversationMemory
Section titled “ConversationMemory”import { ConversationMemory } from "@schift-io/sdk";Constructor
Section titled “Constructor”new ConversationMemory(config?: MemoryConfig)| Option | Type | Default |
|---|---|---|
maxMessages | number | 50 |
transformContext | (messages: ChatMessage[]) => ChatMessage[] | — |
Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
add(message: ChatMessage) | void | Add message to history |
getMessages() | ChatMessage[] | Get all messages |
clear() | void | Clear non-system messages |
length | number | Message count (getter) |
ToolRegistry
Section titled “ToolRegistry”import { ToolRegistry } from "@schift-io/sdk";Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
register(tool: AgentTool) | void | Register a tool |
get(name: string) | AgentTool | undefined | Get tool by name |
has(name: string) | boolean | Check if tool exists |
list() | AgentTool[] | List all tools |
execute(name, args) | Promise<ToolResult> | Execute a tool by name |
filtered(allowedNames: Set<string>) | ToolRegistry | New registry with only allowed tools |
without(blockedNames: Set<string>) | ToolRegistry | New registry excluding blocked tools |
toOpenAI() | Array | Generate OpenAI-compatible tool definitions |
toAnthropic() | Array | Generate Anthropic-compatible tool definitions |
AgentEventEmitter
Section titled “AgentEventEmitter”import { AgentEventEmitter } from "@schift-io/sdk";Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
on(type, handler) | () => void | Subscribe to event. Returns unsubscribe fn |
on("*", handler) | () => void | Subscribe to all events |
off(type, handler) | void | Unsubscribe from event |
emit(event) | void | Emit an event |
removeAll() | void | Remove all handlers |
SkillLoader
Section titled “SkillLoader”import { SkillLoader, loadSkills } from "@schift-io/sdk";Constructor
Section titled “Constructor”new SkillLoader(skillsDir: string)Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
loadAll(options?) | Promise<SkillSummary[]> | Load all skill files |
get(name: string) | Promise<Skill | undefined> | Get a skill by name |
getAll() | Promise<Skill[]> | Get all loaded skills |
reload(name: string) | Promise<Skill | undefined> | Reload a specific skill |
Convenience
Section titled “Convenience”const loader = await loadSkills("./skills");// Equivalent to: new SkillLoader("./skills") + loadAll()SkillResolver
Section titled “SkillResolver”import { SkillResolver } from "@schift-io/sdk";Constructor
Section titled “Constructor”new SkillResolver(loader: SkillLoader)Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
resolve(query) | Promise<Skill[]> | Get all skills |
resolvePrimary(query) | Promise<ResolvedSkill | undefined> | Best-matching skill for query |
buildPromptSection(skills) | { promptText, allowedTools } | Build prompt injection section |
PolicyEngine
Section titled “PolicyEngine”import { PolicyEngine, policyViolation } from "@schift-io/sdk";Constructor
Section titled “Constructor”new PolicyEngine(contract: SkillContract)Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
beforeTool(input) | PolicyDecision | Check if tool call is allowed |
afterTool(input) | PolicyDecision | Validate tool result |
Helper
Section titled “Helper”policyViolation(reason: string): ToolResult// Returns { success: false, data: null, error: "POLICY_VIOLATION:reason" }ExtensionHost
Section titled “ExtensionHost”import { ExtensionHost } from "@schift-io/sdk";Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
load(extension) | Promise<void> | Load an extension (function or module path) |
Managed Agents
Section titled “Managed Agents”Server-side managed agents — create, configure, and run agents via the Schift Cloud API.
AgentsClient
Section titled “AgentsClient”const client = schift.agents;| Method | Returns | Description |
|---|---|---|
create(req: CreateAgentRequest) | Promise<AgentResponse> | Create a managed agent |
list() | Promise<AgentResponse[]> | List all agents |
get(id: string) | Promise<AgentResponse> | Get agent by ID |
update(id, req) | Promise<AgentResponse> | Update an agent |
delete(id: string) | Promise<void> | Delete an agent |
runs(agentId: string) | RunsClient | Get runs client for an agent |
RunsClient
Section titled “RunsClient”const runs = schift.agents.runs("agt_abc123");| Method | Returns | Description |
|---|---|---|
create(req: CreateRunRequest) | Promise<RunResponse> | Start a run |
list() | Promise<RunResponse[]> | List all runs |
get(runId: string) | Promise<RunResponse> | Get run by ID |
streamEvents(runId, afterSeq?) | AsyncGenerator<RunEvent> | Stream run events |
Schift (Client)
Section titled “Schift (Client)”import { Schift } from "@schift-io/sdk";Constructor
Section titled “Constructor”new Schift(config: SchiftConfig)| Option | Type | Default |
|---|---|---|
apiKey | string | required (must start with sch_) |
baseUrl | string | "https://api.schift.io" |
timeout | number | 60000 |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
transport | HttpTransport | HTTP transport for Agent/RAG |
workflows | WorkflowClient | Workflow sub-client |
agents | AgentsClient | Managed Agents sub-client |
models | ModelsClient | Model catalog |
db | DBClient | Bucket/document management |
tools | SchiftTools | Tool definition helpers |
Core Methods
Section titled “Core Methods”| Method | Returns | Description |
|---|---|---|
embed(request) | Promise<EmbedResponse> | Generate embeddings |
embedBatch(request) | Promise<EmbedBatchResponse> | Batch embeddings |
search(request) | Promise<SearchResult[]> | Vector search |
chat(request) | Promise<ChatResponse> | RAG chat |
chatStream(request) | AsyncGenerator<ChatStreamEvent> | RAG chat with SSE streaming |
webSearch(query, maxResults?) | Promise<WebSearchResultItem[]> | Web search |
aggregate(request) | Promise<AggregateResponse> | Metadata aggregation |
rerank(request) | Promise<RerankResult> | Rerank documents |
similarity(request) | Promise<{ score: number }> | Text similarity score |
cluster(request) | Promise<ClusterResult> | Text clustering |
classify(request) | Promise<ClassifyResult> | Zero-shot classification |
Bucket Methods
Section titled “Bucket Methods”| Method | Returns | Description |
|---|---|---|
listBuckets() | Promise<Bucket[]> | List all buckets |
createBucket(request) | Promise<Bucket> | Create a bucket |
deleteBucket(nameOrId) | Promise<void> | Delete a bucket |
bucketSearch(nameOrId, request) | Promise<SearchResult> | Search a bucket |
bucketGraph(nameOrId, query?, topK?) | Promise<GraphResult> | Graph query on a bucket |
db.upload(bucket, options) | Promise<BucketUploadResult> | Upload files to a bucket |
Edge Methods
Section titled “Edge Methods”| Method | Returns | Description |
|---|---|---|
addEdges(nameOrId, edges) | Promise<{ count: number }> | Add graph edges |
listEdges(nameOrId, nodeId, options?) | Promise<EdgeListResult> | List edges for a node |
deleteEdge(nameOrId, source, target, relation?) | Promise<void> | Delete an edge |
Collection Methods
Section titled “Collection Methods”| Method | Returns | Description |
|---|---|---|
listCollections() | Promise<Collection[]> | List collections |
getCollection(id) | Promise<Collection> | Get collection by ID |
createCollection(request) | Promise<Collection> | Create a collection |
deleteCollection(id) | Promise<void> | Delete a collection |
collectionStats(id) | Promise<Stats> | Get collection statistics |
collectionAdd(collection, request) | Promise<Result> | Add documents to collection |
collectionSearch(collection, request) | Promise<SearchResult> | Search a collection |
upsertVectors(collection, vectors) | Promise<Result> | Upsert raw vectors |
deleteVectors(collection, ids) | Promise<Result> | Delete vectors by ID |
upsertDocuments(collection, documents, model) | Promise<Result> | Upsert documents with embedding |
LLM Routing
Section titled “LLM Routing”| Method | Returns | Description |
|---|---|---|
chatCompletion(request) | Promise<ChatCompletionResult> | OpenAI-compatible chat completions |
listModels() | Promise<Model[]> | List available LLM models |
getRouting() | Promise<RoutingConfig> | Get current routing config |
setRouting(request) | Promise<RoutingConfig> | Set routing config |
Usage & Jobs
Section titled “Usage & Jobs”| Method | Returns | Description |
|---|---|---|
usage() | Promise<Usage> | Get current usage |
usageSummary() | Promise<UsageSummary> | Get usage summary |
getJob(jobId) | Promise<Job> | Get job status |
listJobs(options?) | Promise<Job[]> | List jobs |
cancelJob(jobId) | Promise<Job> | Cancel a job |
reprocessJob(jobId) | Promise<Job> | Reprocess a failed job |
SchiftTools
Section titled “SchiftTools”Tool calling helpers that generate provider-specific tool definitions. Automatically created on schift.tools.
// OpenAI formatconst tools = schift.tools.openai();// Anthropic formatconst tools = schift.tools.anthropic();// Vercel AI SDK formatconst tools = schift.tools.vercelAI();// Handle any tool call (auto-detects format)const result = await schift.tools.handle(toolCall);| Method | Returns | Description |
|---|---|---|
openai() | object[] | OpenAI-compatible tool definitions |
anthropic() | object[] | Anthropic-compatible tool definitions |
vercelAI() | Record<string, object> | Vercel AI SDK tool definitions |
handle(toolCall) | Promise<string> | Execute a tool call from any provider |
AgentTool
Section titled “AgentTool”interface AgentTool { name: string; // Must match /^[a-zA-Z_][a-zA-Z0-9_]*$/ description: string; parameters?: JSONSchema; handler: (args: Record<string, unknown>) => Promise<ToolResult>; maxCallsPerRun?: number; // Per-run call limit}ToolResult
Section titled “ToolResult”interface ToolResult { success: boolean; data: unknown; error?: string;}AgentRunResult
Section titled “AgentRunResult”interface AgentRunResult { steps: AgentStep[]; output: string; totalDurationMs: number;}AgentStep
Section titled “AgentStep”interface AgentStep { id: string; type: "think" | "tool_call" | "tool_result" | "final_answer" | "error"; content?: string; toolName?: string; toolArgs?: Record<string, unknown>; toolResult?: ToolResult; durationMs: number;}RunOptions
Section titled “RunOptions”interface RunOptions { requestId?: string; signal?: AbortSignal;}ChatMessage
Section titled “ChatMessage”interface ChatMessage { role: "system" | "user" | "assistant" | "tool"; content: string; toolCallId?: string; toolName?: string;}SkillsConfig
Section titled “SkillsConfig”interface SkillsConfig { loader: SkillLoader; autoResolve?: boolean; // Default: true}SkillContract
Section titled “SkillContract”interface SkillContract { skillName: string; model?: string; allowedTools?: string[]; blockedTools?: string[]; procedures?: string[]; constraints?: string[];}SkillFrontmatter
Section titled “SkillFrontmatter”interface SkillFrontmatter { name: string; description: string; model?: string; "allowed-tools"?: string[]; "blocked-tools"?: string[]; procedures?: string[]; constraints?: string[]; rag?: string;}PolicyDecision
Section titled “PolicyDecision”interface PolicyDecision { allowed: boolean; stage: "before_tool" | "after_tool" | "procedure" | "constraint"; reason?: string;}ExtensionAPI
Section titled “ExtensionAPI”interface ExtensionAPI { registerTool(tool: AgentTool): void; on<K extends AgentEventType>(type: K, handler: (event: AgentEventMap[K]) => void): () => void; off<K extends AgentEventType>(type: K, handler: (event: AgentEventMap[K]) => void): void; readonly agentName: string;}MCPServerConfig
Section titled “MCPServerConfig”interface MCPServerConfig { transport: "stdio" | "sse"; command?: string; args?: string[]; url?: string; toolPrefix?: string;}Managed Agent Types
Section titled “Managed Agent Types”interface CreateAgentRequest { name: string; model?: string; instructions?: string; tools?: AgentToolDef[]; ragConfig?: RagConfig; metadata?: Record<string, unknown>;}
interface AgentResponse { id: string; orgId: string; name: string; model: string; instructions: string; tools: AgentToolDef[]; ragConfig: RagConfig; metadata: Record<string, unknown>; createdAt: string; updatedAt: string;}
interface RunResponse { id: string; agentId: string; orgId: string; status: "pending" | "running" | "success" | "error" | "timeout"; inputText: string; outputText?: string; error?: string; tokensUsed: number; durationMs?: number; createdAt: string; finishedAt?: string;}
interface RunEvent { seq: number; eventType: string; [key: string]: unknown;}Event Types
Section titled “Event Types”type AgentEventType = | "agent_start" | "turn_start" | "tool_call" | "tool_result" | "message_delta" | "agent_end" | "error" | "policy_violation";Each event includes type, runId, and timestamp. Additional fields vary by event type:
| Event | Additional Fields |
|---|---|
agent_start | input |
turn_start | turnIndex |
tool_call | toolName, toolArgs, callId |
tool_result | toolName, callId, result, durationMs |
message_delta | content |
agent_end | output, totalDurationMs |
error | error |
policy_violation | skillName, stage, reason, toolName? |
WebSearchProvider
Section titled “WebSearchProvider”const WebSearchProvider = { SCHIFT: "schift", TAVILY: "tavily", SERPER: "serper", BRAVE: "brave",} as const;Model Catalogs
Section titled “Model Catalogs”import { OpenAIModel, GeminiModel, ClaudeModel } from "@schift-io/sdk";
// OpenAIOpenAIModel.GPT_5_4 // "gpt-5.4"OpenAIModel.GPT_5_4_MINI // "gpt-5.4-mini"OpenAIModel.GPT_5_4_NANO // "gpt-5.4-nano"OpenAIModel.GPT_4_1 // "gpt-4.1"OpenAIModel.GPT_4_1_MINI // "gpt-4.1-mini"OpenAIModel.GPT_4_1_NANO // "gpt-4.1-nano"OpenAIModel.GPT_4O // "gpt-4o"OpenAIModel.GPT_4O_MINI // "gpt-4o-mini"OpenAIModel.O3 // "o3"OpenAIModel.O3_MINI // "o3-mini"OpenAIModel.O3_PRO // "o3-pro"OpenAIModel.O4_MINI // "o4-mini"
// GoogleGeminiModel.GEMINI_3_1_PRO // "gemini-3.1-pro"GeminiModel.GEMINI_3_1_FLASH // "gemini-3.1-flash"GeminiModel.GEMINI_3_1_FLASH_LITE // "gemini-3.1-flash-lite"GeminiModel.GEMINI_2_5_PRO // "gemini-2.5-pro"GeminiModel.GEMINI_2_5_FLASH // "gemini-2.5-flash"GeminiModel.GEMINI_2_5_FLASH_LITE // "gemini-2.5-flash-lite"
// AnthropicClaudeModel.OPUS_4_6 // "claude-opus-4-6"ClaudeModel.SONNET_4_6 // "claude-sonnet-4-6"ClaudeModel.HAIKU_4_5 // "claude-haiku-4-5-20251001"Error Classes
Section titled “Error Classes”import { SchiftError, // Base error (status, code) AuthError, // 401 - Invalid API key QuotaError, // 402 - Quota exceeded EntitlementError, // 403 - Upgrade required AgentError, // Agent failure (stepId) ToolError, // Tool execution failure (toolName) MaxStepsError, // Max ReAct iterations reached} from "@schift-io/sdk";