Skip to main content

@agentskit/core

The shared contract layer for AgentsKit: TypeScript types, the headless chat controller, stream helpers, and building blocks used by @agentskit/react, @agentskit/ink, @agentskit/runtime, and adapters. No third-party runtime dependencies — keep this package small and stable.

When to use

  • You implement a custom adapter, tool, memory, or UI on top of official types.
  • You need createChatController without React (advanced integrations).
  • You want to understand messages, tool calls, and stream chunks across the ecosystem.

You usually do not import core directly in a typical React app except for types — prefer useChat and @agentskit/react.

Install

npm install @agentskit/core

Most feature packages already depend on core; you add it explicitly when authoring libraries or sharing types.

Public exports (overview)

Chat controller and config

ExportRole
createChatControllerHeadless state machine: send, stream, tools, memory, skills, retriever
Types: ChatConfig, ChatController, ChatState, ChatReturnConfiguration and controller shape

The controller merges system prompts, runs retrieval, dispatches tool calls, persists via ChatMemory, and exposes subscribe/update patterns consumed by UI packages.

Primitives and streams

ExportRole
buildMessageConstruct a typed Message
consumeStreamDrive StreamSource → chunks + completion
createEventEmitterInternal event bus for observers
executeToolCallRun a tool from a ToolCall payload
safeParseArgsParse JSON tool arguments safely
createToolLifecycleinit / dispose for tools
generateIdStable IDs for messages and calls

Agent loop helpers

ExportRole
buildToolMapName → ToolDefinition map
activateSkillsMerge skill system prompts and skill-provided tools
executeSafeToolGuarded execution (confirmation hooks, errors)

Memory and RAG (lightweight)

ExportRole
createInMemoryMemory, createLocalStorageMemory, createFileMemorySimple bundled memories for tests or demos
serializeMessages / deserializeMessagesPersistence helpers
createStaticRetriever, formatRetrievedDocumentsRetriever helpers for static context

Heavy backends live in @agentskit/memory; vector stores and chunking in @agentskit/rag.

Configuration file

ExportRole
loadConfigLoad AgentsKitConfig from project (CLI / tooling)

Types (high level)

AdapterFactory, StreamSource, StreamChunk, Message, ToolDefinition, ToolCall, SkillDefinition, ChatMemory, Retriever, VectorMemory, Observer, AgentEvent, and related types — full signatures in TypeDoc (below).

Example: inspect types in a custom tool

import type { ToolDefinition, ToolExecutionContext } from '@agentskit/core'

export const myTool: ToolDefinition = {
name: 'greet',
description: 'Greets a user by name.',
schema: {
type: 'object',
properties: { name: { type: 'string' } },
required: ['name'],
},
async execute(args: Record<string, unknown>, _ctx: ToolExecutionContext) {
const name = String(args.name ?? 'world')
return `Hello, ${name}!`
},
}

Example: headless controller (advanced)

import { createChatController } from '@agentskit/core'
import { anthropic } from '@agentskit/adapters'

const chat = createChatController({
adapter: anthropic({ apiKey: process.env.ANTHROPIC_API_KEY!, model: 'claude-sonnet-4-6' }),
})

chat.subscribe(() => {
console.log(chat.getState().status, chat.getState().messages.length)
})

await chat.send('Hello')

Prefer useChat in React apps — it wraps this pattern with hooks.

Troubleshooting

IssueMitigation
Type errors after upgradePin all @agentskit/* to the same semver; core types move with the ecosystem.
createChatController vs useChatController is framework-agnostic; React hook adds state binding and Strict Mode safety.
Bundle size concernsTree-shake unused exports; avoid importing server-only utilities in client bundles.

See also

Start here · Packages · TypeDoc (@agentskit/core) · React · Ink · Adapters · Runtime · Tools · Skills · useChat · useStream · useReactive