Crestapps core external relays

From CrestApps/CrestApps.AgentSkills · View interactive version

Crestapps core external relays is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for implementing and managing persistent external chat relays in CrestApps.Core 2.0 using IExternalChatRelay, IExternalChatRelayManager and its ExternalChatRelayConnectionManager singleton, ExternalChatRelayContext, IExternalChatRelayEventHandler, IExternalChatRelayNotificationHandler, IExtern

How to use this skill

Skill file

CrestApps.Core External Chat Relays

Scope

IExternalChatRelay is the contract for a persistent, bidirectional connection to a live-agent or other external chat platform. An implementation supplies connection, prompt, signal, disconnect, and async-disposal behavior; the transport is application-defined.

The core packages ship no IExternalChatRelay implementation, only the manager: ExternalChatRelayConnectionManager is registered by AddCoreAIOrchestration() as the singleton IExternalChatRelayManager and tracks relay instances by session ID. Its members are GetOrCreateAsync(sessionId, context, factory, cancellationToken), Get(sessionId) and CloseAsync(sessionId, cancellationToken).

Connect and Close a Relay

Create the relay in the factory passed to the manager. The manager connects it, disposes a failed connection attempt, and disposes an extra instance if a concurrent caller won the same session ID.

var relay = await relayManager.GetOrCreateAsync(
    sessionId,
    new ExternalChatRelayContext
    {
        SessionId = sessionId,
        ChatType = ChatContextType.AIChatSession,
    },
    () => new MyExternalChatRelay(),
    cancellationToken);

await relay.SendPromptAsync(prompt, cancellationToken);
await relayManager.CloseAsync(sessionId, cancellationToken);

MyExternalChatRelay must implement IExternalChatRelay. The manager does not construct relays or choose a platform.

Event and Notification Integration

The current packages ship no default IExternalChatRelayEventHandler, IExternalChatRelayNotificationHandler, or IExternalChatRelayNotificationBuilder implementation. Consequently, registering a relay alone does not route incoming external events into chat messages or notifications.

An integration that needs event routing must implement and register its own IExternalChatRelayEventHandler (HandleEventAsync) and IExternalChatRelayNotificationHandler (HandleAsync). IExternalChatRelayNotificationBuilder exposes NotificationType and Build(relayEvent, notification, result, T); nothing in the core packages resolves builders, so your notification handler decides how to pick one, for example by matching NotificationType to ExternalChatRelayEvent.EventType. ExternalChatRelayEventTypes supplies constants such as agent-typing, agent-stopped-typing, agent-connected, agent-disconnected, agent-reconnecting and connection-lost; integrations may add custom strings. ExternalChatRelayEvent carries EventType, Content, AgentName and Metadata.

Keep platform credentials and reconnection policy inside the relay implementation. Call CloseAsync when the corresponding session ends so the manager disconnects and disposes the relay.

Related skills

Upgrading from 1.x

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.