Afnio Main Components#
Afnio is a flexible and powerful library for building, training, and optimizing LM‑driven agents and end‑to‑end workflows. This page summarizes the core concepts of the framework.
Core concepts#
Variable — a first‑class, tunable object that holds prompt fragments, numeric hyperparameters, or small structured inputs used to fill prompt templates. Variables carry metadata (role, constraints, requires_grad, etc.) and can be optimized by Afnio’s optimizers. Use Variables to rewrite or tune prompt templates, tune hyperparameters, or represent compact datasets to use for tuning.
Autodiff - Afnio’s automatic differentiation engine that tracks operations performed on variables and builds a computational graph dynamically to be able to compute textual gradients for semantic feedback to each node of the graph.
Cognitive API — a modular, functional framework for composing LM‑based modules (chat completions, split/merge helpers, LM‑as‑judge, evaluators) into agents and end‑to‑end workflows. It provides standardized response formats, built‑in metrics, loss functions and validators so modules can be composed, reused and connected to Afnio’s optimizers and Autodiff. The
cog.Modulebase class defines theforward,training_step,validation_stepandtest_stepmethods plus parameter‑management hooks to integrate custom architectures into optimization loops.DataLoaders — utilities for preparing and iterating over datasets used in training, validation, and testing. DataLoaders support batching, shuffling, sampling (including weighted samplers for class imbalance), deterministic seeding, and integration with Afnio evaluation helpers so data flows seamlessly into training, validation, and testing loops.
Trainer — orchestrates training, validation and testing of Afnio agents. The Trainer handles epoch loops, checkpointing, metric collection, and integration with model clients (LMs) and optimizers. Use the Trainer to run experiments, compare checkpoints, and produce the metrics used to guide prompt/hyperparameter optimization.