Skip to content
AgentsKit

@agentskit/core — Functions

API functions for @agentskit/core.

#Function: activateSkills()

activateSkills(skills, prompt?): Promise<ActivateSkillsResult>

Defined in: packages/core/src/agent-loop.ts:35

#Parameters

#skills

SkillDefinition[]

#prompt?

string

#Returns

Promise<ActivateSkillsResult>


#Function: audioPart()

audioPart(source, opts?): AudioPart

Defined in: packages/core/src/types/content.ts:60

#Parameters

#source

string

#opts?

Omit<AudioPart, "type" | "source"> = \{\}

#Returns

AudioPart


#Function: buildMessage()

buildMessage(params): Message

Defined in: packages/core/src/primitives.ts:44

#Parameters

#params

#content

string

#metadata?

Record<string, unknown>

#role

MessageRole

#status?

MessageStatus

#toolCallId?

string

#Returns

Message


#Function: buildToolMap()

buildToolMap(...sources): Map<string, ToolDefinition<Record<string, unknown>>>

Defined in: packages/core/src/agent-loop.ts:17

#Parameters

#sources

...(ToolDefinition<Record<string, unknown>>[] | undefined)[]

#Returns

Map<string, ToolDefinition<Record<string, unknown>>>


#Function: compileBudget()

compileBudget(input): Promise<CompileBudgetResult>

Defined in: packages/core/src/budget.ts:82

Take a declared budget and a set of messages/system/tools, then return a trimmed request guaranteed to fit under budget. Three strategies:

  • 'drop-oldest': remove oldest messages until it fits
  • 'sliding-window': backwards-compatible alias of 'drop-oldest'
  • 'summarize': fold dropped messages into a single summary message

#Parameters

#input

CompileBudgetInput

#Returns

Promise<CompileBudgetResult>


#Function: consumeStream()

consumeStream(source, handlers): Promise<void>

Defined in: packages/core/src/primitives.ts:265

#Parameters

#source

StreamSource

#handlers

ConsumeStreamHandlers

#Returns

Promise<void>


#Function: createChatController()

createChatController(initial): ChatController

Defined in: packages/core/src/controller.ts:26

#Parameters

#initial

ChatConfig

#Returns

ChatController


#Function: createEventEmitter()

createEventEmitter(): object

Defined in: packages/core/src/primitives.ts:21

#Returns

object

#addObserver()

addObserver(observer): () => void

#Parameters

observer

Observer

#Returns

() => void

#emit()

emit(event): void

#Parameters

event

AgentEvent

#Returns

void


#Function: createInMemoryMemory()

createInMemoryMemory(initialMessages?): ChatMemory

Defined in: packages/core/src/memory.ts:20

#Parameters

#initialMessages?

Message[] = []

#Returns

ChatMemory


#Function: createLocalStorageMemory()

createLocalStorageMemory(key): ChatMemory

Defined in: packages/core/src/memory.ts:36

#Parameters

#key

string

#Returns

ChatMemory


#Function: createProgressiveArgParser()

createProgressiveArgParser(): ProgressiveArgParser

Defined in: packages/core/src/progressive.ts:40

Stream-parse a JSON object where top-level field values arrive incrementally. Fires an event as soon as each top-level field has a syntactically complete value, enabling "progressive" tool execution — the tool can begin work on the first field before the LLM has finished emitting the rest.

Only works at the top level of a JSON object — nested structures are parsed atomically when their enclosing top-level field closes. That matches the common tool-args shape: a flat \{ query, limit, ...\} object where the expensive operation depends on one key.

#Returns

ProgressiveArgParser


#Function: createStaticRetriever()

createStaticRetriever(config): Retriever

Defined in: packages/core/src/rag.ts:18

#Parameters

#config

StaticRetrieverConfig

#Returns

Retriever


#Function: createToolLifecycle()

createToolLifecycle(tools): object

Defined in: packages/core/src/primitives.ts:188

#Parameters

#tools

Map<string, ToolDefinition<Record<string, unknown>>>

#Returns

object

#disposeAll()

disposeAll(): Promise<void>

#Returns

Promise<void>

#init()

init(tool): Promise<void>

#Parameters

tool

ToolDefinition

