HyperChat Documentation

repository·dev2·Indexed 20 days ago

https://github.com/bigsweetpotatostudio/hyperchat

HyperChat is an open-source local AI Agent platform using a 'Configuration as Code' approach. It features a dual-mode architecture consisting of a Web Frontend for multi-workspace collaboration and a CLI Frontend for agent-first interaction. The platform supports the Model Context Protocol (MCP), allowing developers to manage AI capabilities, memory, and tools locally. It utilizes an agent-centric model where each agent is a self-contained application with its own configuration (agent.yaml), memory, and toolsets.

Tokens
46.4K
Snippets
163
Records
204
Agent score
72%

What's inside HyperChat

  1. Overview of HyperChat

    dev2

    HyperChat is an open-source chat client designed to provide a high-quality chat experience through two core pillars:

    1. Universal Chat Client: Supports the Model Context Protocol (MCP) and allows users to connect to various LLM (Large Language Model) APIs.
    2. Local Agent & Task System: Implements a local Agent and task system where AI assists in completing specific tasks on the user's machine.
  2. Handle errors and timeouts in TaskQueue

    dev2

    Error Strategies

    Configure how the queue reacts to task failures using errorStrategy:

    • 'stop': Stops the entire queue; all pending tasks are rejected.
    • 'continue': Continues processing other tasks (default).
    • 'retry': Retries the failed task until retryCount is reached.

    Timeout Control

    Set the timeout option (in milliseconds) to automatically reject tasks that run longer than the specified duration.

    // Retry strategy
    const queue = new TaskQueue({
        concurrency: 1,
        errorStrategy: 'retry',
        retryCount: 3
    });
    
    // Timeout control
    const timeoutQueue = new TaskQueue({
        concurrency: 1,
        timeout: 5000 // 5 seconds
    });
    
    try {
        await timeoutQueue.add(async () => {
            await new Promise(resolve => setTimeout(resolve, 10000));
            return 'Done';
        });
    } catch (error) {
        console.log('Task timed out');
    }
  3. Built-in MCP Tool Categories

    dev2

    HyperChat implements an "Everything is MCP" concept, providing four primary categories of built-in MCP tools to enhance Agent capabilities:

    1. Common Tools: Includes web browsing, Google/Bing search, and time retrieval.
    2. Knowledge Base: Allows models to select from available knowledge bases and even add new content to them.
    3. Agent Operations: Supports Call Agent and New Task functionality.
    4. Command Line: A built-in CLI MCP that allows Agents to execute commands or perform SSH operations (designed to simplify the typically difficult installation of CLI-based MCPs).
  4. Understand the Agent-Centric Architecture

    dev2

    HyperChat has transitioned from a 'Workspace-centric' model to an 'Agent-centric' model. In this architecture, the Workspace acts primarily as a discovery path for Agents, while each Agent is a fully self-contained AI application.

    Key Concepts

    • Self-Contained Agents: Every Agent owns its own Model Context Protocol (MCP) tools and task configurations. This makes Agents easy to share, backup, or migrate.
    • Workspace Role: The workspace no longer manages global MCP or tasks; it is responsible for Agent discovery and lifecycle management.
    • Directory Structure: Agent-specific resources are stored within the Agent's own directory under .hyperchat/agents/{agent_name}/.
  5. How HyperChat's dual-mode architecture works

    dev2

    HyperChat 2.0 uses a dual-mode architecture designed for different interaction needs:

    🌐 Web Frontend (Multi-Workspace Collaboration)

    • Focus: Project-level collaboration and unified resource management.
    • Features: Multi-workspace tab management, visual configuration, real-time monitoring, and shared MCP (Model Context Protocol) service pools.
    • Best for: Project development, team collaboration, and visual management.
    • Command: hyperchat serve (accessible at http://localhost:16100).

    💻 CLI Frontend (Agent-First Interaction)

    • Focus: Rapid, centralized interaction with specific AI Agents.
    • Features: Fast startup, Agent-specific memory/context, and on-demand MCP tool loading.
    • Best for: Quick conversations, automation scripts, command-line workflows, and CI/CD integration.
    • Command: hyperchat <command> (e.g., hyperchat "hello").
  6. Configuration file format and technical details

    dev2

    HyperChat settings use the JSONC format, which allows for comments within the configuration files.

    Technical Implementation Details:

    • Validation: Uses Zod for runtime validation to ensure type safety.
    • Schema: Automatically generates JSON Schema files to support editor intelligent completion (IntelliSense).
    • Performance: Settings are saved immediately upon modification, and the settings interface uses lazy loading to minimize re-renders.
  7. Understand the HyperChat dual-layer architecture

    dev2

    HyperChat 2.0 uses a dual-layer architecture to optimize for different usage scenarios:

    1. Web Layer (Workspace-centric): Designed for multi-workspace collaboration. It uses a WorkspaceManager-enhanced to manage multiple workspace instances, provides a unified MCP (Model Context Protocol) service pool at the workspace level, and uses SSE for real-time data synchronization. It is ideal for project-level management and team collaboration.

    2. CLI Layer (Agent-centric): Designed for rapid, agent-first interaction. It allows direct access to Agent instances, bypassing workspace initialization. It features on-demand toolchain loading, independent agent memory/chat history, and is optimized for scripts and automation without UI overhead.

    Configuration follows a 5-level priority merging mechanism (Global + Workspace).

    // Web Layer: Workspace-level MCP management
    const workspace = workspaceManager.get(workspacePath);
    const mcpManager = workspace.getMcpManager();
    const client = mcpManager.getClient(clientName);
    
    // CLI Layer: Agent-first MCP access
    const agentInstance = workspace.getAgentInstance(agentName);
    const client = agentInstance.getMCPClient(clientName);
  8. Understand the HyperChat dual-layer settings system

    dev2

    HyperChat uses a two-tier settings architecture to balance global preferences with project-specific configurations:

    1. App Settings (Global)

      • Scope: Affects the entire application (behavior and appearance).
      • Access: Click the "应用设置" (App Settings) button in the top right of the workspace interface.
      • Storage: AppData/app-settings.jsonc.
    2. Workspace Settings (Local)

      • Scope: Affects only the specific workspace.
      • Access: Right-click the workspace tab or click the three-dot menu (⋮) on the workspace tab and select "工作区设置" (Workspace Settings).
      • Storage: [Workspace]/.hyperchat/settings.jsonc.

    Setting Priority

    Settings are applied in the following order of precedence (highest to lowest): Workspace Settings > App Settings > System Defaults.

    Workspace settings will override any matching keys defined in App Settings.

  9. Core Concepts: The Agent Model in HyperChat

    dev2

    HyperChat is built on the philosophy that an Agent = Intelligence (LLM) + Tool + Memory. The software focuses on creating Agents that can interact with tools and perform tasks.

    Key capabilities include:

    • MCP Tool Support: When adding an Agent, you can select MCP (Model Context Protocol) tools and define them via system prompts.
    • Task Automation: You can add Tasks that trigger an Agent to complete specific work via scheduled messages or via Web API calls.
    • Agent-to-Agent Calls: Agents can call other Agents as tools. For example, a standard model can call a specialized Gemini Think Agent to solve complex reasoning tasks using built-in MCP capabilities.
  10. Workspace settings storage and schema

    dev2

    Workspace settings are persisted locally within each workspace directory.

    • Storage Location: Settings are saved to .hyperchat/settings.jsonc inside the workspace folder. The .jsonc format is used to support JSON with comments.
    • Schema Support: The system automatically generates a settings.schema.json file. If you use a compatible editor, you will receive intelligent autocompletion and validation while editing the settings file directly.
  11. Manage task concurrency and priority

    dev2

    Concurrent Execution

    Set the concurrency option to a value greater than 1 to execute multiple tasks in parallel.

    Task Priority

    When adding a task via .add(task, priority), you can specify a priority level. Lower numerical values indicate higher priority. The queue automatically maintains the execution order based on these values.

    Dynamic Concurrency Adjustment

    You can change the number of concurrent tasks at runtime using .setConcurrency(n) and check the current value with .getConcurrency().

    // Concurrent execution example
    const concurrentQueue = new TaskQueue({ concurrency: 3 });
    const tasks = Array.from({ length: 5 }, (_, i) =>
        concurrentQueue.add(async () => {
            return `Task ${i + 1} complete`;
        })
    );
    const results = await Promise.all(tasks);
    
    // Priority example
    const lowPriorityTask = queue.add(async () => 'low', 10);
    const highPriorityTask = queue.add(async () => 'high', 1);
    
    // Dynamic adjustment
    queue.setConcurrency(4);
    console.log(queue.getConcurrency()); // 4