packages/agent-signal/README.md
@lobechat/agent-signal is the shared Agent Signal domain package. It defines the language of Agent Signal nodes and source events, but it does not run policies, call model runtimes, read databases, trigger workflows, or import app server modules.
Use this package when code needs browser-safe or server-safe source event types, source event constants, scope-key helpers, and the core Agent Signal node shapes.
Do not add app integration here. Side effects belong in src/server/services/agentSignal or the browser service facade.
Import from the package root when building or inspecting source, signal, action, and executor nodes:
import type { AgentSignalSource, BaseAction, BaseSignal } from '@lobechat/agent-signal';
import { createAction, createSignal, createSource } from '@lobechat/agent-signal';
Use these APIs inside runtime, scheduler, policy, and observability code that needs normalized semantic nodes.
Import from @lobechat/agent-signal/source when producing, typing, validating, or routing source events:
import {
AGENT_SIGNAL_SOURCE_TYPES,
createSourceEvent,
type AgentSignalSourceEvent,
type AgentSignalSourceEventInput,
} from '@lobechat/agent-signal/source';
const event = createSourceEvent({
payload: {
message: 'Please remember that I prefer concise answers.',
messageId: 'msg_1',
topicId: 'topic_1',
},
sourceId: 'source_1',
sourceType: AGENT_SIGNAL_SOURCE_TYPES.agentUserMessage,
});
createSourceEvent fills in:
scopeKey, from topicId first, then bot thread metadata, then fallback:globaltimestamp, from Date.now() when the caller does not provide oneUse AgentSignalSourceEventInput<TSourceType> for producer inputs and AgentSignalSourceEvent<TSourceType> once scopeKey and timestamp are required.
Use getSourceEventScopeKey for source-event payloads and AgentSignalScopeKey when code already has structured scope metadata:
import { AgentSignalScopeKey, getSourceEventScopeKey } from '@lobechat/agent-signal/source';
const topicScopeKey = getSourceEventScopeKey({ topicId: 'topic_1' });
const botScopeKey = AgentSignalScopeKey.forBotThread({
applicationId: 'discord-app',
platform: 'discord',
platformThreadId: 'thread_1',
});
Use this package for:
Use the browser service facade for:
See src/services/agentSignal.ts and src/store/chat/slices/aiChat/actions/agentSignalBridge.ts.
Use server services for:
See src/server/services/agentSignal/emitter.ts, src/server/services/agentSignal/orchestrator.ts, and src/server/services/agentSignal/sources/index.ts.
| Source event | Constant | Primary producer | Payload intent |
|---|---|---|---|
agent.execution.completed | AGENT_SIGNAL_SOURCE_TYPES.agentExecutionCompleted | Agent Runtime | Server agent execution completed with operation, step, topic, and context metadata. |
agent.execution.failed | AGENT_SIGNAL_SOURCE_TYPES.agentExecutionFailed | Agent Runtime | Server agent execution failed with operation, reason, error, topic, and context metadata. |
agent.user.message | AGENT_SIGNAL_SOURCE_TYPES.agentUserMessage | Workflow bridge, Bot router | User feedback/message content that policies can analyze for memory, prompt, document, or skill changes. |
bot.message.merged | AGENT_SIGNAL_SOURCE_TYPES.botMessageMerged | Bot router | Bot-platform message content merged into a conversation scope. |
client.gateway.error | AGENT_SIGNAL_SOURCE_TYPES.clientGatewayError | Gateway event handler | Browser gateway error for a client-side runtime operation. |
client.gateway.runtime_end | AGENT_SIGNAL_SOURCE_TYPES.clientGatewayRuntimeEnd | Gateway event handler | Browser gateway runtime finished for a client-side operation. |
client.gateway.step_complete | AGENT_SIGNAL_SOURCE_TYPES.clientGatewayStepComplete | Gateway event handler | Browser gateway step completed with operation and step index metadata. |
client.gateway.stream_start | AGENT_SIGNAL_SOURCE_TYPES.clientGatewayStreamStart | Gateway event handler | Browser gateway stream started with operation and first step metadata. |
client.runtime.complete | AGENT_SIGNAL_SOURCE_TYPES.clientRuntimeComplete | Chat streaming executor | Browser chat runtime completed with operation, topic, thread, and status metadata. |
client.runtime.start | AGENT_SIGNAL_SOURCE_TYPES.clientRuntimeStart | Chat streaming executor | Browser chat runtime started; workflow may bridge this into agent.user.message with serialized context. |
runtime.after_step | AGENT_SIGNAL_SOURCE_TYPES.runtimeAfterStep | Agent Runtime | Server runtime step finished with operation, step index, topic, and context metadata. |
runtime.before_step | AGENT_SIGNAL_SOURCE_TYPES.runtimeBeforeStep | Agent Runtime | Server runtime step is about to run with operation, step index, topic, and context metadata. |
AGENT_SIGNAL_CLIENT_SOURCE_TYPES is the allow-list for browser-originated events accepted by src/server/routers/lambda/agentSignal.ts. It currently includes only the client.* source events.
createSourceEvent.AgentSignalSource.AGENT_SIGNAL_CLIENT_SOURCE_TYPES only when browser code should be allowed to emit it through the lambda router.Keep source events stable. Source type strings are persisted in traces, dedupe keys, and workflow payloads.