Skip to main content

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 Command via input() method
    • Iterates through steps (Actions), calling do(context, request) on each
    • Accumulates return values from each step into returned_value dict
    • 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 Error object

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 request
    • rollback() - 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

  1. Create Actions: Instantiate Action subclasses that implement do() and optionally rollback()
  2. Create Container: Container(steps=[action1, action2, ...], name="use case name")
  3. Create Command: Command("name") with request data
  4. Execute: container.input(command) starts the pipeline
  5. Result: Returns accumulated dict of results, or Error on failure

Error Handling & Rollback

  • If any step throws an exception, the Container:
    1. Captures the failure index and reason
    2. Calls rollback() on all steps up to and including the failed step
    3. Returns an Error object with details
  • If rollback itself fails, the error includes failed_rollback information

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

agframe-0.2.3.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

agframe-0.2.3-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file agframe-0.2.3.tar.gz.

File metadata

  • Download URL: agframe-0.2.3.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.12

File hashes

Hashes for agframe-0.2.3.tar.gz
Algorithm Hash digest
SHA256 79732cc7ed5c2982fa6016b448392b6d034fcf03df8393976baf7f2b6d5f5cfb
MD5 d09a164059b14649d8b5e0e4fc2d3fdf
BLAKE2b-256 f3bba1d269dcdc24d1b543925af1e37b59a1b75b8cc1beda93fd1572d464caf4

See more details on using hashes here.

File details

Details for the file agframe-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: agframe-0.2.3-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

Hashes for agframe-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b32fbfc0d4ff9d2f7479e12ef49c7b70588e7ffd415e29584a5baaf423a5015b
MD5 e6adcc13b91c833a4a77b96df44bf033
BLAKE2b-256 c04613a175a8e9a104a322b5923cea03f584c7284c0476de659d4b5cf148f968

See more details on using hashes here.

Supported by

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