Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Mate] Add Knowledge bridge to crawl official documentation#2069

Draft
wachterjohannes wants to merge 1 commit into
symfony:mainfrom
wachterjohannes:feature/mate-knowledge-bridge
Draft

[Mate] Add Knowledge bridge to crawl official documentation#2069
wachterjohannes wants to merge 1 commit into
symfony:mainfrom
wachterjohannes:feature/mate-knowledge-bridge

Conversation

@wachterjohannes
Copy link
Copy Markdown
Contributor

Q A
Bug fix? no
New feature? yes
Docs? yes
Issues -
License MIT

Summary

Introduces a new Mate bridge — symfony/ai-knowledge-mate-extension — that exposes pluggable documentation providers as MCP tools so agents can crawl official docs structurally instead of guessing from training data.

The Symfony bridge ships a built-in SymfonyDocsProvider for symfony/symfony-docs that registers itself when the Knowledge bridge is also installed (interface_exists() guard).

Tools

Tool Purpose
knowledge-toc Without arguments: list providers. With a provider: browse its TOC at path (or root).
knowledge-read Read a documentation page split into RST sections.
knowledge-search Case-insensitive substring search across a provider's chunks.

Behavior

  • The first call for a provider clones the source repo (git clone --depth 1) into the local cache.
  • Subsequent calls hit the cache.
  • The cache auto-refreshes once it's older than ai_mate_knowledge.cache_ttl_seconds (default 24h).
  • Section-based chunking reuses Symfony\AI\Store\Document\Loader\RstLoader so chunking semantics stay aligned with the Store component.

Adding a custom provider

use Symfony\AI\Mate\Bridge\Knowledge\Provider\DocsProviderInterface;
use Symfony\AI\Mate\Bridge\Knowledge\Service\GitFetcher;

final class MyDocsProvider implements DocsProviderInterface
{
    public function __construct(private GitFetcher $fetcher) {}

    public function getName(): string { return 'my-docs'; }
    public function getTitle(): string { return 'My Docs'; }
    public function getDescription(): string { return 'My project documentation'; }
    public function getFormat(): string { return 'rst'; }

    public function sync(string \$cacheDir): string
    {
        \$repo = \$cacheDir.'/docs';
        \$this->fetcher->fetch('https://github.com/me/docs.git', 'main', \$repo);

        return \$repo.'/index.rst';
    }
}

Tag the service ai_mate.knowledge_provider.

Future-proofing

The chunk model (PageChunk) already matches what Symfony\AI\Store\Document\Vectorizer consumes, so a future vector-search bridge would only need to extract a small SearcherInterface from KeywordSearcher and an IndexerInterface from the JSON cache step. Not done now to keep the scope focused (YAGNI).

Test plan

  • Knowledge bridge: 23/23 PHPUnit tests pass (services, models, registry, tools, TTL behavior)
  • Symfony bridge: 114/114 existing tests still pass after my edits
  • PHPStan clean on Knowledge bridge
  • doctor-rst clean on docs change
  • End-to-end: install both bridges in a real project, run bin/mate mcp:tools:call knowledge-toc '{}' then '{"provider":"symfony"}'

Introduces a new Mate bridge (`symfony/ai-knowledge-mate-extension`) that
exposes pluggable documentation providers as MCP tools so agents can
crawl official docs structurally instead of guessing from training data.

Tools shipped:

 * `knowledge-toc` — without args lists registered providers; with a
   provider browses its TOC at the given path
 * `knowledge-read` — reads a documentation page split into RST sections
 * `knowledge-search` — case-insensitive substring search across a
   provider's chunks

Providers implement `DocsProviderInterface` and register as services
tagged `ai_mate.knowledge_provider`. The first call clones the source
repository (via `git clone --depth 1`) into the local Mate cache; the
cache is auto-refreshed once it is older than
`ai_mate_knowledge.cache_ttl_seconds` (default 24h).

Section-based chunking reuses `Symfony\AI\Store\Document\Loader\RstLoader`
so chunking semantics stay aligned with the Store component.

The Symfony bridge ships a built-in `SymfonyDocsProvider` for
https://github.com/symfony/symfony-docs that registers itself when the
Knowledge bridge is also installed (guarded via `interface_exists()`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant