formatContextPromptText (messages/context-prompt.ts)

airi · packages/core-agent/src/messages/context-prompt.ts · typescript · MIT
ai, tag:knn-classified

Formats runtime context into a deterministic prompt block for chat models, returning a user message or empty string.

// Source: https://github.com/moeru-ai/airi | License: MIT | Copyright 2024-PRESENT Neko Ayaka
// Provided via justclaw.it.com; keep this notice with the code.
import type { UserMessage } from '@xsai/shared-chat'

import type { ContextMessage } from '../types/chat'

/**
 * Active context messages grouped by core registry source key.
 *
 * The record values are cloned snapshots owned by callers; mutating them must
 * not mutate the underlying context registry.
 */
export type ContextSnapshot = Record<string, ContextMessage[]>

/**
 * Render runtime context modules into a compact, readable text block.
 *
 * Use when:
 * - Composing chat prompts that need to attach side-channel runtime context
 *   (e.g. game state, system status) to the latest user message.
 *
 * Expects:
 * - A snapshot key

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key