#Returns

Promise<void>


#Function: createVirtualizedMemory()

createVirtualizedMemory(backing, options?): ChatMemory & object

Defined in: packages/core/src/virtualized-memory.ts:33

Wrap any ChatMemory implementation with a fixed active window. Older messages (cold) are preserved on disk / in the backing store but omitted from load() unless a retriever surfaces them.

Key guarantees:

  • Backing store always holds the full conversation. No data loss.
  • load() returns at most maxActive + maxRetrieved messages.
  • save() merges the caller's messages with any cold tail the caller did not see, so callers that load -> mutate -> save do not accidentally truncate history.

#Parameters

#backing

ChatMemory

#options?

VirtualizedMemoryOptions = \{\}

#Returns


#Function: defineTool()

defineTool<TSchema>(config): ToolDefinition<InferSchemaType<TSchema>>

Defined in: packages/core/src/types/tool.ts:139

Create a ToolDefinition with automatic type inference from the JSON schema.

#Type Parameters

#TSchema

TSchema extends JSONSchema7

#Parameters

#config

DefineToolConfig<TSchema>

#Returns

ToolDefinition<InferSchemaType<TSchema>>


#Function: deserializeMessages()

deserializeMessages(record): Message[]

Defined in: packages/core/src/memory.ts:12

#Parameters

#record

MemoryRecord | null | undefined

#Returns

Message[]


#Function: executeSafeTool()

executeSafeTool(options): Promise<ToolExecResult>

Defined in: packages/core/src/agent-loop.ts:87

#Parameters

#options

ExecuteSafeToolOptions

#Returns

Promise<ToolExecResult>


#Function: executeToolCall()

executeToolCall(tool, args, context, onPartialResult?): Promise<string>

Defined in: packages/core/src/primitives.ts:77

#Parameters

#tool

ToolDefinition

#args

Record<string, unknown>

#context

ToolExecutionContext

#onPartialResult?

(accumulated) => void

#Returns

Promise<string>


#Function: executeToolProgressively()

executeToolProgressively<TArgs>(tool, chunks, context, options?): ProgressiveExecResult

Defined in: packages/core/src/progressive.ts:228

Run a tool "progressively": feed argument-text chunks as they stream, and kick off tool.execute as soon as the trigger fields have arrived. Additional field events keep landing in the same onField callback so the tool can adapt.

The tool's args parameter reflects whichever fields had arrived by the trigger point — callers that need the complete object should wait for finalArgs.

#Type Parameters

#TArgs

TArgs extends Record<string, unknown>

#Parameters

#tool

ToolDefinition<TArgs>

#chunks

AsyncIterable<string>

#context

Omit<ToolExecutionContext, "call"> & object

#options?

ProgressiveExecOptions = \{\}

#Returns

ProgressiveExecResult


#Function: filePart()

filePart(source, opts?): FilePart

Defined in: packages/core/src/types/content.ts:68

#Parameters

#source

string

#opts?

Omit<FilePart, "type" | "source"> = \{\}

#Returns

FilePart


#Function: filterParts()

filterParts<T>(parts, kind): (Extract<TextPart, { type: T; }> | Extract<ImagePart, { type: T; }> | Extract<AudioPart, { type: T; }> | Extract<VideoPart, { type: T; }> | Extract<FilePart, { type: T; }>)[]

Defined in: packages/core/src/types/content.ts:118

Filter parts by kind.

#Type Parameters

#T

T extends "text" | "image" | "audio" | "video" | "file"

#Parameters

#parts

ContentPart[]

#kind

T

#Returns

(Extract<TextPart, { type: T; }> | Extract<ImagePart, { type: T; }> | Extract<AudioPart, { type: T; }> | Extract<VideoPart, { type: T; }> | Extract<FilePart, { type: T; }>)[]


#Function: formatRetrievedDocuments()

formatRetrievedDocuments(documents): string

Defined in: packages/core/src/rag.ts:35

#Parameters

#documents

RetrievedDocument[]

#Returns

string


#Function: generateId()

generateId(prefix): string

Defined in: packages/core/src/primitives.ts:17

#Parameters

#prefix

string

#Returns

string


#Function: imagePart()

imagePart(source, opts?): ImagePart

