Skip to content

Agent

An Agent is a program that receives a question, decides what tools to use, and produces an answer. It runs a ReAct loop (Reason + Act):

User question
-> LLM thinks + picks a tool
-> Tool executes, returns result
-> LLM thinks again (with tool result)
-> Final answer (or pick another tool)

The loop continues until the LLM produces a final answer or hits maxSteps (default: 10).

import { Schift, Agent, RAG } from "@schift-io/sdk";
const schift = new Schift({ apiKey: "sch_..." });
const rag = new RAG({ bucket: "my-docs" }, schift.transport);
const agent = new Agent({
name: "My Agent",
instructions: "You are a helpful assistant. Use the knowledge base.",
rag,
tools: [myCustomTool],
model: "gpt-4o-mini",
transport: schift.transport,
maxSteps: 15,
});
const result = await agent.run("What is Schift?");
console.log(result.output);

Agents support three ways to connect to an LLM:

Routes through Schift’s /v1/chat/completions endpoint. Supports model routing across OpenAI, Google, and Anthropic.

const agent = new Agent({
name: "Cloud Agent",
instructions: "...",
model: "gpt-4o-mini", // or "claude-sonnet-4-6", "gemini-2.5-flash"
transport: schift.transport,
});

Connect directly to OpenAI, Google, or Anthropic endpoints. Bypasses Schift Cloud for LLM calls (RAG still uses Schift Cloud).

const agent = new Agent({
name: "Direct Agent",
instructions: "...",
model: "gpt-4o-mini",
baseUrl: "https://api.openai.com/v1",
apiKey: process.env.OPENAI_API_KEY,
});

Connect to Ollama, vLLM, LiteLLM, or any OpenAI-compatible endpoint.

const agent = new Agent({
name: "Local Agent",
instructions: "...",
model: "llama3",
baseUrl: "http://localhost:11434/v1",
});

See the Self-hosting guide for details.

AgentWorkflowClient
Use whenInteractive Q&A, tool callingFixed data pipelines (ETL, batch)Simple embed/search calls
LoopReAct (dynamic, LLM decides)DAG (fixed steps, deterministic)None
ToolsYesBlock typesN/A
MemoryConversation historyN/AN/A
OptionTypeDefaultDescription
namestringrequiredDisplay name
instructionsstringrequiredSystem prompt for the LLM
modelModelId | string"gpt-4o-mini"LLM model identifier
transportTransportSchift Cloud transport (from schift.transport)
baseUrlstringCustom OpenAI-compatible endpoint
apiKeystringAPI key for direct/self-hosted mode
toolsAgentTool[][]Tools available to the agent
ragRAGRAG instance (auto-registers as tool)
memoryMemoryConfigConversation memory config. Omit for stateless
maxStepsnumber10Max ReAct loop iterations
toolTimeoutMsnumber30000Timeout for each tool execution (ms)
maxToolCallsnumbermaxSteps * 5Maximum total tool calls per run
parallelToolExecutionbooleanfalseExecute multiple tool calls in parallel per turn
skillsSkillsConfigDynamic skill loading. See Skills
extensionsArrayExtension initializers or module paths
mcpMCPServerConfig[]MCP server configs (forward compatibility)

Pass per-run options to agent.run():

const result = await agent.run("question", {
requestId: "req_abc123", // Track this run across logs
signal: AbortSignal.timeout(30000), // Cancel after 30s
});
OptionTypeDescription
requestIdstringCorrelation ID for logging/tracing
signalAbortSignalCancel the run when aborted

Agents emit events during execution. Subscribe with agent.on():

agent.on("tool_call", (event) => {
console.log(`Calling ${event.toolName}...`);
});
agent.on("agent_end", (event) => {
console.log(`Done in ${event.totalDurationMs}ms`);
});
// Wildcard: listen to all events
agent.on("*", (event) => {
console.log(event.type, event);
});
EventFired when
agent_startRun begins
turn_startEach ReAct iteration starts
tool_callLLM decides to call a tool
tool_resultTool execution completes
message_deltaLLM produces final answer text
agent_endRun completes successfully
errorAn error occurs
policy_violationA skill policy blocks a tool call

Unsubscribe with the returned cleanup function:

const unsub = agent.on("tool_call", handler);
unsub(); // stop listening

See Events reference for full event payloads.

agent.run() returns an AgentRunResult:

interface AgentRunResult {
steps: AgentStep[]; // Each step in the ReAct loop
output: string; // Final answer text
totalDurationMs: number; // Total execution time
}

Each step has a type: think, tool_call, tool_result, final_answer, or error.