Platform SDK

@kraken-ai/platform is the authoring and client surface for the Kraken platform. Declare agents, connectors, actions, and skills in a typed project, and invoke deployed agents from your own code with the PlatformClient.

#Installation

The @kraken-ai/platform package ships the authoring helpers, the PlatformClient, and the kraken CLI. It is already a dependency of every scaffolded project. To add it to an existing project:

$ pnpm add @kraken-ai/platform

Installing the package makes the kraken binary available for logging in, generating types, and running locally. See the CLI reference.

ts
import {
  definePlatformAgent,
  defineConnector,
  defineTool,
  defineAction,
  definePackagedSkill,
  PlatformClient,
} from "@kraken-ai/platform";
import { z } from "zod";

#definePlatformAgent

definePlatformAgent(config) declares a platform-managed agent. It validates the scalar fields at definition time and returns a frozen draft. The agent's identity comes from its file path (  src/agents/<name>.ts ), never from a config field — so there is no name. Tools and a custom kernel are not permitted: capabilities come from connectors, teams from team.members, all injected by the platform through the governance gateway.

modelModelStringRequired

Provider-qualified model string, e.g. "google/gemini-3-flash-preview".

instructionsstringRequired

System instructions defining the agent's behavior.

descriptionstringOptional

Capabilities description shown to orchestrator agents during delegation.

displayNamestringOptional

Optional UI label. Does not affect identity.

connectorsConnectorBlueprint[]Optional

Connectors whose tools and resources this agent may use. Pass the objects returned by defineConnector().

actionsPlatformAction[]Optional

The agent's typed terminal outputs. Pass the objects returned by defineAction().

skillsAgentSkillPackage[]Optional

Packaged skills available to the agent, typically imported from ./skills/<name> directories.

outputSchemaz.ZodTypeOptional

Zod schema constraining the agent's structured output. When actions are provided, the platform builds the output schema from them automatically.

team{ members: AgentRef[]; ... }Optional

Delegation team. members are other defined agents or remote agent IDs; optional maxConcurrentWorkers, maxTokenBudgetPerWorker, and maxDurationPerWorker bound worker fan-out.

triggersTriggerInput[]Optional

Registry triggers that fire this agent. Agents without triggers run only ad-hoc. See Triggers.

temperaturenumberOptional

Sampling temperature.

thinkingLevel"low" | "medium" | "high"Optional

Default reasoning depth for all LLM calls.

maxOutputTokensnumberOptional

Maximum number of output tokens per model call.

logLevel"silent" | "debug" | "info" | "warn" | "error"Optional

Log verbosity for this agent.

ts
import { definePlatformAgent } from "@kraken-ai/platform";
import slack from "../connectors/slack";
import linear from "../connectors/linear";

// File path → identity = "market-analyst"
export default definePlatformAgent({
  model: "google/gemini-3-flash-preview",
  instructions: "You are a market research analyst.",
  connectors: [slack, linear],
  displayName: "Market Analyst",
});

#defineConnector & defineTool

defineConnector(definition) declares a connector that exposes tools, resources, and prompts to agents through the governed platform. Connector identity comes from the file path ( src/connectors/<name>.ts ). defineTool({ description, input, handler }) defines a single tool inside a connector, inferring the handler argument types from the Zod input schema.

ts
import { defineConnector, defineTool } from "@kraken-ai/platform";
import { z } from "zod";

export default defineConnector({
  displayName: "Orakle",
  description: "Pricing intelligence for retail SKUs",
  requiredEnvVars: ["ORAKLE_API_KEY"],
  tools: {
    priceCheck: defineTool({
      description: "Look up a fair-market price band",
      input: z.object({ sku: z.string(), geo: z.string() }),
      handler: async ({ sku, geo }) => fetchPrice(sku, geo),
    }),
  },
});

requiredEnvVars declares the environment variables the connector needs at runtime; the platform provisions only the declared keys. For the full connector model, including resources and prompts, see Connectors and the Connector SDK.

#defineAction

defineAction({ schema, handler?, webhook? }) declares a standalone action — one of the agent's typed terminal decisions. The handler's payload type is inferred from the Zod schema. Action identity comes from the file path ( src/actions/<name>.ts ). Listing actions in an agent's actions array constrains its structured output to exactly one action.

ts
import { defineAction } from "@kraken-ai/platform";
import { z } from "zod";

export default defineAction({
  schema: z.object({ reason: z.string(), confidence: z.number() }),
  handler: async (payload) => {
    payload.reason;     // string
    payload.confidence; // number
  },
});

