Flows: Building Blocks of Reasoning and Collaborating AI

Martin Josifoski, Lars Klein, Maxime Peyrard, Yifei Li, Saibo Geng, Julian Paul Schnitzler, Yuxing Yao, Jiheng Wei, Debjit Paul, Robert West · OpenReview

Abstract

Recent advances in artificial intelligence (AI) have produced highly capable and controllable systems. This creates unprecedented opportunities for structured reasoning as well as collaboration among multiple AI systems and humans. To fully realize this potential, it is essential to develop a principled way of designing and studying such structured interactions. For this purpose, we introduce the conceptual framework of Flows: a systematic approach to modeling complex interactions. Flows are self-contained building blocks of computation, with an isolated state, communicating through a standardized message-based interface. This modular design allows Flows to be recursively composed into arbitrarily nested interactions, with a substantial reduction of complexity. Crucially, any interaction can be implemented using this framework, including prior work on AI–AI and human–AI interactions, prompt engineering schemes, and tool augmentation. We demonstrate the potential of Flows on the task of competitive coding, a challenging task on which even GPT-4 struggles. Our results suggest that structured reasoning and collaboration substantially improve generalization, with AI-only Flows adding +21 and human–AI Flows adding +54 absolute points in terms of solve rate. To support rapid and rigorous research, we introduce the aiFlows library. The library comes with a repository of Flows that can be easily used, extended, and composed into novel, more complex Flows.

Introduction

While Large Language Models (LLMs) like GPT-4 exhibit remarkable capabilities, they often struggle with complex, multi-step reasoning and the effective use of external tools in a "one-shot" manner. Current approaches to managing these complexities often rely on ad-hoc abstractions that lack a principled foundation, making them difficult to scale or adapt. This paper introduces Flows, a conceptual framework and Python library (aiFlows) designed to treat AI interactions as modular, recursive building blocks. By structuring LLM reasoning into isolated, message-passing units, we demonstrate that structured interaction can significantly enhance performance on challenging tasks.

The Flows Framework

The core contribution of this work is the Flow abstraction, inspired by the Actor model of concurrent computation. A "Flow" is a self-contained unit of computation with its own isolated state, communicating with other Flows exclusively through standardized messages.

Overview of the Flows framework, showing the hierarchy from basic tools to complex composite interactions.

Flows are categorized into two types:

  • Atomic Flows: These serve as wrappers around fundamental tools, specific LLM prompts (e.g., GPT-4 with a few-shot prompt), or human inputs.
  • Composite Flows: These orchestrate interactions between multiple sub-Flows. Because Composite Flows adhere to the same message-based interface as Atomic Flows, they can be nested recursively to build systems of arbitrary complexity.

This modularity allows for "agnostic" design; for instance, a "Code Generator" Flow does not need to know whether its "Planner" sub-Flow is an AI agent or a human. This decoupling simplifies the design of complex multi-agent and human-AI systems.

Experimental Evaluation: Competitive Coding

To evaluate the framework, we focused on Competitive Coding (CC), a task requiring rigorous logic and implementation skills. We utilized problems from platforms like Codeforces and LeetCode. A critical aspect of our methodology was temporal analysis. We split the dataset into problems released before and after GPT-4's training cutoff (September 2021) to distinguish between genuine reasoning and memorization (data contamination).

Key Results

Our experiments compared various Flow configurations against a baseline of GPT-4 performing direct zero-shot inference. The results highlight the power of structured reasoning and collaboration.

Problem solve rate over time, demonstrating the performance of different Flow configurations compared to a baseline.
  • AI-Only Collaboration: Implementing a "Code-Debug-Collab" Flow—where one LLM generates code and another provides feedback based on execution results—increased the solve rate by +21 absolute points on novel problems.
  • Human-AI Synergy: Replacing the AI-generated plan with a human-provided strategy (an "Oracle Plan") resulted in a massive +54 absolute point increase, bringing the solve rate from ~27% to over 80%.
  • Generalization: While baseline performance dropped significantly on post-cutoff problems, the structured Flows mitigated this decline, suggesting that structured interaction is a key driver for generalization in novel scenarios.

Discussion and Conclusion

The Flows framework demonstrates that how models interact can be as important as the models themselves. Modularity enables the creation of "grounded" feedback loops, where AI-generated content is verified against real-world execution (e.g., compiler errors), which we found to be far more effective than ungrounded self-reflection.

Future work will address the trade-offs between the cost of multiple API calls and performance gains, as well as exploring asynchronous execution for truly concurrent multi-agent systems. The aiFlows library and the "FlowVerse" repository provide a foundation for the research community to share and build upon these interaction patterns.

Summary updated

BibTeX
@misc{josifoski2023flows,
  author = {Martin Josifoski and Lars Klein and Maxime Peyrard and Yifei Li and Saibo Geng and Julian Paul Schnitzler and Yuxing Yao and Jiheng Wei and Debjit Paul and Robert West},
  title = {{Flows: Building Blocks of Reasoning and Collaborating AI}},
  year = {2023},
  eprint = {2308.01285},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2308.01285},
}
Figure