Skip to main content

fabricatio-actions

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

Action primitives for the Fabricatio LLM agent framework — file I/O, output persistence, context manipulation, and template-based rendering.


Installation

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

For the full Fabricatio suite:

pip install fabricatio[full]

Overview

fabricatio-actions provides reusable Action subclasses that serve as building blocks in Fabricatio workflow steps. Each action encapsulates a single operation — reading a file, persisting output, gathering context values — and plugs directly into the agent's event-driven pipeline.

Actions integrate with the LLM capability layer (UseLLM) where appropriate, automatically inferring paths and parameters from task context when not explicitly provided.


Actions

File System

Class Description
ReadText Read a file's contents as UTF-8 text. Accepts read_path (str or Path); exposes result under output_key (default "read_text").
DumpText Write text to a file, creating parent directories as needed. Accepts dump_path (str or Path) and text_key naming the context key to write.
SmartReadText Extends ReadText with LLM-assisted path resolution. If read_path is unset, infers it from the task briefing via UseLLM.
SmartDumpText Extends DumpText with LLM-assisted path resolution. If dump_path is unset, infers it from the task briefing.

Output Management

Class Description
DumpFinalizedOutput Serializes a FinalizedDumpAble object to disk. Path may be provided directly, or inferred via LLM from the task briefing.
RenderedDump Renders a FinalizedDumpAble object through a named template (template_name) and writes the result to disk. Uses Fabricatio's built-in template manager.
PersistentAll Iterates the execution context and persists every PersistentAble object into its own subdirectory under persist_dir. Supports single objects and Iterable collections. Set override=True to clear an existing directory first.
RetrieveFromPersistent Loads a PersistentAble object from a file or directory at load_path. Returns a single object for a file, or a list of objects for a directory.
RetrieveFromLatest Loads the most recent PersistentAble object from a directory at load_path. Requires load_path to be a directory.

Context Manipulation

Class Description
GatherAsList Collects context values whose keys match a gather_prefix or gather_suffix into a list. Both fields are optional; at least one must be set.
Forward Copies a value from one context key (original) to another (output_key), enabling value aliasing across workflow steps.

Models

Class Description
FromMapping Abstract base for actions that can be instantiated from a Mapping[str, V]. Implement from_mapping() to return a list of action instances.
FromSequence Abstract base for actions that can be instantiated from a Sequence[V]. Implement from_sequence() to return a list of action instances.

ReadText, DumpText, RetrieveFromLatest, and Forward all implement from_mapping(). Forward additionally implements from_sequence().


Usage

Reading and Writing Files

from fabricatio_actions.actions import ReadText, DumpText

# Read a file
read = ReadText(read_path="input.txt", output_key="content")
content = await read._execute()

# Write text from context
dump = DumpText(dump_path="output.txt", text_key="content")
await dump._execute(content="sample text")

Bulk Instantiation from Mappings

from fabricatio_actions.actions import ReadText, DumpText, Forward

# Create multiple ReadText actions from a mapping
readers = ReadText.from_mapping({
    "config": "config.yaml",
    "prompt": "prompts/main.txt",
})

# Create Forward actions from a mapping or sequence
forwards = Forward.from_mapping({"raw_data": ["data", "payload"]})
chain = Forward.from_sequence(["step1", "step2"], original="input")

LLM-Assisted Path Resolution

SmartReadText and SmartDumpText extend the basic file actions with LLM path inference:

from fabricatio_actions.actions import SmartReadText

smart = SmartReadText(read_path=None)  # path inferred from task briefing
content = await smart._execute(task_input=some_task)

Works the same way for DumpFinalizedOutput and RenderedDump when no explicit path is given.

Persisting and Retrieving Objects

from fabricatio_actions.actions import PersistentAll, RetrieveFromLatest

# Persist all PersistentAble objects from context
persist = PersistentAll(persist_dir="checkpoints/run-42", override=True)
count = await persist._execute(obj_a=model_a, obj_b=model_b)
# -> persists model_a and model_b into checkpoints/run-42/

# Retrieve the latest version
retrieve = RetrieveFromLatest(
    retrieve_cls=MyModel,
    load_path="checkpoints/run-42/",
)
latest = await retrieve._execute()

Template-Based Output

from fabricatio_actions.actions import RenderedDump

dump = RenderedDump(template_name="report.md.jinja", dump_path="report.md")
path = await dump._execute(to_dump=my_finalized_data)

Dependencies

  • fabricatio-core — Core interfaces (Action, Task) and utilities
  • fabricatio-capabilitiesFinalizedDumpAble, PersistentAble interfaces
  • fabricatio-tool — File system utilities (dump_text)

License

MIT — see LICENSE

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fabricatio_actions-0.1.16-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file fabricatio_actions-0.1.16-py3-none-any.whl.

File metadata

  • Download URL: fabricatio_actions-0.1.16-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fabricatio_actions-0.1.16-py3-none-any.whl
Algorithm Hash digest
SHA256 9959071d84f3c844964ed255908ad57dd7f19ce975fdcb4feb0c2525bb9c9bd9
MD5 e0e87497f9d9d9c2b4ac2037802f91a0
BLAKE2b-256 fa35e59ba3a331bb47b22797fea6f4833ce4373411811038ce4111ea00fdc291

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.16 This release

1 file

0.1.15

1 file

0.1.14

1 file

0.1.13

1 file

0.1.12

1 file

0.1.11

1 file

0.1.10

1 file

0.1.9

1 file

0.1.8

1 file

0.1.7

1 file

0.1.6

1 file

0.1.5

1 file

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page