kernl

Class: Agent<TContext, TOutput>

Defined in: packages/kernl/src/agent.ts:34

Extends

  • BaseAgent<TContext, TOutput>

Type Parameters

Type ParameterDefault type
TContextUnknownContext
TOutput extends AgentOutputTypeTextOutput

Implements

  • AgentConfig<TContext, TOutput>

Constructors

Constructor

new Agent<TContext, TOutput>(config: AgentConfig<TContext, TOutput>): Agent<TContext, TOutput>;

Defined in: packages/kernl/src/agent.ts:52

Parameters

ParameterType
configAgentConfig<TContext, TOutput>

Returns

Agent<TContext, TOutput>

Overrides

BaseAgent<TContext, TOutput>.constructor

Properties

PropertyModifierTypeDefault valueDescriptionOverridesInherited fromDefined in
description?readonlystringundefined--AgentConfig.description Agent.descriptionpackages/kernl/src/agent/base.ts:58
guardrailsreadonly{ input: InputGuardrail[]; output: OutputGuardrail<AgentOutputType>[]; }undefinedA list of checks that run in parallel to the agent's execution on the input + output for the agent, depending on the configuration.--packages/kernl/src/agent.ts:45
guardrails.inputpublicInputGuardrail[]undefined---packages/kernl/src/agent.ts:46
guardrails.outputpublicOutputGuardrail<AgentOutputType>[]undefined---packages/kernl/src/agent.ts:47
idreadonlystringundefined--AgentConfig.id Agent.idpackages/kernl/src/agent/base.ts:56
instructionsreadonly(context: Context<TContext>) => string | Promise<string>undefined--AgentConfig.instructions BaseAgent.instructionspackages/kernl/src/agent/base.ts:59
kernl?protectedKernlundefined--Agent.kernlpackages/kernl/src/agent/base.ts:51
kindreadonly"llm""llm"-BaseAgent.kind-packages/kernl/src/agent.ts:41
memoryreadonlyAgentMemoryConfigundefined--AgentConfig.memory Agent.memorypackages/kernl/src/agent/base.ts:64
modelreadonlyLanguageModelundefined-AgentConfig.model BaseAgent.model-packages/kernl/src/agent.ts:42
modelSettingsreadonlyLanguageModelRequestSettingsundefinedConfigures model-specific tuning parameters (e.g. temperature, top_p, etc.)--packages/kernl/src/agent.ts:43
namereadonlystringundefined--AgentConfig.name Agent.namepackages/kernl/src/agent/base.ts:57
outputreadonlyTOutputundefinedThe type of the output that the agent will return. Can be either: - "text" (default): The agent returns a plain string response - A Zod schema: The agent returns structured output validated against the schema When a Zod schema is provided, the output is converted to JSON Schema and sent to the model for native structured output support. The response is then validated against the Zod schema as a safety net.--packages/kernl/src/agent.ts:49
resetToolChoicereadonlybooleanundefinedWhether to reset the tool choice to the default value after a tool has been called. Defaults to true. This ensures that the agent doesn't enter an infinite loop of tool usage.--packages/kernl/src/agent.ts:50
systoolsreadonlyBaseToolkit<TContext>[]undefined--BaseAgent.systoolspackages/kernl/src/agent/base.ts:63
toolkitsreadonlyBaseToolkit<TContext>[]undefined--AgentConfig.toolkits BaseAgent.toolkitspackages/kernl/src/agent/base.ts:62

Accessors

memories

Get Signature

get memories(): {
  create: (params: AgentMemoryCreate) => Promise<MemoryRecord>;
  list: (params?: Omit<MemoryListOptions, "filter"> & {
     collection?: string;
     limit?: number;
  }) => Promise<MemoryRecord[]>;
  search: (params: Omit<MemorySearchQuery, "filter"> & {
     filter?: Omit<MemoryFilter, "scope"> & {
        scope?: Omit<Partial<MemoryScope>, "agentId">;
     };
  }) => Promise<SearchHit<IndexMemoryRecord>[]>;
  update: (params: AgentMemoryUpdate) => Promise<MemoryRecord>;
};