See Actions for delivery, webhooks, and acknowledgement semantics.

#definePackagedSkill

definePackagedSkill(input) is the author-side factory for the directory-based Agent Skills layout. The project loader normally synthesizes packaged skills from a SKILL.md directory; this factory exists for tests and inline synthetic skills, and validates the input so invalid frontmatter cannot slip through. See Skills.

#PlatformClient

new PlatformClient(config?) connects to a deployed Kraken platform. config accepts an optional baseUrl and apiKey. When omitted, each value resolves in priority order: explicit config options first, then the KRAKEN_BASE_URL / KRAKEN_API_KEY environment variables (which override stored credentials), then credentials stored by kraken login. A missing endpoint or key throws at construction time.

agent(id, opts?)(id, opts?) => AgentHandleOptional

Get a handle to a deployed agent by ID. opts.threadId continues an existing conversation thread; opts.mode is reserved ("local" is not yet implemented and raises a PlatformError).

agentsAgentsNamespaceOptional

List agents and create, fetch, or list conversation threads — agents.list(), agents.createThread(agentId), agents.getThread(...), agents.listThreads(...) .

dataDataNamespaceOptional

Discover and run platform data queries — data.list(), data.describe(name), data.query(name, params?) .

pipelinesPipelinesNamespaceOptional

Run a typed pipeline query — pipelines.query(pipeline, queryName, schema, params) validates rows against the provided Zod schema.

runsRunsNamespaceOptional

Start, fetch, cancel, and stream agent runs — runs.start(params), runs.get(runId), runs.cancel(runId), runs.getEvents(...), runs.streamEvents(runId).

ts
import { PlatformClient } from "@kraken-ai/platform";

const client = new PlatformClient({
  baseUrl: "https://your-platform.example.com",
  apiKey: process.env.KRAKEN_API_KEY,
});

const handle = client.agent("market-analyst");
const run = await handle.generate("Summarize this week's pricing moves");

for await (const event of run.stream()) {
  if (event.type === "text") process.stdout.write(event.content);
}

const output = await run.result;

#AgentHandle

client.agent(id) returns an AgentHandle. When types have been generated with kraken generate, the input, output, and action payloads are inferred per agent.

generate(input, opts?)(input, opts?) => Promise<GenerateResult>Optional

Send input to the agent. Resolves to a result with a threadId, a stream() async iterable of events, and a result promise of the agent's final output. opts.signal aborts the request.

onAction(name, handler)(name, handler) => voidOptional

Register a handler invoked when the agent emits the named action during a run. The payload type is inferred from generated types.

stream()() => AsyncIterable<AgentEvent>Optional

On a GenerateResult: iterate the live event stream.

Stream events are a discriminated union on type:

text{ content: string }Optional

Incremental assistant output.

thinking{ content: string }Optional

Incremental model reasoning.

tool_call{ name; args }Optional

The agent invoked a connector tool.

tool_result{ name; result }Optional

A tool returned a result.

action{ name; payload; actionExecutionId }Optional

The agent emitted a terminal action. Registered onAction handlers run and the SDK acknowledges delivery.

done{ output; usage? }Optional

The run completed. Resolves the result promise.

error{ message; code }Optional

The run failed. Rejects the result promise with a PlatformError.

ts
const handle = client.agent("market-analyst");

handle.onAction("approve", async (payload) => {
  await recordApproval(payload);
});

const run = await handle.generate("Review the Q3 pricing proposal");
const output = await run.result;

#Errors

Authoring and client failures surface as typed errors:

PlatformErrorerror.code: PlatformErrorCodeOptional

Raised for API and runtime failures. Narrow on error.code (for example "unauthorized", "not_found", "rate_limited", "timeout" ); unrecognized codes surface as "unknown" so switches stay exhaustive.

SecurityErrorauthoring guardOptional

Thrown by definePlatformAgent when a forbidden field is supplied — tools or kernel, or a non-config team shape.

DiscoveryErrorproject discoveryOptional

Thrown when the CLI cannot discover or validate the project (for example a malformed manifest).

Note

The platform runs your agents inside governed, sandboxed runtimes. Every tool call and action passes through the governance gateway and is written to an immutable audit trail — see Governance and Audit & Compliance.

#Next steps

  • Connector SDK — The full connector authoring surface: tools, resources, prompts, and the local connector server.
  • Pipelines (Python) — Define typed data pipelines and expose their queries to agents and the PlatformClient.
  • Platform API — The HTTP API the PlatformClient wraps: agents, threads, runs, data, and pipelines.