APFlow: Orchestration That AI Agents Can Discover, Invoke, and Operate¶
A closer look at APFlow's architecture: durable Runs, explicit recovery, shared token budgets, and a common capability contract across MCP, A2A, REST, and CLI.
Consider a research workflow that gathers information from two services, produces a summary, and sends a notification. Getting those steps to run once is straightforward. Operating them raises more questions.
What happens if the client disconnects after submitting the workflow? Which successful results can be reused after a failure? Did a timed-out external request actually complete? How much did all the attempts consume?
APFlow brings those questions into the orchestration model.
APFlow is an open-source Python engine for AI-Perceivable Distributed Orchestration. It coordinates tasks and exposes orchestration capabilities through structured contracts that agents, applications, and people can use.
APFlow puts this approach into practice through durable submission, immutable Run history, selective recovery, and invocation-level usage accounting.
Give agents an operational contract¶
An agent needs a useful description of a capability, its accepted inputs, its outputs, and the rules governing its invocation.
APFlow embeds the apcore module standard to describe and expose those capabilities. Registered modules can be presented through MCP tools, A2A skills, REST endpoints, and CLI commands. Discovery and invocation remain subject to the deployment's authorization and approval policies.
That gives different callers a common operational vocabulary. An agent can submit work through MCP. A service can inspect it through HTTP. An operator can investigate a Run through the CLI.
Each caller still uses its own protocol, while the underlying capability comes from the same registry.
Authenticated service boundaries use verified identity, task ownership, and executor capability checks. Outbound integrations can use server-owned connection profiles and credential references, with public results and diagnostics redacted. These controls give a team concrete places to enforce who may operate a workflow and how it reaches external systems.
For local exploration, the unified server exposes REST, A2A, and MCP in one process:
Its default port is 8000, with REST discovery under /modules, HTTP documentation at /docs, A2A under /a2a, and MCP under /mcp.
Model organization and execution separately¶
A workflow often has both a business structure and an execution order.
The research project might contain a collection stage, an analysis stage, and a delivery stage. Within collection, independent requests can run concurrently. Analysis waits for their results.
APFlow represents these relationships separately:
parent_iddefines the structure tree used for organization, workflow reuse, and progress aggregation.dependenciesdefines the execution DAG used for ordering, parallel scheduling, and result injection.
This separation lets a task belong to a business group while depending on work elsewhere in the tree. A parent-child relationship alone does not impose execution order.
APFlow also supports five creation and reuse modes: Create, Link, Copy, Archive, and Mixed. Teams can build new definitions, reference completed work, make editable clones, freeze completed workflows, or combine copied and linked portions.
Make acceptance durable¶
For background work, submission needs a clear meaning.
APFlow separates definition creation, durable acceptance, and observation. A caller can create a task tree with an idempotency key, recover its creation receipt if the response is lost, and submit the structural root for background execution.
The acceptance record persists before the submission call returns. A dispatcher then executes accepted work. REST and unified servers run that dispatcher during their application lifespan; standalone MCP, A2A, and CLI deployments need a dispatcher connected to the same database.
A successful submission response confirms acceptance. The workflow's persisted state tells the caller whether the work has finished.
That distinction matters when a browser closes or an agent loses its connection. Observation can reconnect to stored state without starting another execution.
Recover with a new Run and preserved history¶
Once accepted, a Run's graph definition and completed result snapshots are frozen. A terminal Run remains a record of what happened.
For recovery, run.retry creates a new Run with new task IDs and explicit lineage to its source. Confirmed completed results can be reused as frozen local snapshots. Optional retry selections determine the starting scope, and APFlow includes affected downstream tasks, required dependencies, and structural ancestors.
The new root must then be submitted or executed explicitly.
For the research workflow, this can preserve confirmed collection results while retrying the failed analysis and the work affected by it. The earlier failure remains available for inspection.
Remote side effects require additional care. A lost response does not establish whether an email, payment, or external update happened. Unknown outcomes require receipt verification and explicit replay authorization. Executor-specific checkpoints can restore supported internal state; replay safety still depends on the external operation's contract.
Account for attempts, including uncertainty¶
APFlow records physical invocations and immutable usage events. Reported consumption from failed attempts remains part of the accounting history.
Shared token scopes add admission control across participating tasks. Before an invocation starts, the ledger considers spent tokens, existing reservations, unknown liabilities, and the requested reservation. Every retry needs its own reservation.
This contract depends on a trusted executor declaring and enforcing a token bound across its provider calls. A scope must be bound to its member tasks. Creating a budget account alone does not govern every operation in the application.
When usage is missing, APFlow retains the outstanding liability until it can be reconciled with evidence. That preserves the distinction between a confirmed zero and an unknown amount.
Applications can consume usage events with acknowledgement and deduplication. Pricing, credits, refunds, and wallets remain application responsibilities.
Put the records to work¶
For an individual developer, a useful first project is a personal research digest: collect sources, generate an analysis through your chosen model integration, and inspect the results. Start with a small graph and examine what happens when one source fails.
For a technical team, evaluate a document-processing pipeline: extraction, validation, analysis, and a reviewed delivery step. Submission receipts help locate failed handoffs. Run lineage preserves the evidence needed for incident investigation. Shared token scopes give participating calls a common admission budget, and usage events can feed internal reporting.
These are example evaluation scenarios. Their business value depends on the integrations, policies, and operating process the team implements.
Start small, choose the deployment you need¶
APFlow supports SQLite for local operation and PostgreSQL for distributed workers, with leader election, task leasing, and worker management. Its scheduler creates fresh instances for recurring executions, keeping their outcomes separate.
Executors can contain ordinary business logic, HTTP calls, or integrations with an existing agent system. A function decorator provides a small entry point for custom Python capabilities.
The project remains classified as Alpha. Evaluate its contracts against a representative workflow, especially where external side effects and provider usage are involved.
Start with a workflow you can inspect end to end: create it, submit it, observe it, induce a failure, and examine the resulting Run and usage history.
Explore the APFlow repository, the documentation, and the current submission and recovery guide. Try one representative workflow, share what you learn in an issue, and star the repository to follow its development.
Comments
Join the discussion via GitHub Discussions.