Skip to main content
import { Agent, type AgentConfig } from "@ai_kit/core";

AgentConfig

PropertyTypeDefaultDescription
namestringrequiredAgent identifier (logging, telemetry).
instructionsstringundefinedDefault system prompt (override with system).
modelLanguageModelrequiredModel from the AI SDK.
toolsAgentToolsundefinedTools exposed by default (ToolSet or provider-specific).
telemetrybooleanfalseEnables OTEL / Langfuse export by default.
loopToolsbooleanfalseEnables the automatic tool loop.
maxStepToolsnumber20 (DEFAULT_MAX_STEP_TOOLS)Max tool executions before the loop stops.

Constructor

const agent = new Agent(config: AgentConfig);

Instance methods

agent.generate(options)

generate<OUTPUT = never, PARTIAL = never, STATE extends RuntimeState = RuntimeState>(
  options: AgentGenerateOptions<OUTPUT, PARTIAL, STATE>
): Promise<AgentGenerateResult<OUTPUT>>;
Options extend AI SDK generateText parameters (prompt or messages) with:
  • system?: string – overrides the default instructions.
  • structuredOutput?: Output.Output<OUTPUT, PARTIAL> – schema-based generation (Zod).
  • runtime?: RuntimeStore<STATE> – shared runtime (see RuntimeStore).
  • telemetry?: AgentTelemetryOverrides – merges functionId, metadata, recordInputs, recordOutputs.
  • loopTools?: boolean / maxStepTools?: number – per-call overrides for the tool loop.
Returns a GenerateTextResult enriched with loopTool?: boolean.

agent.stream(options)

stream<OUTPUT = never, PARTIAL = never, STATE extends RuntimeState = RuntimeState>(
  options: AgentStreamOptions<OUTPUT, PARTIAL, STATE>
): Promise<AgentStreamResult<PARTIAL>>;
Additional properties:
  • textStream, fullStream, text, response, usage, steps.
  • experimental_partialOutputStream when structuredOutput is provided.
  • toAIStreamResponse() / toDataStreamResponse() to integrate with HTTP streaming responses.
Structured output automatically switches to the structured pipeline when supported by the model.

agent.withTelemetry(enabled?: boolean)

Enable or disable telemetry by mutating the instance. Returns this for chaining.
agent.withTelemetry();      // enable
agent.withTelemetry(false); // disable

Utility types

  • AgentTools – union between AI SDK ToolSet and provider dictionaries.
  • AgentGenerateResult<T> – alias of GenerateTextResult + loopTool.
  • AgentStreamResult<T> – alias of StreamTextResult + loopTool.
  • AgentTelemetryOverridesfunctionId, metadata, recordInputs?, recordOutputs?.

Runtime handling

When runtime is provided:
  • a RuntimeStore snapshot is created for the call duration;
  • onCleanup handlers run at the end (success, error, or cancellation);
  • RuntimeStore.mergeExperimentalContext merges manually passed experimental_context with the runtime state.
Without a runtime, the agent simply wraps the AI SDK behaviour.