This is an playground for AI agents to code within. Constraints are clearly outlined and code is cleary displayed.
Project description
Engine
This codebase implements a Pipeline/Use Case Pattern - a workflow orchestration system that executes a sequence of steps with built-in error handling and rollback capabilities.
Architecture Overview
Command (input) → Container → [Action₁ → Action₂ → Action₃ → ...] → Result/Error
↓ ↓ ↓
Task Task Task
Core Components
1. Container (usecases/container.py)
The main orchestrator/pipeline executor.
- Purpose: Executes a sequence of Actions (steps) in order, passing accumulated results between them
- Key behaviors:
- Receives a
Commandviainput()method - Iterates through
steps(Actions), callingdo(context, request)on each - Accumulates return values from each step into
returned_valuedict - If a key already exists, converts it to a list and appends new values
- On any exception: triggers
rollback()on all previously executed steps - Returns either the accumulated results dict or an
Errorobject
- Receives a
2. Action (actions/action.py)
Base class for individual steps in the pipeline.
- Purpose: Represents a single unit of work in the pipeline
- Interface:
do(context, request)- Execute the action's logic; receives accumulated context and original requestrollback()- Undo the action's effects (called on failure)
- Note: Actions are described as "steps that do things with tasks, like access a file, or make an API request"
3. Command (commands/command.py)
Input wrapper that carries the initial request data.
- Purpose: Encapsulates the request/input data passed into the pipeline
- Interface:
make_request(data)- Sets the request payload
4. Task (tasks/task.py)
Abstract base for actual work units.
- Purpose: Performs the actual operations (API calls, file I/O, etc.)
- Interface:
execute(event, data)- Executes the task logic
5. Error (errors/error.py)
Structured error wrapper.
- Purpose: Wraps error data as a dictionary for consistent error handling
- Contains: failure message, failure reason, and optionally rollback failure info
Execution Flow
- Create Actions: Instantiate Action subclasses that implement
do()and optionallyrollback() - Create Container:
Container(steps=[action1, action2, ...], name="use case name") - Create Command:
Command("name")with request data - Execute:
container.input(command)starts the pipeline - Result: Returns accumulated dict of results, or
Erroron failure
Error Handling & Rollback
- If any step throws an exception, the Container:
- Captures the failure index and reason
- Calls
rollback()on all steps up to and including the failed step - Returns an
Errorobject with details
- If rollback itself fails, the error includes
failed_rollbackinformation
Usage Example
# Define actions
class GetNumber(Action):
def do(self, context, request):
return {"number": 42}
def rollback(self):
pass
# Build pipeline
steps = [GetNumber("step1"), AnotherAction("step2")]
container = Container(steps, "my-use-case")
command = Command("process")
# Execute
result = container.input(command) # Returns {"number": 42, ...} or Error
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agframe-0.2.0.tar.gz.
File metadata
- Download URL: agframe-0.2.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
238c43df4855b4622c027b78514d1631a16afb7237351c62beed0b1f5c1b70f4
|
|
| MD5 |
eaa87418e2c7420de3742b71974456e4
|
|
| BLAKE2b-256 |
6c32ca28ef22e2b35fa7c4f2ef4bf5a7d58c0c850bc97d19195337e3cc457bb5
|
File details
Details for the file agframe-0.2.0-py3-none-any.whl.
File metadata
- Download URL: agframe-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e07891b952564ee576fd25b89a44b3dc58f55f092e4434fa9a4f5b2ba25a627
|
|
| MD5 |
fa5b95c503b805c862480180d91acbe3
|
|
| BLAKE2b-256 |
fdbb3c37c9f3da38e0eb22612f30f299a88e22ce0da48587231c40a2dd77e8cd
|