Skip to content

Guided tour

FabrCore 2.0 · Release and package availability

These guides track the current 2.0 source. Stable 2.0.0 publication is pending; package commands show the release target. Until it is published, follow the source quick start or use a matching available prerelease set. Release migration · Runtime modes

MODULE 05 · LESSON 5.8

Connect page behavior to chat and agent lifecycle

Connect agent messages to page refresh and explicit lifecycle controls.

Lesson 28 of 86 · FabrCore 2.0

Overview

The page may need to react to a business result without showing its control payload as a chat bubble. OnMessageReceived receives the whole AgentMessage. Returning false suppresses that item only in the link panel; it does not erase shared workspace history.

A business response may need two presentations

An agent can return text for the conversation and metadata that tells the page to refresh a request record. OnMessageReceived receives the whole envelope so application code can recognize its own contract. Returning false suppresses that item in this link panel; it does not delete it from shared history or cancel the underlying business operation.

Bind lifetime to your intended scope

A page-scoped agent can be useful for temporary work, while an enduring assistant should outlive a component render. Dispose subscriptions when the component leaves and avoid provisioning a new instance on every UI update. A callback that performs a write must still check authorization and idempotency; receiving an agent message is not blanket approval to mutate a record.

Handle a page-specific response

Download the Operations Desk source. The README lists project setup, package prerequisites and local ports.

  1. Handle data-changed or ui-update messages in C#, validate the target/context, refresh the page data and return false when the panel should suppress the handled payload. Return true for normal chat.
  2. Use CreateAgent with SurfaceChatLinkCreateAgentContext to supply a page-specific recipe. Creation happens after the user clicks Create, not automatically on page load.
  3. Use AllowExternalAgent for an already healthy pre-provisioned target; disable it for strict manual creation. Enable AllowReset only when reset is appropriate and label readiness/lifecycle messages clearly.
Parent Message Interception · reference snippet
<SurfaceChatLink AgentHandle="crm-agent"
                 Title="CRM Assistant"
                 OnMessageReceived="HandleAgentMessageAsync" />

@code {
    private async Task<bool> HandleAgentMessageAsync(AgentMessage message)
    {
        if (string.Equals(message.MessageType, "ui-update", StringComparison.OrdinalIgnoreCase))
        {
            await RefreshSectionAsync(message.Message);
            return false;
        }

        if (string.Equals(message.MessageType, "data-changed", StringComparison.OrdinalIgnoreCase))
        {
            await ReloadDataAsync();
            return false;
        }

        return true;
    }
}
Page-Scoped Agents · reference snippet
<SurfaceChatLink AgentHandle="customer-assistant"
                 Title="Customer Assistant"
                 CreateAgent="CreateCustomerAssistantAsync"
                 AllowReset="true" />

@code {
    private Task<AgentHealthStatus> CreateCustomerAssistantAsync(
        SurfaceChatLinkCreateAgentContext context)
    {
        return context.PrincipalContext.CreateAgent(new AgentConfiguration
        {
            Handle = context.AgentAlias,
            AgentType = "customer-agent",
            Models = "default",
            Description = "Customer page assistant",
            ForceReconfigure = false
        });
    }
}

Verify both the callback and the history

  1. Send a test response with the page's expected metadata. Observe the callback updating the intended request view and confirm it ignores unrelated envelopes.
  2. Return false for that recognized control payload and confirm it is absent from the local panel's bubbles. Inspect shared history separately to see that suppression did not erase the stored message.
  3. Navigate away and return. One incoming response should trigger one active callback, not accumulated handlers from earlier component instances.

The page now interprets an explicit application contract while preserving the distinction between local rendering, shared history and business effects.

If the result is different

Reset is not hard eviction. Suppressing a message in one panel does not remove it from /surface or delete the agent's history.

Go deeper

Explore the related documentation.