Defined in: packages/kernl/src/agent/base.ts:158

Memory management scoped to this agent.

Returns
{
  create: (params: AgentMemoryCreate) => Promise<MemoryRecord>;
  list: (params?: Omit<MemoryListOptions, "filter"> & {
     collection?: string;
     limit?: number;
  }) => Promise<MemoryRecord[]>;
  search: (params: Omit<MemorySearchQuery, "filter"> & {
     filter?: Omit<MemoryFilter, "scope"> & {
        scope?: Omit<Partial<MemoryScope>, "agentId">;
     };
  }) => Promise<SearchHit<IndexMemoryRecord>[]>;
  update: (params: AgentMemoryUpdate) => Promise<MemoryRecord>;
}
NameTypeDefined in
create()(params: AgentMemoryCreate) => Promise<MemoryRecord>packages/kernl/src/agent/base.ts:183
list()(params?: Omit<MemoryListOptions, "filter"> & { collection?: string; limit?: number; }) => Promise<MemoryRecord[]>packages/kernl/src/agent/base.ts:169
search()(params: Omit<MemorySearchQuery, "filter"> & { filter?: Omit<MemoryFilter, "scope"> & { scope?: Omit<Partial<MemoryScope>, "agentId">; }; }) => Promise<SearchHit<IndexMemoryRecord>[]>packages/kernl/src/agent/base.ts:210
update()(params: AgentMemoryUpdate) => Promise<MemoryRecord>packages/kernl/src/agent/base.ts:200

Inherited from

BaseAgent.memories

threads

Get Signature

get threads(): {
  create: (params: Omit<ThreadCreateParams, "agentId" | "model">) => Promise<Thread>;
  delete: (tid: string) => Promise<void>;
  get: (tid: string, options?: ThreadGetOptions) => Promise<Thread | null>;
  history: (tid: string, params?: ThreadHistoryParams) => Promise<ThreadEvent[]>;
  list: (params: Omit<ThreadsListParams, "agentId">) => Promise<CursorPage<Thread, ThreadsListParams>>;
  update: (tid: string, patch: ThreadUpdateParams) => Promise<Thread | null>;
};

Defined in: packages/kernl/src/agent.ts:210

Thread management scoped to this agent.

Convenience wrapper around kernl.threads that automatically filters to this agent's threads.

Returns
{
  create: (params: Omit<ThreadCreateParams, "agentId" | "model">) => Promise<Thread>;
  delete: (tid: string) => Promise<void>;
  get: (tid: string, options?: ThreadGetOptions) => Promise<Thread | null>;
  history: (tid: string, params?: ThreadHistoryParams) => Promise<ThreadEvent[]>;
  list: (params: Omit<ThreadsListParams, "agentId">) => Promise<CursorPage<Thread, ThreadsListParams>>;
  update: (tid: string, patch: ThreadUpdateParams) => Promise<Thread | null>;
}
NameTypeDefined in
create()(params: Omit<ThreadCreateParams, "agentId" | "model">) => Promise<Thread>packages/kernl/src/agent.ts:228
delete()(tid: string) => Promise<void>packages/kernl/src/agent.ts:225
get()(tid: string, options?: ThreadGetOptions) => Promise<Thread | null>packages/kernl/src/agent.ts:221
history()(tid: string, params?: ThreadHistoryParams) => Promise<ThreadEvent[]>packages/kernl/src/agent.ts:226
list()(params: Omit<ThreadsListParams, "agentId">) => Promise<CursorPage<Thread, ThreadsListParams>>packages/kernl/src/agent.ts:223
update()(tid: string, patch: ThreadUpdateParams) => Promise<Thread | null>packages/kernl/src/agent.ts:237

Methods

bind()

bind(kernl: Kernl): void;

Defined in: packages/kernl/src/agent/base.ts:92