Defined in: packages/core/src/types/content.ts:56

Build an image part from a URL / data URI / hosted id.

#Parameters

#source

string

#opts?

Omit<ImagePart, "type" | "source"> = \{\}

#Returns

ImagePart


#Function: normalizeContent()

normalizeContent(content, parts): object

Defined in: packages/core/src/types/content.ts:106

Normalize any of (string | ContentPart[] | undefined) into \{ text, parts \}. Callers that have both the legacy content string and the new parts array use this to pick the right one.

#Parameters

#content

string | undefined

#parts

ContentPart[] | undefined

#Returns

object

#parts

parts: ContentPart[]

#text

text: string


#Function: parseToolArgs()

parseToolArgs(args): ParsedToolArgs

Defined in: packages/core/src/primitives.ts:122

#Parameters

#args

string

#Returns

ParsedToolArgs


#Function: partsToText()

partsToText(parts): string

Defined in: packages/core/src/types/content.ts:77

Collapse a parts array into a text-only projection. Non-text parts are rendered as [image: url] / [audio: url] etc. so plain-text adapters see something meaningful.

#Parameters

#parts

ContentPart[]

#Returns

string


#Function: safeParseArgs()

safeParseArgs(args): Record<string, unknown>

Defined in: packages/core/src/primitives.ts:137

Backwards-compatible parser for callers that only need the safe value.

#Parameters

#args

string

#Returns

Record<string, unknown>


#Function: serializeMessages()

serializeMessages(messages): MemoryRecord

Defined in: packages/core/src/memory.ts:5

#Parameters

#messages

Message[]

#Returns

MemoryRecord


#Function: textPart()

textPart(text): TextPart

Defined in: packages/core/src/types/content.ts:51

Build a text part.

#Parameters

#text

string

#Returns

TextPart


#Function: videoPart()

videoPart(source, opts?): VideoPart

Defined in: packages/core/src/types/content.ts:64

#Parameters

#source

string

#opts?

Omit<VideoPart, "type" | "source"> = \{\}

#Returns

VideoPart

Explore nearby

On this page

Function: activateSkills()Parametersskillsprompt?ReturnsFunction: audioPart()Parameterssourceopts?ReturnsFunction: buildMessage()Parametersparamscontentmetadata?rolestatus?toolCallId?ReturnsFunction: buildToolMap()ParameterssourcesReturnsFunction: compileBudget()ParametersinputReturnsFunction: consumeStream()ParameterssourcehandlersReturnsFunction: createChatController()ParametersinitialReturnsFunction: createEventEmitter()ReturnsaddObserver()ParametersobserverReturnsemit()ParameterseventReturnsFunction: createInMemoryMemory()ParametersinitialMessages?ReturnsFunction: createLocalStorageMemory()ParameterskeyReturnsFunction: createProgressiveArgParser()ReturnsFunction: createStaticRetriever()ParametersconfigReturnsFunction: createToolLifecycle()ParameterstoolsReturnsdisposeAll()Returnsinit()ParameterstoolReturnsFunction: createVirtualizedMemory()Parametersbackingoptions?ReturnsFunction: defineTool()Type ParametersTSchemaParametersconfigReturnsFunction: deserializeMessages()ParametersrecordReturnsFunction: executeSafeTool()ParametersoptionsReturnsFunction: executeToolCall()ParameterstoolargscontextonPartialResult?ReturnsFunction: executeToolProgressively()Type ParametersTArgsParameterstoolchunkscontextoptions?ReturnsFunction: filePart()Parameterssourceopts?ReturnsFunction: filterParts()Type ParametersTParameterspartskindReturnsFunction: formatRetrievedDocuments()ParametersdocumentsReturnsFunction: generateId()ParametersprefixReturnsFunction: imagePart()Parameterssourceopts?ReturnsFunction: normalizeContent()ParameterscontentpartsReturnspartstextFunction: parseToolArgs()ParametersargsReturnsFunction: partsToText()ParameterspartsReturnsFunction: safeParseArgs()ParametersargsReturnsFunction: serializeMessages()ParametersmessagesReturnsFunction: textPart()ParameterstextReturnsFunction: videoPart()Parameterssourceopts?Returns