Skip to main content

fabricatio-capabilities

MIT Python Versions PyPI Version PyPI Downloads PyPI Downloads Build Tool: uv

High-level LLM agent capabilities for structured extraction, content rating, sequence ordering, text compaction, and task dispatch. Built on fabricatio-core.

Installation

pip install fabricatio[capabilities]
# or
uv pip install fabricatio[capabilities]

For the full Fabricatio suite:

pip install fabricatio[full]

Overview

fabricatio-capabilities provides opinionated, composable mixins that give agents higher-level reasoning abilities:

  • Extract structured data from unstructured text into Pydantic models.
  • Rate content against multi-criteria rubrics, including automated criteria drafting, weighted composite scoring, and top-k selection.
  • Order sequences of items (strings or WithBriefing objects) by a requirement or by computed scores.
  • Compact raw text to a target length (characters, words, or sentences) while preserving its core meaning.
  • Propose & dispatch tasks to candidate roles based on semantic matching.
  • Patch and persist Pydantic models with type-safe update mechanisms.

Every capability is an ABC mixin — subclass alongside your agent's base to compose exactly the abilities you need.

Package Structure

fabricatio_capabilities/
 ├── capabilities/         # Mixin classes
 │   ├── extract.py        # Extract — structured extraction from text
 │   ├── rating.py         # Rating — multi-criteria rating, criteria drafting, composite scoring, best-k selection
 │   ├── rating_image.py   # RatingImage — rate attached images via a vision-capable LLM
 │   ├── compact.py        # Compact + LengthType — length-constrained text compaction
 │   └── task.py           # ProposeTask, DispatchTask — task proposal and delegation
 ├── models/               # Reusable Pydantic base models
 │   ├── generic.py        # Patch, SequencePatch, PersistentAble, FinalizedDumpAble, ModelHash, UpdateFrom, etc.
 │   └── kwargs_types.py   # TypedDict kwargs: CompositeScoreKwargs, OrderStringKwargs, ReferencedKwargs
 └── config.py             # Template name configuration (CapabilitiesConfig)

Key Classes

Capabilities

Class Base Purpose
Extract Propose Extracts one or more Pydantic model instances from a string or list of strings. Uses configurable prompt templates.
Rating Propose Fine-grained rating against a manual and score range. Can draft rating manuals, criteria, and weights (Klee method AHP). Computes composite scores and picks best-k candidates.
Ordering Rating Orders a sequence of strings or WithBriefing items by a natural-language requirement or by computed composite scores.
RatingImage Rating Rates an attached image against criteria via a vision-capable LLM. Routes to the VISION variant slot by default; reuses the bounded-score model builder.
Compact Propose Compacts raw text to at most a target length in characters, words, or sentences (LengthType). compact re-validates the LLM output against the bound (up to three retries); force_compact iteratively re-compacts the output until the bound is met.
ProposeTask Propose Proposes a Task object from a natural-language prompt.
DispatchTask UseLLM Dispatches a Task to the best-matching candidate Role based on briefing text and event subscriptions.

Models

Class Purpose
Patch[T] Type-safe field-level updates to a target Pydantic model. Fields present on the patch are copied onto the target. Supports JSON schema generation with reference-class documentation.
SequencePatch[T] Patch for sequences of objects carrying a tweaked list.
ProposedUpdateAble Combines SketchedAble + UpdateFrom — allows an object to be updated in-place from a proposed replacement.
FinalizedDumpAble JSON serialization with alias support and direct file writing.
PersistentAble Save to / load from a file path with BLAKE3 content hashing and JSON serialization.
ModelHash Consistent __hash__ based on model_dump_json().
UpdateFrom Abstract base for in-place updates with type-checked pre-validation.
AsPrompt Converts a model instance into an LLM prompt string.
WordCount Mixin providing word count tracking for models.

Kwargs Types

CompositeScoreKwargs, BestKwargs, OrderStringKwargs, ReferencedKwargs[T] — TypedDicts that extend ValidateKwargs with capability-specific parameters (topic, criteria, weights, manual, reference).

Configuration

All options below are read through the fabricatio configuration chain (see the Configuration Guide). Set them under the [ext.capabilities] table in fabricatio.toml, equivalently under [tool.fabricatio.ext.capabilities] in pyproject.toml, or via FABRICATIO_EXT__CAPABILITIES__<FIELD_UPPER> environment variables.

