Briyah SDK - v2.0.6
    Preparing search index...

    Class Agent

    Index
    agentName: string
    agentNickname: string
    allowSearch: boolean
    assistant?: Assistant
    attachedArtifacts: string[] = []
    attachedFiles: FileMetadata[] = []
    beginInstruction: string = ''
    createdAt: Date
    description: string
    disableBalanceCheck: boolean = false
    disableMarkup: boolean = false
    enabledPacks?: () => readonly string[]

    The packs the owning user has enabled, consulted only when promptFolder is a bare name — a pack-qualified one always resolves.

    A thunk rather than an array because an agent outlives a toggle: the user can enable a pack while this instance is cached, and a snapshot taken at construction would need invalidating across every cached agent, room and service. Reading through the thunk means there is nothing to invalidate.

    Absent means "scan no packs", which is exactly the behaviour from before packs existed. Deliberately not in AgentConfig — it belongs to the user, not the agent, and persisting it would freeze a copy of the enabled set.

    fullContextFiles: boolean = true
    history: any[]
    historyPin?: number

    Index into history below which the rolling window may trim, and at or above which it may not. Protects a task that must survive intact from an agent whose window is deliberately short.

    Deliberately not in AgentConfig and never saved. maxHistoryMessages is operator configuration; this is transient state about the task in flight, and persisting it would leave an agent looking as though its window had been changed by hand. A restart clears it, costing at most the protection on one task in progress.

    It also needs no clearing. Re-pinning ends the previous pin, so an abandoned task is reclaimed the next time one starts, and the worst a stale pin can do is keep more history than intended — never drop any.

    id?: string
    isControlledByHuman: boolean = false
    isPublished: boolean = false
    markupRate: number = 2
    maxHistoryMessages?: number
    maxOutputTokens: number = 0
    modelName: string
    openai?: OpenAI
    ownerRoomId?: string
    pack?: string

    The pack this agent is filed under. See AgentConfig.pack.

    packAgentKey?: string

    The pack template's key, when this agent came from one.

    privateContext: string = ''

    Private, agent-specific context that is visible only to this agent — never to other agents. Injected into the agent's transient (uncached) prompt message rather than the cached system instructions, so it can change frequently without invalidating the prompt cache. In stories this holds the character's inventory and conditions; contrast with description, which is the public appearance every other agent can see.

    promptCacheTTL: number = 0
    promptFolder: string
    reasoningEffort: "low" | "medium" | "high"
    serviceName: string
    smallModelName?: string
    storageDir: string
    templateAgentId?: string
    toolNames: string[] = []
    totalCost: number = 0
    totalInputTokens: number = 0
    totalMarkup: number = 0
    totalOutputTokens: number = 0
    useModerator: boolean = false

    This agent intends to send MODERATE messages, so its room needs a moderator to route them.

    For a human-controlled agent it is also what removes the action and target pickers from the room's composer: the player types, the room forces the message to MODERATE, and the moderator decides who hears it and who answers.

    For an AI agent it is a declaration, not a coercion. An agent emits MODERATE by its own choice — either its perceive schema offers moderate as a way to defer the routing decision, or it has no schema at all and answers in prose, which Room.parseAgentResponse converts. An agent that names its own targets keeps doing so.

    vectorStore?: VectorStore
    • Parameters

      • message: any
      • fromSelf: boolean = false

      Returns void

    • Attaches an artifact to the agent

      Parameters

      • artifactId: string

        The artifact ID

      Returns void

    • Parameters

      • fileName: string
      • fileData: Uint8Array

      Returns Promise<string>

    • Parameters

      Returns boolean

    • Replace this agent's conversation history with a single summary message. Uses the compact_agent prompt, resolved via the standard lookup order: user/ → user/root → common/ → common/root. On failure, the original history is restored.

      Returns Promise<
          {
              message: string;
              newChars: number;
              newLength: number;
              originalChars: number;
              originalLength: number;
              success: boolean;
              summary?: string;
          },
      >

    • Returns Promise<void>

    • Drops the newest message from history.

      From the end only, which is what makes it safe to call repeatedly: the head of history is untouched, so a provider that requires the conversation to open on a user message still gets one. It can leave two messages of the same role adjacent, which the APIs accept and fold into a single turn.

      The caller decides what a message is worth — nothing here asks whether the message being removed is an agent's answer or the prompt that drew it, because a person undoing a turn wants both gone and clicks twice.

      Returns boolean

      True when a message was removed, false when only framing was left

    • Detaches an artifact from the agent

      Parameters

      • artifactId: string

        The artifact ID

      Returns void

    • Parameters

      • prompt: string
      • OptionalimageProperties: Record<string, any>
      • OptionalreferenceImageArtifactIds: string[]

      Returns Promise<{ artifactId?: string; error?: any }>

    • Returns Promise<void>

    • Generates an image from a text prompt.

      Parameters

      • prompt: string

        Text description of the image

      • OptionalimageProperties: Record<string, any>

        Optional provider-specific image options (e.g. width, height, quality) passed through to the underlying AI service

      Returns Promise<{ artifactId?: string; error?: any }>

      Promise resolving to { artifactId } on success or { error } on failure

    • Gets all attached artifact IDs

      Returns string[]

      Array of artifact IDs

    • Gets formatted messages from the agent's history starting from a specific index

      Parameters

      • fromIndex: number = 0

        The index to start from (0-based)

      Returns string[]

      Array of formatted messages

    • Gets the raw (unformatted) content of every message in the agent's history.

      Returns string[]

      Array of message content strings

    • Whether this agent's own prompt folder supplies <name>.prompt, rather than inheriting it from the shared roots. See BaseAiService.hasOwnPromptFile for why both questions exist.

      Parameters

      • name: string

      Returns boolean

    • Whether <name>.prompt resolves for this agent, so a caller can tell an agent that can run a kind of turn from one whose prompt folder has no prompt for it.

      False when the agent has no AI service or no paths yet — the answer to "could this agent run that turn" is then no, which is what a caller wants to hear.

      Parameters

      • name: string

      Returns boolean

    • The size of this agent's conversation history in characters.

      Returns number

      Total characters across every message in history

    • Parameters

      • prompt: string
      • instructionFileName: string
      • variables: any
      • saveResponse: boolean = true
      • cacheMessage: boolean = false
      • maxOutputChars: number = 0

      Returns Promise<any>

    • Whether this agent's history has grown past the compaction threshold.

      An agent with maxHistoryMessages is excluded: a rolling window already bounds it, and the two mechanisms answer different needs. A window is for an agent whose old turns stop mattering — a moderator routing the next message does not need last hour's. Compaction is for one whose past must survive in some form, which is why it costs a model call to write a summary rather than dropping messages off the front.

      Returns boolean

      True when compaction is worth a call

    • Notifies listeners that the agent state has changed Triggers SSE updates if callback is registered

      Returns void

    • Marks the current end of history as the start of a task the rolling window must not trim into.

      A no-op for an agent with no window: there is nothing to protect it from, and a pin on an agent that keeps everything would only be a field to explain. That is what makes it safe to call from a shared path — the Dungeon Master running its own fight keeps its whole campaign either way.

      Call it before the message that starts the task is added to history, so the task's own opening instruction is inside the pin rather than the first thing dropped.

      Returns void

    • Parameters

      • promptFileName: string
      • variables: any
      • saveResponse: boolean = true
      • cacheMessage: boolean = false

      Returns Promise<any>

    • Saves the agent to disk via AgentStoreService Called automatically after conversation history changes

      Returns void

    • Sets the callback to be called when agent state changes Used for SSE updates to push changes to connected clients

      Parameters

      • callback: () => void

        Function to call when state changes

      Returns void

    • Parameters

      • prompt: string
      • jsonSchema: any = null
      • saveResponse: boolean = true
      • promptInstructions: string = null
      • cacheMessage: boolean = false
      • maxOutputChars: number = 0

      Returns Promise<any>

    • Trims conversation history to keep only the last N messages if maxHistoryMessages is set Preserves system messages (role: 'developer') at the start of history Used for rolling window history management (e.g., moderator agents)

      A historyPin raises the floor: everything since the pin is kept even when that is more than the window allows. The window still applies to whatever came before it, so a specialist handed a second task drops the first.

      Parameters

      • threshold: number = 0

        Allow history to grow 'threshold' messages past the limit before trimming a 'threshold'-sized chunk of messages at once

      Returns void

    • Type Parameters

      • T

      Parameters

      • fn: () => Promise<T>

      Returns Promise<T>

    • How large a history may grow, in characters, before it is worth compacting.

      Read per call rather than cached so an operator can retune a long-running server without restarting it. Characters rather than tokens because it is the one measure available without asking a tokenizer, and the threshold only has to be roughly right — four characters to a token is close enough to make 100,000 mean "about 25k tokens".

      Returns number

      The threshold in characters

    • Generates a nickname from an agent name by taking the first word

      Parameters

      • agentName: string

        The full agent name

      Returns string

      The first word as nickname, or the full name if empty