Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.7 KB
Raw Blame
import {
  AGENT_SIGNAL_SKILL_MANAGEMENT_IDENTIFIER,
  AGENT_SIGNAL_SKILL_MANAGEMENT_TOOL_API_NAMES,
} from '@lobechat/builtin-tool-agent-signal';
import { AgentSignalToolExecutionRuntime } from '@lobechat/builtin-tool-agent-signal/executionRuntime';

import { createResourceRuntimePrimitives } from '@/server/services/agentSignal/services/selfIteration/tools/runtimePrimitives';
import { SkillManagementDocumentService } from '@/server/services/skillManagement';

import type { ServerRuntimeRegistration } from './types';

/**
 * Registers the same-turn skill-management builtin server runtime, so an
 * `execAgent` run with `plugins: ['agent-signal-skill-management']` can execute
 * its tools. The surface is skill-only (safe managed-skill reads + creates /
 * CAS replaces) — no memory, no proposal/idea recorders. Evidence is embedded in
 * the agent's prompt, so there is no collector.
 */
export const agentSignalSkillManagementRuntime: ServerRuntimeRegistration = {
  factory: (context) => {
    const { agentId, serverDB, userId, workspaceId } = context;
    if (!agentId || !userId || !serverDB) {
      throw new Error('agent-signal-skill-management requires agentId, userId and serverDB');
    }

    const service = createResourceRuntimePrimitives({
      agentId,
      db: serverDB,
      memoryReason: (count) =>
        `Agent Signal skill-management memory candidate from ${count} evidence refs.`,
      skillDocumentService: new SkillManagementDocumentService(serverDB, userId, workspaceId),
      userId,
    });

    return new AgentSignalToolExecutionRuntime({
      apiNames: AGENT_SIGNAL_SKILL_MANAGEMENT_TOOL_API_NAMES,
      service,
    });
  },
  identifier: AGENT_SIGNAL_SKILL_MANAGEMENT_IDENTIFIER,
};