Bind this agent to a kernl instance. Called by kernl.register().

Parameters

ParameterType
kernlKernl

Returns

void

Inherited from

BaseAgent.bind

emit()

emit<K>(event: K, ...args: AgentHookEvents<TContext, TOutput>[K]): boolean;

Defined in: packages/kernl/src/agent/base.ts:107

Emit a lifecycle event to agent and kernl listeners.

Type Parameters

Type Parameter
K extends keyof AgentHookEvents<TContext, TOutput>

Parameters

ParameterType
eventK
...argsAgentHookEvents<TContext, TOutput>[K]

Returns

boolean

Inherited from

BaseAgent.emit

off()

off<K>(event: K, listener: (...args: AgentHookEvents<TContext, TOutput>[K]) => void): this;

Defined in: packages/shared/dist/emitter.d.ts:26

Type Parameters

Type Parameter
K extends keyof AgentHookEvents<TContext, TOutput>

Parameters

ParameterType
eventK
listener(...args: AgentHookEvents<TContext, TOutput>[K]) => void

Returns

this

Inherited from

BaseAgent.off

on()

on<K>(event: K, listener: (...args: AgentHookEvents<TContext, TOutput>[K]) => void): this;

Defined in: packages/shared/dist/emitter.d.ts:25

Type Parameters

Type Parameter
K extends keyof AgentHookEvents<TContext, TOutput>

Parameters

ParameterType
eventK
listener(...args: AgentHookEvents<TContext, TOutput>[K]) => void

Returns

this

Inherited from

BaseAgent.on

once()

once<K>(event: K, listener: (...args: AgentHookEvents<TContext, TOutput>[K]) => void): this;

Defined in: packages/shared/dist/emitter.d.ts:27

Type Parameters

Type Parameter
K extends keyof AgentHookEvents<TContext, TOutput>

Parameters

ParameterType
eventK
listener(...args: AgentHookEvents<TContext, TOutput>[K]) => void

Returns

this

Inherited from

BaseAgent.once

run()

run(input: 
  | string
| LanguageModelItem[], options?: ThreadExecuteOptions<TContext>): Promise<ThreadExecuteResult<ResolvedAgentResponse<TOutput>>>;

Defined in: packages/kernl/src/agent.ts:70

Blocking execution - spawns or resumes thread and waits for completion

Parameters

ParameterType
input| string | LanguageModelItem[]
options?ThreadExecuteOptions<TContext>

Returns

Promise<ThreadExecuteResult<ResolvedAgentResponse<TOutput>>>

Throws

If the specified thread is already running (concurrent execution not allowed)

Throws

If the agent is not bound to a kernl instance


stream()

stream(input: 
  | string
| LanguageModelItem[], options?: ThreadExecuteOptions<TContext>): AsyncIterable<ThreadStreamEvent>;

Defined in: packages/kernl/src/agent.ts:141

Streaming execution - spawns or resumes thread and returns async iterator

NOTE: streaming probably won't make sense in scheduling contexts so spawnStream etc. won't make sense

Parameters

ParameterType
input| string | LanguageModelItem[]
options?ThreadExecuteOptions<TContext>

Returns

AsyncIterable<ThreadStreamEvent>

Throws

If the specified thread is already running (concurrent execution not allowed)

Throws

If the agent is not bound to a kernl instance


tool()

tool(id: string): Tool<TContext> | undefined;

Defined in: packages/kernl/src/agent/base.ts:119

Get a specific tool by ID from systools and toolkits.

Parameters

ParameterType
idstring

Returns

Tool<TContext> | undefined

Inherited from

BaseAgent.tool

tools()

tools(context: Context<TContext>): Promise<Tool<TContext>[]>;

Defined in: packages/kernl/src/agent/base.ts:136

Get all tools available from systools and toolkits for the given context.

Parameters

ParameterType
contextContext<TContext>

Returns

Promise<Tool<TContext>[]>

Inherited from

BaseAgent.tools

On this page