Creating Plot Twists
    Preparing search index...

    Class ChatAbstract

    Built-in tool for realtime conversation with the user.

    A twist attaches a chat action to a note; tapping it opens a conversation the user can speak or type, with the same agent either way. Each finished turn is written into the thread as a note, so the conversation reads the same while it is happening and when the user scrolls back to it later. When it ends, the twist's onEnded callback receives the transcript.

    class CoachTwist extends Twist<CoachTwist> {
    build(build: ToolBuilder) {
    return {
    plot: build(Plot, { thread: { access: ThreadAccess.Create } }),
    chat: build(Chat),
    };
    }

    async offer(threadId: string) {
    await this.tools.plot.createNote({
    thread: { id: threadId },
    content: "Want to talk this through?",
    actions: [
    await this.tools.chat.action({
    title: "Talk it through",
    spec: await this.callback(this.launchSpec),
    threadId,
    }),
    ],
    });
    }

    async launchSpec(): Promise<NewChatSpec> {
    return {
    instructions: "You are a coach. Ask one question at a time.",
    greeting: "What's actually holding this up?",
    onEnded: await this.callback(this.extract),
    };
    }

    async extract(session: ChatSession) {
    // Post-process session.turns however the twist needs.
    }
    }

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    Constructors

    Methods

    • Builds the action to attach to a note.

      Parameters

      • opts: { title: string; spec: Callback; threadId: Uuid }
        • title: string

          Button text.

        • spec: Callback

          Callback returning the NewChatSpec, invoked when the user taps.

        • threadId: Uuid

          The thread the note is going on. Used to build the fallback link that clients predating chat support open instead.

      Returns Promise<Action>