[ext.capabilities]
extract_template = "built-in/extract"
as_prompt_template = "built-in/as_prompt"
dispatch_task_template = "built-in/dispatch_task"
rate_fine_grind_template = "built-in/rate_fine_grind"
rate_image_template = "built-in/rate_image"
draft_rating_manual_template = "built-in/draft_rating_manual"
draft_rating_criteria_template = "built-in/draft_rating_criteria"
extract_reasons_from_examples_template = "built-in/extract_reasons_from_examples"
extract_criteria_from_reasons_template = "built-in/extract_criteria_from_reasons"
draft_rating_weights_klee_template = "built-in/draft_rating_weights_klee"
order_string_template = "built-in/order_string"
order_briefed_template = "built-in/order_briefed"
compact_template = "built-in/compact"
Option Type Default Description
extract_template str "built-in/extract" The name of the extract template which will be used to extract model from string.
as_prompt_template str "built-in/as_prompt" The name of the as prompt template which will be used to convert a string to a prompt.
dispatch_task_template str "built-in/dispatch_task" The name of the dispatch task template which will be used to dispatch a task.
rate_fine_grind_template str "built-in/rate_fine_grind" The name of the rate fine grind template which will be used to rate fine grind.
rate_image_template str "built-in/rate_image" The name of the rate image template which will be used to rate an attached image via a vision-capable model.
draft_rating_manual_template str "built-in/draft_rating_manual" The name of the draft rating manual template which will be used to draft rating manual.
draft_rating_criteria_template str "built-in/draft_rating_criteria" The name of the draft rating criteria template which will be used to draft rating criteria.
extract_reasons_from_examples_template str "built-in/extract_reasons_from_examples" The name of the extract reasons from examples template which will be used to extract reasons from examples.
extract_criteria_from_reasons_template str "built-in/extract_criteria_from_reasons" The name of the extract criteria from reasons template which will be used to extract criteria from reasons.
draft_rating_weights_klee_template str "built-in/draft_rating_weights_klee" The name of the draft rating weights klee template which will be used to draft rating weights with Klee method.
order_string_template str "built-in/order_string" The name of the order string template which will be used to order string.
order_briefed_template str "built-in/order_briefed" The name of the order briefed template which will be used to order briefed.
compact_template str "built-in/compact" The name of the compact template which will be used to compact raw text to a target length.

Usage

Structured Extraction

from pydantic import BaseModel
from fabricatio_capabilities.capabilities.extract import Extract

class Person(BaseModel):
    name: str
    age: int

class MyAgent(Extract, YourBaseAgent):
    ...

agent = MyAgent()
person = await agent.extract(Person, "Alice is 30 years old.")
assert person.name == "Alice"

Multi-Criteria Rating

from fabricatio_capabilities.capabilities.rating import Rating

class MyAgent(Rating, YourBaseAgent):
    ...

agent = MyAgent()
manual = await agent.draft_rating_manual("essay quality", {"clarity", "argument"})
scores = await agent.rate("The essay is well-structured.", manual, (0.0, 10.0))

Text Compaction

from fabricatio_capabilities.capabilities.compact import Compact, LengthType

class MyAgent(Compact, YourBaseAgent):
    ...

agent = MyAgent()
compacted = await agent.compact(
    raw,
    requirement="keep the key facts and the formal tone",
    target_length=200,
    length_type=LengthType.Chars,  # Chars (default), Words, or Sentences
)

The output is validated to be at most target_length units (measured after stripping); oversized LLM responses are retried and, after three failed attempts, the method returns None.

When a single pass keeps missing the bound, force_compact feeds each oversized output back as the input of the next pass until the bound is met (max_iterations=5 by default); if the bound stays unreachable it returns the shortest attempt:

compacted = await agent.force_compact(
    raw,
    requirement="keep the key facts and the formal tone",
    target_length=200,
    max_iterations=5,
)

Sequence Ordering

from fabricatio_capabilities.capabilities.order import Ordering

class MyAgent(Ordering, YourBaseAgent):
    ...

agent = MyAgent()
ordered = await agent.order(
    ["clean kitchen", "buy groceries", "pay bills"],
    "by urgency",
)

Task Dispatch

from fabricatio_capabilities.capabilities.task import ProposeTask, DispatchTask

class MyAgent(ProposeTask, DispatchTask, YourBaseAgent):
    ...

agent = MyAgent()
task = await agent.propose_task("Summarize this document.")
result = await agent.dispatch_task(task, candidates={role_a, role_b})

Patching Models

from pydantic import BaseModel
from fabricatio_capabilities.models.generic import Patch

class User(BaseModel):
    name: str
    age: int
    email: str = ""

class UserPatch(Patch[User], BaseModel):
    name: str | None = None
    email: str | None = None

user = User(name="Alice", age=30)
patch = UserPatch(name="Bob")
updated = patch.apply(user)
assert updated.name == "Bob" and updated.age == 30

Dependencies

  • fabricatio-core — core interfaces (Propose, UseLLM, Task, Role, TEMPLATE_MANAGER)
  • orjson — fast JSON serialization
  • pydantic — model validation and schema generation
  • more-itertools — utility iterators

License

MIT — see LICENSE

Metadata

Release files for fabricatio-capabilities 0.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for fabricatio-capabilities 0.6.2
File Interpreter ABI Platform
fabricatio_capabilities-0.6.2-py3-none-any.whl Python 3 none any Details

Release files / fabricatio_capabilities-0.6.2-py3-none-any.whl

Download URL fabricatio_capabilities-0.6.2-py3-none-any.whl
Size 35.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88dbad410da334b068ff68ea01c886a1b9ea15b8db66439d0b87c5bbdf902596
BLAKE2b-256 checksum
How to use checksums
52868aeb471e1cfcef58e0e0d7a728a40d222edc75659871766a14eb66f7360b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.7.0

1 release file

This release

0.6.2 This release

1 release file

0.6.1

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.2

1 release file

0.4.0

1 release file

0.3.9

1 release file

0.3.8

1 release file

0.3.7

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.5

1 release file

0.2.4

8 release files

0.2.3

8 release files

0.2.2

4 release files

0.2.1

4 release files

0.2.0

4 release files

0.1.10

3 release files

0.1.9

3 release files

0.1.8

3 release files

0.1.7

4 release files

0.1.6

4 release files

0.1.5

4 release files

0.1.4

4 release files

0.1.2

4 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page