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.

10.0 KB
Raw Blame
/**
 * Heterogeneous-agent descriptor.
 *
 * `getAgentDetail` is called by an orchestrator agent (e.g. LobeAI) to decide
 * whether a target agent is fit for a job β€” typically "can this agent fix a bug
 * in a real codebase?". For a normal model-backed agent the answer lives in
 * `model` / `provider` / `plugins`. For a **heterogeneous** agent (an external
 * CLI/runtime such as Claude Code, CodeBuddy, Codex, Droid, OpenCode, Pi, or Qoder)
 * those fields are misleading: the agent brings its own toolset and ignores
 * the plugin list, so we must instead
 * describe what the external runtime is and what it can do.
 *
 * This module maps a `LobeAgentAgencyConfig` into a compact, LLM-facing runtime
 * descriptor plus a few human-readable lines for the tool `content`.
 */
import type {
  DeviceExecutionTarget,
  HeterogeneousProviderConfig,
  LobeAgentAgencyConfig,
} from '@lobechat/types';

type HeteroType = HeterogeneousProviderConfig['type'];

interface HeteroTypeProfile {
  /** High-level capability tags the orchestrator can reason over. */
  capabilities: string[];
  /** One-paragraph capability summary written for the orchestrator LLM. */
  description: string;
  /** Friendly product name. */
  displayName: string;
  /** Local child-process CLI vs. an agent dispatched to a remote device. */
  kind: 'cli' | 'remote' | 'runtime';
}

const CODING_CAPABILITIES = [
  'filesystem-read',
  'filesystem-write',
  'shell-commands',
  'code-search',
  'multi-step-autonomy',
];

const HETERO_PROFILES: Record<HeteroType, HeteroTypeProfile> = {
  'antigravity': {
    capabilities: CODING_CAPABILITIES,
    description:
      "Antigravity β€” Google's native CLI coding agent (agy). It uses its own signed-in account, models and built-in tools to read and edit files and run permitted commands in a working directory. Command execution follows the user's Antigravity permission policy.",
    displayName: 'Antigravity',
    kind: 'cli',
  },
  'amp': {
    capabilities: CODING_CAPABILITIES,
    description:
      "Amp β€” Sourcegraph's autonomous coding agent. Reads, edits and writes files, runs shell commands and works across a real codebase to complete software-engineering tasks.",
    displayName: 'Amp',
    kind: 'cli',
  },
  'claude-code': {
    capabilities: CODING_CAPABILITIES,
    description:
      "Claude Code β€” Anthropic's autonomous CLI coding agent. It has full access to a working directory: it can read, edit and write files, run shell commands and tests, search the codebase, and carry multi-step software-engineering tasks (bug fixes, feature work, refactors) end to end on its own. It does NOT use the chat `plugins`/`model` settings β€” it runs its own built-in toolset and model.",
    displayName: 'Claude Code',
    kind: 'cli',
  },
  'codebuddy': {
    capabilities: CODING_CAPABILITIES,
    description:
      "CodeBuddy β€” Tencent's autonomous CLI coding agent. It can read, edit and write files, run shell commands and tests, search a working directory, and complete multi-step software-engineering tasks with its own built-in tools and model.",
    displayName: 'CodeBuddy',
    kind: 'cli',
  },
  'codex': {
    capabilities: CODING_CAPABILITIES,
    description:
      "Codex β€” OpenAI's autonomous CLI coding agent. It has full access to a working directory: it can read, edit and write files, run shell commands and tests, and complete multi-step software-engineering tasks autonomously. It does NOT use the chat `plugins`/`model` settings β€” it runs its own built-in toolset and model.",
    displayName: 'Codex',
    kind: 'cli',
  },
  'copilot': {
    capabilities: CODING_CAPABILITIES,
    description:
      "GitHub Copilot β€” GitHub's autonomous CLI coding agent. It can inspect and edit a working directory, run shell commands and tests, search code, and complete multi-step software-engineering tasks through its built-in tools.",
    displayName: 'GitHub Copilot',
    kind: 'cli',
  },
  'cursor': {
    capabilities: CODING_CAPABILITIES,
    description:
      'Cursor β€” an autonomous CLI coding agent with filesystem and shell access that completes software-engineering tasks autonomously.',
    displayName: 'Cursor',
    kind: 'cli',
  },
  'deepseek-harness': {
    capabilities: [...CODING_CAPABILITIES, 'subagents'],
    description:
      'DeepSeek Harness β€” LobeHub’s built-in DeepSeek agent runtime. It can inspect and modify a working directory, run shell commands, use structured tools, and delegate work to subagents without requiring an external CLI installation.',
    displayName: 'DeepSeek Harness',
    kind: 'runtime',
  },
  'droid': {
    capabilities: CODING_CAPABILITIES,
    description:
      "Factory Droid β€” Factory's autonomous coding agent. It can inspect and edit a working directory, run shell commands and tests, search code, and complete multi-step software-engineering tasks through its built-in tools.",
    displayName: 'Factory Droid',
    kind: 'cli',
  },
  'devin': {
    capabilities: CODING_CAPABILITIES,
    description:
      'Devin β€” Cognition’s autonomous local coding agent with filesystem and shell access that completes software-engineering tasks through its own tools and models.',
    displayName: 'Devin',
    kind: 'cli',
  },
  'grok-build': {
    capabilities: CODING_CAPABILITIES,
    description:
      "Grok Build β€” xAI's autonomous coding agent. It can inspect and edit a working directory, run shell commands and tests, search code, and complete multi-step software-engineering tasks through its built-in tools.",
    displayName: 'Grok Build',
    kind: 'cli',
  },
  'hermes': {
    capabilities: CODING_CAPABILITIES,
    description:
      'Hermes β€” a remote autonomous agent runtime that runs on a connected device and can read, edit and write files and run commands in its workspace.',
    displayName: 'Hermes',
    kind: 'remote',
  },
  'kimi-code': {
    capabilities: CODING_CAPABILITIES,
    description:
      'Kimi Code β€” Moonshot AI’s autonomous terminal coding agent with filesystem and shell access.',
    displayName: 'Kimi Code',
    kind: 'cli',
  },
  'opencode': {
    capabilities: CODING_CAPABILITIES,
    description:
      'OpenCode β€” an open-source terminal coding agent with filesystem and shell access that completes software-engineering tasks autonomously.',
    displayName: 'OpenCode',
    kind: 'cli',
  },
  'openclaw': {
    capabilities: CODING_CAPABILITIES,
    description:
      'OpenClaw β€” a remote autonomous agent platform. It runs on a connected device with full filesystem and shell access to its workspace.',
    displayName: 'OpenClaw',
    kind: 'remote',
  },
  'pi': {
    capabilities: CODING_CAPABILITIES,
    description:
      'Pi β€” a minimal, extensible terminal coding agent with filesystem and shell access that completes software-engineering tasks autonomously.',
    displayName: 'Pi',
    kind: 'cli',
  },
  'qoder': {
    capabilities: CODING_CAPABILITIES,
    description:
      'Qoder β€” an autonomous terminal coding agent with filesystem and shell access that completes software-engineering tasks autonomously.',
    displayName: 'Qoder',
    kind: 'cli',
  },
  'trae': {
    capabilities: CODING_CAPABILITIES,
    description:
      'TRAE CLI β€” the TRAE Enterprise coding agent CLI. It can read and edit files, run commands, and complete multi-step software-engineering tasks in a working directory.',
    displayName: 'TRAE CLI',
    kind: 'cli',
  },
};

const EXECUTION_TARGET_DESCRIPTIONS: Record<DeviceExecutionTarget, string> = {
  auto: 'auto-selected online device (one is activated automatically; with several the agent picks one)',
  device: 'a specific device connected via `lh connect`',
  local: "in-process on the user's desktop",
  none: 'no execution environment (plain chat)',
  sandbox: 'a server-spawned cloud sandbox',
};

/**
 * LLM-facing runtime descriptor for a heterogeneous agent. Surfaced in
 * `GetAgentDetailState.config.runtime`.
 */
export interface HeteroAgentRuntimeDescriptor {
  /** Device this agent is bound to, when `executionTarget === 'device'`. */
  boundDeviceId?: string;
  /** High-level capability tags. */
  capabilities: string[];
  /** Human-readable capability summary for the orchestrator. */
  description: string;
  /** Friendly product name (e.g. "Claude Code"). */
  displayName: string;
  /** Where the agent executes. */
  executionTarget?: DeviceExecutionTarget;
  /** External CLI, bundled local runtime, or remote device runtime. */
  kind: 'cli' | 'remote' | 'runtime';
  /** Runtime type identifier (e.g. `claude-code`, `codex`). */
  type: HeteroType;
}

/**
 * Build a runtime descriptor for a heterogeneous agent, or `undefined` when the
 * agent is a normal model-backed chat agent (no `heterogeneousProvider`).
 */
export const describeHeterogeneousAgent = (
  agencyConfig: LobeAgentAgencyConfig | undefined,
): HeteroAgentRuntimeDescriptor | undefined => {
  const provider = agencyConfig?.heterogeneousProvider;
  if (!provider?.type) return undefined;

  const profile = HETERO_PROFILES[provider.type];
  if (!profile) return undefined;

  return {
    boundDeviceId: agencyConfig?.boundDeviceId,
    capabilities: profile.capabilities,
    description: profile.description,
    displayName: profile.displayName,
    executionTarget: agencyConfig?.executionTarget,
    kind: profile.kind,
    type: provider.type,
  };
};

/**
 * Render the runtime descriptor into human-readable lines for the tool
 * `content`. Returns an empty array for non-hetero agents.
 */
export const renderHeteroRuntimeLines = (
  descriptor: HeteroAgentRuntimeDescriptor | undefined,
): string[] => {
  if (!descriptor) return [];

  const lines: string[] = [
    `Runtime: ${descriptor.displayName} (heterogeneous \`${descriptor.type}\` agent β€” ignores the chat model/plugins settings above)`,
    descriptor.description,
  ];

  if (descriptor.executionTarget) {
    const where = EXECUTION_TARGET_DESCRIPTIONS[descriptor.executionTarget];
    lines.push(
      `Runs on: ${where}${
        descriptor.executionTarget === 'device' && descriptor.boundDeviceId
          ? ` (deviceId: ${descriptor.boundDeviceId})`
          : ''
      }`,
    );
  }

  return lines;
};