FluxyChat

AI Agents

Agent lifecycle callbacks

Systematic onStart, onStepStart, onToolExecution, and onEnd hooks for generate, stream, and agent loops.

@fluxy-chat/agent exposes lifecycle hooks aligned with Vercel AI SDK 7 telemetry phases — use them for logging, billing, guardrails, and OpenTelemetry export.

Callback phases

PhaseWhen
onStartBefore the first model step
onStepStartBefore each agent step
onLanguageModelCallStart / onLanguageModelCallEndAround each LLM request
onToolExecutionStart / onToolExecutionEndAround each tool call
onStepEndAfter each step completes
onEndWhen the run finishes

Agent loop example

import { runAgentLoop } from "@fluxy-chat/agent";

await runAgentLoop({
  model,
  tools,
  messages,
  onStart: ({ callId, maxSteps }) => {
    console.log("run", callId, "maxSteps", maxSteps);
  },
  onToolExecutionStart: ({ toolCall }) => {
    console.log("tool", toolCall.name);
  },
  onEnd: ({ text, usage }) => {
    console.log("tokens", usage.totalTokens);
  },
});

SDK telemetry bridge

Wire the same events to OTLP or console export:

import {
  createTelemetryManager,
  createOtlpTelemetryIntegration,
} from "@fluxy-chat/sdk";

const telemetry = createTelemetryManager();
telemetry.register(
  createOtlpTelemetryIntegration({
    endpoint: process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT!,
  }),
);

See Observability (OTLP).

On this page