The Kastrax Class ✅
The Kastrax class is the core entry point for your application. It manages agents, workflows, and server endpoints.
Constructor Options ✅
agents?:
Agent[]
= []
Array of Agent instances to register
tools?:
Record<string, ToolApi>
= {}
Custom tools to register. Structured as a key-value pair, with keys being the tool name and values being the tool function.
storage?:
KastraxStorage
Storage engine instance for persisting data
vectors?:
Record<string, KastraxVector>
Vector store instance, used for semantic search and vector-based tools (eg Pinecone, PgVector or Qdrant)
logger?:
Logger
= Console logger with INFO level
Logger instance created with createLogger()
workflows?:
Record<string, Workflow>
= {}
Workflows to register. Structured as a key-value pair, with keys being the workflow name and values being the workflow instance.
server?:
ServerConfig
= { port: 4111, host: localhost, cors: { origin: '*', allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], allowHeaders: ['Content-Type', 'Authorization', 'x-kastrax-client-type'], exposeHeaders: ['Content-Length', 'X-Requested-With'], credentials: false } }
Server configuration including port, host, timeout, API routes, middleware, CORS settings, and build options for Swagger UI, API request logging, and OpenAPI docs.
Initialization ✅
The Kastrax class is typically initialized in your src/kastrax/index.ts
file:
import { Kastrax } from "@kastrax/core";
import { createLogger } from "@kastrax/core/logger";
// Basic initialization
export const kastrax = new Kastrax({});
// Full initialization with all options
export const kastrax = new Kastrax({
agents: {},
workflows: [],
integrations: [],
logger: createLogger({
name: "My Project",
level: "info",
}),
storage: {},
tools: {},
vectors: {},
});
You can think of the Kastrax
class as a top-level registry. When you register tools with Kastrax, your registered agents and workflows can use them. When you register integrations with Kastrax, agents, workflows, and tools can use them.
Methods ✅
getAgent(name):
Agent
Returns an agent instance by id. Throws if agent not found.
getAgents():
Record<string, Agent>
Returns all registered agents as a key-value object.
getWorkflow(id, { serialized }):
Workflow
Returns a workflow instance by id. The serialized option (default: false) returns a simplified representation with just the name.
getWorkflows({ serialized }):
Record<string, Workflow>
Returns all registered workflows. The serialized option (default: false) returns simplified representations.
getVector(name):
KastraxVector
Returns a vector store instance by name. Throws if not found.
getVectors():
Record<string, KastraxVector>
Returns all registered vector stores as a key-value object.
getDeployer():
KastraxDeployer | undefined
Returns the configured deployer instance, if any.
getStorage():
KastraxStorage | undefined
Returns the configured storage instance.
getMemory():
KastraxMemory | undefined
Returns the configured memory instance. Note: This is deprecated, memory should be added to agents directly.
getServer():
ServerConfig | undefined
Returns the server configuration including port, timeout, API routes, middleware, CORS settings, and build options.
setStorage(storage):
void
Sets the storage instance for the Kastrax instance.
setLogger({ logger }):
void
Sets the logger for all components (agents, workflows, etc.).
setTelemetry(telemetry):
void
Sets the telemetry configuration for all components.
getLogger():
Logger
Gets the configured logger instance.
getTelemetry():
Telemetry | undefined
Gets the configured telemetry instance.
getLogsByRunId({ runId, transportId }):
Promise<any>
Retrieves logs for a specific run ID and transport ID.
getLogs(transportId):
Promise<any>
Retrieves all logs for a specific transport ID.
Error Handling ✅
The Kastrax class methods throw typed errors that can be caught:
try {
const tool = kastrax.getTool("nonexistentTool");
} catch (error) {
if (error instanceof Error) {
console.log(error.message); // "Tool with name nonexistentTool not found"
}
}
Last updated on