Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Openclaw Openclaw GetReplyFromConfig

From Leeroopedia


Knowledge Sources
Domains Agent_Runtime, LLM_Integration
Last Updated 2026-02-06 12:00 GMT

Overview

Concrete orchestrator function for assembling agent context and producing a reply, provided by the OpenClaw agent runtime.

Description

getReplyFromConfig is the primary entry point for the reply pipeline. It accepts a normalized MsgContext envelope, optional reply options, and an optional configuration override, then orchestrates the full context assembly process: resolving the agent and model, bootstrapping the workspace, running media and link understanding, initializing session state, parsing directives, handling inline actions, staging sandbox media, and finally delegating to runPreparedReply for LLM inference.

The function is designed to be called by channel handlers after message normalization and routing. It returns either a single ReplyPayload, an array of payloads (for multi-part replies), or undefined (when the message should be silently ignored).

Key internal stages:

  1. Agent and model resolution -- derives the agent ID from the session key, resolves the default model/provider, applies heartbeat model overrides if applicable.
  2. Workspace bootstrapping -- ensures the agent workspace directory exists with bootstrap files.
  3. Finalization -- calls finalizeInboundContext to produce a FinalizedMsgContext with guaranteed authorization fields.
  4. Media/link understanding -- enriches the context with transcriptions and summaries.
  5. Session initialization -- loads session state, history, and determines reset/abort status.
  6. Directive resolution -- parses user directives and resolves model, think level, verbose level, elevated permissions, and tool overrides.
  7. Inline action handling -- processes status requests, session commands, and skill commands that short-circuit before LLM inference.
  8. Sandbox media staging -- copies media files into the sandbox workspace.
  9. Prepared reply -- delegates to runPreparedReply with the fully assembled parameters.

Usage

Call getReplyFromConfig from any channel handler after constructing a MsgContext. Pass GetReplyOptions to configure streaming callbacks, abort signals, skill filters, and typing indicators.

Code Reference

Source Location

  • Repository: openclaw
  • File: src/auto-reply/reply/get-reply.ts
  • Lines: 53-334

Signature

export async function getReplyFromConfig(
  ctx: MsgContext,
  opts?: GetReplyOptions,
  configOverride?: OpenClawConfig,
): Promise<ReplyPayload | ReplyPayload[] | undefined>

Import

import { getReplyFromConfig } from "../auto-reply/reply/get-reply.js";

I/O Contract

Inputs

Name Type Required Description
ctx MsgContext Yes The normalized inbound message envelope populated by the channel adapter.
opts GetReplyOptions No Optional configuration for streaming, abort control, skill filtering, and event callbacks.
configOverride OpenClawConfig No Override for the loaded configuration. When omitted, the function calls loadConfig() to read the current configuration.

The GetReplyOptions type includes:

Name Type Description
runId string Override run ID for agent events.
abortSignal AbortSignal Abort signal for the underlying agent run.
images ImageContent[] Inbound images (webchat attachments).
onReplyStart () => void Callback when the agent run starts producing a reply.
onPartialReply (payload: ReplyPayload) => void Streaming partial reply callback.
onBlockReply (payload: ReplyPayload) => void Block-level reply callback for chunked streaming.
onToolResult (payload: ReplyPayload) => void Tool result emission callback.
isHeartbeat boolean Whether this is a heartbeat (scheduled) message.
skillFilter string[] Restrict loaded skills to this list.

Outputs

Name Type Description
(return) ReplyPayload[] | undefined A single reply, multiple reply payloads (multi-part), or undefined if the message should be silently ignored.

The ReplyPayload type:

export type ReplyPayload = {
  text?: string;
  mediaUrl?: string;
  mediaUrls?: string[];
  replyToId?: string;
  replyToTag?: boolean;
  replyToCurrent?: boolean;
  audioAsVoice?: boolean;
  isError?: boolean;
  channelData?: Record<string, unknown>;
};

Usage Examples

Basic Usage

import { getReplyFromConfig } from "../auto-reply/reply/get-reply.js";
import type { MsgContext } from "../auto-reply/templating.js";

const ctx: MsgContext = {
  Body: "Summarize the latest changes",
  BodyForAgent: "Summarize the latest changes",
  SessionKey: "agent:default:telegram:dm:12345",
  Provider: "telegram",
  OriginatingChannel: "telegram",
  OriginatingTo: "12345",
};

const reply = await getReplyFromConfig(ctx, {
  onPartialReply: (payload) => {
    // Stream partial text to the client
    process.stdout.write(payload.text ?? "");
  },
  abortSignal: AbortSignal.timeout(60_000),
});

if (Array.isArray(reply)) {
  for (const part of reply) {
    await sendToChannel(part);
  }
} else if (reply) {
  await sendToChannel(reply);
}

Related Pages

Implements Principle

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment