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.

4.7 KB
Raw Blame
import { describe, expect, it } from 'vitest';

import { LobeAgentManifest } from './manifest';
import { MAX_MEDIA_URLS } from './media';
import { LobeAgentApiName } from './types';

describe('LobeAgentManifest', () => {
  it('describes the capabilities the model can discover before activation', () => {
    expect(LobeAgentManifest.meta.avatar).toBe('🤖');
    for (const capability of ['plans', 'todos', 'question', 'media', 'sub-agent']) {
      expect(LobeAgentManifest.meta.description).toContain(capability);
    }
    expect(LobeAgentManifest.meta.readme).toContain(
      'built-in assistant capabilities that can be expanded over time',
    );
  });

  it('should describe multimodal analysis as a fallback tool', () => {
    const apiDescription = LobeAgentManifest.api[0].description;

    expect(apiDescription).toContain('native multimodal capability');
    expect(apiDescription).toContain('use this tool only as a fallback');
    expect(apiDescription).toContain('Provide either refs or urls');
    expect(apiDescription).toContain('Prefer refs when stable refs are available');
    expect(apiDescription).toContain('msg_xxx.image_1');
    expect(apiDescription).toContain('msg_xxx.audio_1');
    expect(apiDescription).toContain('use urls only for direct media URLs');
    expect(apiDescription).toContain('answer the user directly with the result');
  });

  it('should instruct agents to prefer native multimodal access before media analysis', () => {
    expect(LobeAgentManifest.systemRole).toContain('`analyzeMedia` is only a fallback');
    expect(LobeAgentManifest.systemRole).toContain(
      'media is already visible in the current multimodal context',
    );
    expect(LobeAgentManifest.systemRole).toContain(
      'active model lacks the needed audio/image/video capability',
    );
    expect(LobeAgentManifest.systemRole).toContain('media only appears as remote URLs');
  });

  it('should state the media URL cap once, from the runtime constant', () => {
    const { urls } = LobeAgentManifest.api[0].parameters.properties;

    expect(urls.maxItems).toBe(MAX_MEDIA_URLS);
    expect(urls.description).toContain(`at most ${MAX_MEDIA_URLS} per call`);
    // The cap is a limit, not a batching recipe: no guidance to fan out over it.
    expect(urls.description).not.toContain('parallel');
    expect(LobeAgentManifest.systemRole).not.toMatch(/at most \d+ URLs/i);
  });

  it('should allow todos without a plan when the user asks for that', () => {
    expect(LobeAgentManifest.systemRole).toContain('unless the user explicitly asks otherwise');
  });

  it('should route local media through file refs instead of local URLs or base64 text', () => {
    const analyzeMedia = LobeAgentManifest.api[0];
    const { refs, urls } = analyzeMedia.parameters.properties;

    expect(analyzeMedia.description).toContain('local filesystem');
    expect(analyzeMedia.description).toContain('base64 text');
    expect(refs.description).toContain('local file-reading tools');
    expect(urls.description).toContain('Local filesystem paths and file:// URLs are unsupported');
    expect(LobeAgentManifest.systemRole).toContain(
      'Never pass local filesystem paths or `file://` URLs to `analyzeMedia.urls`',
    );
    expect(LobeAgentManifest.systemRole).toContain('stable ref');
  });

  it('should keep media analysis parameters compatible with strict tool schema validators', () => {
    const parameters = LobeAgentManifest.api[0].parameters;

    expect(parameters).not.toHaveProperty('oneOf');
    expect(parameters).not.toHaveProperty('allOf');
    expect(parameters).not.toHaveProperty('anyOf');
  });

  it('should expose a restrained vent API for reporting platform friction', () => {
    const ventApi = LobeAgentManifest.api.find((api) => api.name === LobeAgentApiName.vent);

    expect(ventApi).toBeDefined();
    expect(ventApi!.parameters.required).toEqual(['category', 'severity', 'summary', 'details']);
    expect(Object.keys(ventApi!.parameters.properties)).toEqual([
      'category',
      'severity',
      'summary',
      'details',
      'attempts',
      'toolName',
      'evidenceRefs',
    ]);
    expect(ventApi!.description).toContain('at most one vent per run');
    expect(LobeAgentManifest.systemRole).toContain('<vent>');
  });

  // A run once called vent 133 times as a way to "stop the tool loop".
  it('tells the model that vent is not a way to stop or end a loop', () => {
    const ventApi = LobeAgentManifest.api.find((api) => api.name === LobeAgentApiName.vent);

    expect(ventApi!.description).toContain('It never stops a tool loop or ends your turn');
    expect(LobeAgentManifest.systemRole).toContain('`vent` is never a control action');
    expect(LobeAgentManifest.systemRole).toContain('do not call it again');
  });
});