In this section
On this page

This tutorial takes a cartridge through the local development loop: scaffold, build when necessary, install, run, change, and reinstall. The generated sentiment-tagger owns a small domain capability and delegates the actual classification to the published classify-en capability.

Prerequisites

You need:

  • the capdag CLI on PATH;
  • the toolchain for the language you choose;
  • a locally installed model cartridge that provides classify-en; and
  • network access on the first model run if that cartridge must download its model.

For Python, install Python 3.11 or newer and the cartridge runtime:

python3 -m pip install capdag

The scaffolded Python entry uses #!/usr/bin/env python3. The python3 found on PATH must therefore be able to import capdag.

1. Create the project

capdag dev new sentiment-tagger --lang python
cd sentiment-tagger

--lang rust, --lang go, and --lang swift produce equivalent projects for those cartridge runtimes. The generated README gives the language-specific build command.

The Python project contains:

sentiment-tagger/
  cartridge.py
  README.md
  .gitignore

The generated entry:

  1. Defines the project-specific input and output media URNs.
  2. Builds one custom Cap URN and advertises it alongside the mandatory identity cap.
  3. Registers a TagOp handler for the canonical Cap URN string.
  4. Calls classify-en with the input text and the closed label set positive,neutral,negative.
  5. Forwards the peer’s progress and emits the returned label.

The generated media URNs include the project name, so an unpublished dev cap does not accidentally reuse a published type:

media:enc=utf8;sentiment-tagger-input
media:enc=utf8;sentiment-tagger-tag

The custom capability has the canonical form:

cap:in="media:enc=utf8;sentiment-tagger-input";language=en;out="media:enc=utf8;sentiment-tagger-tag";sentiment-tagger

language=en says the cap judges English text only, because classify-en does. The cap also lists that tag in its dims, as {"dim": "language", "value": "en"}: the fabric dim the tag comes from and the value chosen from it. Dims describe a cap; dispatch never reads them.

Treat tagged URNs as opaque values. The scaffold constructs the Cap URN with CapUrnBuilder and reuses its canonical string for registration; do not reconstruct that string in handler code.

Inspect the manifest before installation:

./cartridge.py manifest | python3 -m json.tool

For a compiled language, run its build command first and inspect the generated binary’s manifest subcommand instead.

2. Install the development cartridge

capdag dev install

For Rust, Go, and Swift, build the generated binary before this command. dev install reads the manifest, checks its aliases against the fabric, and stages the project under:

~/.capdag/cartridges/dev/v{registry-version}/nightly/sentiment-tagger/0.1.0/

The dev slug is reserved for manifests whose registry_url is null. Reinstalling the same version replaces that development installation.

A dev cap may introduce an alias absent from the fabric. It may not claim an alias that the fabric already maps to a different capability. Rename a colliding alias before continuing.

3. Run the capability

echo "I love this" | capdag run sentiment-tagger

Run the entry through the capdag host. Invoking it directly cannot satisfy its peer call and fails with Peer invocation not supported in this context.

On success, stdout contains one of the three labels. Model download and inference progress appear through the normal progress channel. If no installed cartridge provides classify-en, the peer call fails; the scaffold has no fallback classifier.

4. Change and reinstall it

Open the generated source and change the label set, capability metadata, or peer capability. Then rebuild if needed and reinstall:

capdag dev install
echo "I love this" | capdag run sentiment-tagger

That is the development loop: edit, build when required, dev install, and run. Bump the manifest version to install a new version alongside the old one; otherwise dev install updates the current version directory.

Add another capability

Each additional capability needs:

  1. a Cap in the manifest, with distinct media and operation tags;
  2. an Op implementation; and
  3. a registration that uses the exact canonical Cap URN string advertised by the manifest.

The runtime creates the registered handler for each request and dispatches by the request Cap URN.

Publish the cartridge

Local definitions become registry definitions when the capability is ready for other users. Propose new Cap and Media URNs to capfab, and propose the cartridge to cartridge-shelf. A published manifest records its registry’s anchor and installs in the folder the registry’s charter names instead of dev.

Troubleshoot the development loop

  • Alias conflict: rename an alias that the fabric already assigns to a different Cap URN.
  • No local provider: rerun capdag dev install and verify that the alias matches the manifest.
  • Manifest command fails: make the entry executable and ensure its runtime dependencies are available to the interpreter or binary.
  • NoHandlerError: build the Cap URN once and use the same canonical string in both the manifest and handler registration.
  • Peer invocation fails: install a compatible model cartridge that provides classify-en, then run the development cap through the host rather than its entry directly.

See CapDAG CLI reference for command and option details.