deer-flow/examples/README.md
Hyeonsang Cho 3d4a9ca09f
fix(examples): keep the extension example's tests passing as the contract grows (#7364)
* fix(examples): keep the extension example's tests passing as the contract grows

The README's package-test commands failed one test on main:
isinstance(registry, ExtensionRegistry) is False because the test's
FakeRegistry does not implement knowledge_provider(), which
extension-api 0.2.7 added to the runtime-checkable protocol. The same
assertion broke earlier when plugin() was added. Nothing in CI runs
these tests, so each addition to the contract broke them silently.

FakeRegistry now records knowledge_provider() and plugin() calls, and
the test asserts the example registers neither, as its README says.
Extension Package Check, which already runs when the contract changes,
now installs each bundled example that has a tests/ directory next to
the checkout's extension-api and runs the README's pytest and ruff
commands. A backend test pins that step and checks that every tested
example declares those tools in its dev extra.

The example README and the extensions guide now count nine
contribution kinds, including knowledge providers.

* docs(changelog): reference #7364 for the extension example test fix

* test(extensions): name the missing package-test step in the wiring pin

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-10-24 11:07:26 +08:00

3.8 KiB

Develop an extension from an existing example

Start with the smallest example that covers your extension. Each directory is an independent Python package using the public deerflow-extension-api contract.

Start here What it demonstrates
Extension example Middleware, task lifecycle, model observations, services, and HTTP routes. Start here for backend extensions.
Conversation bookmarks A browser page, conversation action, backend actions, packaged resources, and a model tool. Start here for full-stack plugins.
Agent teams Full Agent orchestration. Use this after the basic contribution and lifecycle patterns are familiar.

Additional examples cover text-list classification, context pruning, advisory screening of fetched content, and sectioned long-form report writing.

Edit, test, check, then install

  1. Copy the selected example outside the DeerFlow checkout. Rename its Python package, distribution and deerflow.extensions entry point. For a full-stack plugin, also choose its own namespace and browser module name.

  2. Follow the example's README to configure its dependencies and run its tests. Keep package behavior tests alongside the extension. For a bundled example with a tests/ directory, CI installs the package with its dev extra next to this checkout's deerflow-extension-api, then runs pytest, ruff check and ruff format --check.

  3. From the DeerFlow checkout root, prepare the backend environment with make -C backend install, then check the package:

    uv run --project backend --no-sync python scripts/check_extension.py /absolute/path/to/your-extension
    

    To try the checker on an unchanged example:

    uv run --project backend --no-sync python scripts/check_extension.py examples/deerflow-extension-bookmarks
    
  4. Follow that example's deployment and try-it instructions. Restart Gateway, refresh the browser when applicable, and exercise the installed feature. Use make extension-upgrade SOURCE=/absolute/path/to/your-extension to apply later source edits: local installs are snapshots.

What the checker covers

The script builds a wheel in a temporary directory, checks exactly one extension entry point and its packaged Python module, parses packaged Python syntax, and checks that the API dependency range accepts this checkout's contract version. It validates conventional ui_manifest.json resources with the same validator used by Gateway, including detecting manifests left out of the wheel in flat or src/ layouts. A custom manifest filename needs an explicit wheel-relative path:

uv run --project backend --no-sync python scripts/check_extension.py /absolute/path/to/your-extension --manifest your_package/resources.json

The build executes the package's build backend, so check trusted sources. The checker does not import the extension, call install(), install the extension, or change deployment configuration. Registration/configuration behavior and the @extension version marker are verified when loading the plugin; continue to run the package tests and the installed feature after packaging checks pass.