EchoBot Documentation

repository·main·Indexed 20 days ago

https://github.com/kdaip/echobot

A Live2D-enabled AI assistant featuring a three-layer architecture (Decision, Roleplay, and Agent Core) to separate personality from task execution. EchoBot supports emotional companionship and productivity tasks, integrating with LLM providers, TTS/ASR systems, and chat platforms like QQ and Telegram. It includes a WebUI for managing Live2D models, backgrounds, and routing modes, as well as a skill library featuring Scrapling for web scraping and automation.

Tokens
85.7K
Snippets
224
Records
313
Agent score
69%

What's inside EchoBot

  1. Use the XLSX skill for spreadsheet tasks

    main

    The xlsx skill is triggered when a user's primary goal involves spreadsheet files (.xlsx, .xlsm, .csv, or .tsv).

    Use this skill for:

    • Opening, reading, editing, or fixing existing spreadsheet files.
    • Adding columns, computing formulas, formatting, charting, or cleaning messy data.
    • Creating new spreadsheets from scratch or from other data sources.
    • Converting between tabular file formats.
    • Restructuring malformed tabular data into proper spreadsheets.

    Do NOT trigger this skill when:

    • The primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration.
  2. Querying elements in Scrapling

    main

    Scrapling is designed for parsing HTML pages (XML feeds are not supported due to adaptive feature limitations). There are five primary ways to locate elements within a page:

    1. CSS3 Selectors: Using standard CSS syntax.
    2. XPath Selectors: Using XPath expressions.
    3. Filters/Conditions: Finding elements based on specific logic.
    4. Text Content: Finding elements containing specific text.
    5. Regex: Finding elements whose content matches a regular expression.

    Additionally, Scrapling supports finding elements similar to a given element.

  3. Optimize content extraction and token usage

    main

    To reduce token consumption and improve result quality when using Scrapling tools:

    1. Use css_selector: Always provide a specific CSS selector to narrow down the content before it is returned. This prevents sending unnecessary HTML/text to the LLM.
    2. Enable main_content_only: Keep this set to true (the default) to strip out navigation, footers, and sidebars by restricting extraction to the <body>.
    3. Choose the right extraction_type:
      • "markdown" (Default): Best for readability and LLM processing.
      • "text": Use for minimal output when structure is not needed.
      • "html": Use when the structural hierarchy of the page is critical.
    4. Handle multiple matches: If your css_selector matches multiple elements, the tool returns all of them in the content list.
  4. Manage browser sessions with StealthySession

    main

    To reuse a browser instance, maintain cookies, and keep a consistent fingerprint across multiple requests, use StealthySession (sync) or AsyncStealthySession (async). This is significantly more efficient than launching a new browser for every request.

    Key Features:

    • Browser Reuse: Reuses the same browser instance for subsequent requests.
    • Cookie Persistence: Automatically handles session state and cookies.
    • Rotating Tab Pool: Use the max_pages argument to create a pool of browser tabs. The fetcher will manage opening new tabs up to the limit and closing finished ones, allowing for high-speed parallel fetching within a single browser instance.
    from scrapling.fetchers import StealthySession
    
    # Create a session with a shared configuration
    with StealthySession(
        headless=True,
        real_chrome=True,
        block_webrtc=True,
        solve_cloudflare=True
    ) as session:
        page1 = session.fetch('https://example1.com')
        page2 = session.fetch('https://example2.com') 
  5. Follow shared runtime and coding rules

    main

    When developing for EchoBot, adhere to these architectural constraints:

    • Async Safety: Do not block the event loop. Move blocking file, network, or CPU-heavy work to asyncio.to_thread(...) or an executor.
    • Single Source of Truth: Maintain one source of truth for sessions, tools, skills, route modes, runtime settings, and scheduling. Use echobot/runtime/bootstrap.py to wire features that should exist across multiple entrypoints.
    • Tool Registry: Extend create_basic_tool_registry(...) or the tool-registry factory instead of hand-building tool lists for a single surface.
    • Skill Location: Keep skill behavior inside echobot/skill_support/ and repository-local skills under skills/.
    • JSON Formatting: Use json.dumps(..., ensure_ascii=False) for JSON output.
    • Context Separation: Preserve the separation between user-facing roleplay context and background agent execution context.
  6. Use the News skill for news-related requests

    main

    The news skill is designed to fetch and present the latest headlines from authoritative Chinese and international sources. It should be triggered by requests regarding news, headlines, hot topics, breaking news, or current events. This includes casual phrasing such as:

    • "今天有什么新闻?"
    • "最新科技动态"
    • "财经热点"
    • "体育新闻"
    • "娱乐八卦"
    • "国际新闻"
    • "what's in the news?"
    • "any big stories today?"

    The skill covers various domains including politics, finance, tech, society, world, sports, and entertainment.

  7. When to use Fetcher vs FetcherSession

    main

    Choosing the right tool depends on your scraping requirements:

    FeatureUse FetcherUse FetcherSession
    Use CaseRapid, single requestsMultiple requests to same/different sites
    OverheadMinimalOptimized via connection pooling
    StateNo state (new session per request)Maintains cookies and authentication
    ConfigurationPer-requestCentralized for the whole session
    PerformanceStandardUp to 10x faster for bulk requests

    Note: If you need JavaScript execution or advanced browser automation, you should use other fetchers provided by the library.

  8. Manage sessions with DynamicSession and AsyncDynamicSession

    main

    Use DynamicSession (sync) or AsyncDynamicSession (async) to reuse a browser instance across multiple requests. This provides:

    • Browser reuse: Faster subsequent requests.
    • Cookie persistence: Automatic handling of session state.
    • Consistent fingerprint: Same browser fingerprint across requests.
    • Memory efficiency: Lower resource usage than launching new browsers.

    Rotating Tab Pool: The max_pages argument allows you to create a rotating pool of browser tabs. The fetcher will limit the number of concurrent tabs to max_pages. If the limit is reached, it will wait up to 60 seconds for a tab to finish before raising a TimeoutError.

    # Synchronous Session
    from scrapling.fetchers import DynamicSession
    
    with DynamicSession(
        headless=True,
        disable_resources=True,
        real_chrome=True
    ) as session:
        page1 = session.fetch('https://example1.com')
        page2 = session.fetch('https://example2.com')
    
    # Asynchronous Session with tab pooling
    import asyncio
    from scrapling.fetchers import AsyncDynamicSession
    
    async def scrape_multiple_sites():
        async with AsyncDynamicSession(
            network_idle=True,
            timeout=30000,
            max_pages=3
        ) as session:
            pages = await asyncio.gather(
                session.fetch('https://spa-app1.com'),
                session.fetch('https://spa-app2.com'),
                session.fetch('https://dynamic-content.com')
            )
            return pages
  9. Discover and Use Skills and Role Cards

    main

    EchoBot uses a discovery mechanism for both functional skills and persona definitions.

    Skills Discovery

    SkillRegistry.discover(...) searches in the following order:

    1. Project skills (located in the skills/ directory).
    2. Local managed roots.
    3. Built-in skills.

    Note: Project skills under skills/ will override built-in skills if they share the same name. Skills can be explicitly activated using /skill-name or $skill-name syntax.

    Role Card Discovery

    Role cards (persona definitions) are discovered from:

    1. echobot/roles/ (optional built-in root).
    2. roles/ (project root).
    3. .echobot/roles/ (local managed root).

    If .echobot/roles/default.md is missing, it is created automatically.

  10. Structure a skill directory and SKILL.md

    main

    A skill is organized as a directory containing a required SKILL.md and optional bundled resources.

    Directory Anatomy

    skill-name/
    ├── SKILL.md (required)
    │   ├── YAML frontmatter (name, description required)
    │   └── Markdown instructions
    └── Bundled Resources (optional)
        ├── scripts/    - Executable code for deterministic/repetitive tasks
        ├── references/ - Docs loaded into context as needed
        └── assets/     - Files used in output (templates, icons, fonts)

    Progressive Disclosure (Loading Model)

    To manage context window efficiency, skills follow a three-level loading system:

    1. Metadata (name + description): Always in context (~100 words).
    2. SKILL.md body: In context whenever the skill triggers (<500 lines ideal).
    3. Bundled resources: Loaded only as needed (unlimited size; scripts execute without loading).

    Best Practices

    • Triggering: In the description field, be "pushy" to prevent Claude from "undertriggering". Instead of just describing the task, explicitly list contexts: "Use this skill whenever the user mentions dashboards, data visualization, or internal metrics..."
    • Organization: For multi-domain skills, use a references/ folder with specific files (e.g., aws.md, gcp.md) so Claude only reads the relevant context.
    • Complexity: If SKILL.md approaches 500 lines, introduce a hierarchy and pointers to other files.
    skill-name/
    ├── SKILL.md (required)
    │   ├── YAML frontmatter (name, description required)
    │   └── Markdown instructions
    └── Bundled Resources (optional)
        ├── scripts/    - Executable code for deterministic/repetitive tasks
        ├── references/ - Docs loaded into context as needed
        └── assets/     - Files used in output (templates, icons, fonts)
  11. Key differences between BeautifulSoup and Scrapling

    main

    When choosing between or migrating to Scrapling, keep these architectural differences in mind:

    • Read-Only: BeautifulSoup allows DOM manipulation (modifying/manipulating the parsed tree). Scrapling is read-only and optimized strictly for high-performance extraction.
    • Parsers: BeautifulSoup supports various engines (like html.parser). Scrapling uses lxml exclusively for maximum speed.
    • Element Types: BeautifulSoup uses Tag objects; Scrapling uses Selector objects.
    • Error Handling:
      • Both return None if find() fails to locate an element.
      • page.css() returns an empty Selectors list if no matches are found. To safely get a single element, use page.css('.selector').first to ensure you get None instead of an empty list if nothing matches.
    • Text Processing: Scrapling includes a TextHandler for advanced cleaning, such as clean() to remove extra whitespace or unwanted characters.