Skip to main content

REFERENCE

Developer Reference

Authentication, APIs, SDKs, Flow Agent processors and parameter resolution, in full.

asgard.message.delta

The asgard.message.delta event streams the content of a message. Each event carries a small piece of text, and the idx field is what keeps them in order.

  1. What it is​

    • When it fires: as the AI generates content, sending it out in pieces
    • What it is for: the live typewriter effect
    • How often: a message can produce many delta events
  2. The fields that matter​

    FieldWhat it is
    messageDelta.message.textThe increment: the new piece of text, which may be a character, a phrase or a sentence
    messageDelta.message.idxThe position, counting up from 0
    messageDelta.message.templateUsually null; it has a value in the complete event
  3. A full example​

    The example below shows the typewriter effect for one complete message. Say the AI is about to answer with a sentence: it goes out as several delta events, each a character, a phrase or a sentence.

    Delta 1 (idx: 0), the first piece​

    {
    "eventType": "asgard.message.delta",
    "requestId": "6939c5a6c590d90c401e3850a1ff44f3",
    "namespace": "qa-7e301310-a594-4a7b-aa2a-xxxxxxxxxxxx",
    "botProviderName": "bpapi-d97c512f-f8dc-46f6-82f0-xxxxxxxxxxxx",
    "customChannelId": "ch-6xxxxxxxxxxxx",
    "fact": {
    "runInit": null,
    "runDone": null,
    "runError": null,
    "messageStart": null,
    "messageDelta": {
    "message": {
    "messageId": "1834828082242916352",
    "replyToCustomMessageId": "",
    "text": "目前", // <- only the new text
    "payload": null,
    "isDebug": false,
    "idx": 0, // <- the first piece
    "template": null // <- usually null
    }
    },
    "messageComplete": null
    }
    }

    Delta 2 (idx: 1), the second piece​

    {
    "eventType": "asgard.message.delta",
    "requestId": "6939c5a6c590d90c401e3850a1ff44f3",
    "namespace": "qa-7e301310-a594-4a7b-aa2a-xxxxxxxxxxxx",
    "botProviderName": "bpapi-d97c512f-f8dc-46f6-82f0-xxxxxxxxxxxx",
    "customChannelId": "ch-6xxxxxxxxxxxx",
    "fact": {
    "runInit": null,
    "runDone": null,
    "runError": null,
    "messageStart": null,
    "messageDelta": {
    "message": {
    "messageId": "1834828082242916352",
    "replyToCustomMessageId": "",
    "text": "台", // <- only the new text
    "payload": null,
    "isDebug": false,
    "idx": 1, // <- the second piece
    "template": null
    }
    },
    "messageComplete": null
    }
    }

    Delta 3 (idx: 2), the third piece​

    {
    "eventType": "asgard.message.delta",
    "requestId": "6939c5a6c590d90c401e3850a1ff44f3",
    "namespace": "qa-7e301310-a594-4a7b-aa2a-xxxxxxxxxxxx",
    "botProviderName": "bpapi-d97c512f-f8dc-46f6-82f0-xxxxxxxxxxxx",
    "customChannelId": "ch-6xxxxxxxxxxxx",
    "fact": {
    "runInit": null,
    "runDone": null,
    "runError": null,
    "messageStart": null,
    "messageDelta": {
    "message": {
    "messageId": "1834828082242916352",
    "replyToCustomMessageId": "",
    "text": "北", // <- only the new text
    "payload": null,
    "isDebug": false,
    "idx": 2, // <- the third piece
    "template": null
    }
    },
    "messageComplete": null
    }
    }
  4. Reading the example​

    What accumulates​

    As the delta events arrive, the front end accumulates the text like this:

    • After delta 1: "目前" (possibly a phrase)
    • After delta 2: "目前台" (still accumulating)
    • After delta 3: "目前台北" (still accumulating)

    What to notice​

    1. The messageId is the same: every delta belongs to the same message
    2. idx counts up: which is what lets you process them in order
    3. text is an increment: each one carries the new piece, whether a character, a phrase or a sentence
  5. Worth knowing​

    • Order matters: process them in idx order
    • Accumulate the text: join the text of every delta to produce the typewriter effect
    • Watch the cost: the interface updates frequently, so keep an eye on performance

Ready to get started?

Want to see how Asgard fits your team? Talk to us.

Contact us