Source-linked AI summary

Language Agents as Optimizable Graphs

Mingchen Zhuge, Wenyi Wang, Louis Kirsch, Francesco Faccio, Dmitrii Khizbullin, Jürgen Schmidhuber

arXiv:2402.16823v3cs.AIcs.CLcs.LGcs.MA

TL;DR

LLM-agent research has produced many disparate prompt-engineering systems and code bases, motivating a unified representation. GPTSwarm models agents as computational graphs and optimizes both node prompts and graph connectivity; experiments demonstrate advantages across several benchmarks. Its evaluation is limited to a single graph distribution because API calls are costly.

  • Problem

    Existing LLM-agent methods use varied prompting schemes and increasingly disparate code bases, making cohesive and automatic improvement an open problem.

    Source: §1 · p. 1
  • Method

    GPTSwarm constructs language agents from graphs and agent societies from graph compositions, then applies node-level prompt improvement and edge-level REINFORCE optimization.

    Source: §1 · p. 1, §2.4 · p. 4, §5 · p. 9
  • Results

    Experiments demonstrate advantages of language-agent graphs and automatic optimization on several benchmarks, including MMLU, Mini CrossWords, HumanEval, and GAIA.

    Source: §1 · p. 2, §5 · p. 9
  • Takeaways & Limitations

    The framework supports constructing, integrating, and automatically improving diverse LLM agents through a shared graph-based representation.

    Source: §1 · pp. 1–2, §5 · p. 9

    The evaluation is limited to a single graph distribution because API calls for this type of evaluation are costly.

    Source: §3.3 · p. 6

Abstract

from arXiv · show

Various human-designed prompt engineering techniques have been proposed to improve problem solvers based on Large Language Models (LLMs), yielding many disparate code bases. We unify these approaches by describing LLM-based agents as computational graphs. The nodes implement functions to process multimodal data or query LLMs, and the edges describe the information flow between operations. Graphs can be recursively combined into larger composite graphs representing hierarchies of inter-agent collaboration (where edges connect operations of different agents). Our novel automatic graph optimizers (1) refine node-level LLM prompts (node optimization) and (2) improve agent orchestration by changing graph connectivity (edge optimization). Experiments demonstrate that our framework can be used to efficiently develop, integrate, and automatically improve various LLM agents. The code can be found at https://github.com/metauto-ai/gptswarm.

1. Introduction

GPTSwarm unifies diverse language-agent systems as optimizable computational graphs, then improves both node prompts and inter-agent orchestration. The framework represents individual agents and societies of agents hierarchically and validates automatic graph optimization across several benchmarks.

1. Introduction

  • GPTSwarm unifies language-agent systems by representing operations as graph nodes and information flow or communication as edges, with composite graphs modeling collaborating agents.The framework can express prompting approaches such as COT, TOT, and Self-Consistency as graphs.Source: §1 · p. 1, Figure 1 · p. 2
  • Graph connectivity can self-improve online during task solving or when transferring a solution to another task.This enables the system to search for improved communication patterns among agents rather than relying only on fixed orchestration.Source: §1 · p. 2
  • Automatic optimization improves both node-level prompts and edge-level communication or orchestration patterns.Node prompts can adapt from prior inputs and task feedback, while graph connectivity can be optimized through prompting, evolutionary methods, or reinforcement learning.Source: §1 · pp. 1–2
  • The graph abstraction addresses disparate agent code bases by providing a common framework for constructing arbitrary systems from recombined fundamental operations.Prior multi-agent systems often required substantial human engineering to define prompting schemes and workflows.Source: §1 · pp. 1–2
  • GPTSwarm validates its graph construction and automatic optimization framework on MMLU, Mini CrossWords, HumanEval, and GAIA.The stated emphasis is on the benefits of automatic graph optimization across these benchmarks.Source: §1 · p. 2

2. GPTSwarm

GPTSwarm represents language agents and multi-agent swarms as directed computational graphs, then optimizes node prompts and inter-agent edges to improve task utility. Its framework supports modular composition, graph-based orchestration, and automatic optimization across diverse agent systems.

2.1. Language Agents as Graphs

  • Language agents are graphs of functional nodes connected by execution edges, while swarms compose agent graphs with additional communication edges into a larger DAG.Nodes may query LLMs, use tools, call functions, or perform embodied actions; within-agent edges define execution, and cross-agent edges define collaboration.Source: §2.1 · p. 2, §2.2 · p. 3

2.2. Graph Definition

  • A graph executes nodes in topological order, passing each node the task input and predecessor outputs, with the output node producing the task solution.Nodes without predecessors receive empty context, and routines may ignore the shared input when operating only on predecessor context.Source: §2.2 · pp. 2–3

2.3. Edge Optimization

  • Edge optimization selects an acyclic pattern of inter-agent connections that maximizes a task-specific utility over the resulting composite graph.Potential edges form a binary configuration space, restricted to composite graphs that remain DAGs.Source: §2.3 · p. 3

2.3.1. PROBLEM REFORMULATION

  • Because graph utilities are typically nondifferentiable and DAG choices are combinatorial, the method optimizes a parameterized distribution over feasible DAGs instead of directly searching discrete graphs.The distribution parameters define probabilities over candidate edges while preserving acyclicity.Source: §2.3.1 · p. 3

2.3.2. SOLUTION PARAMETERIZATION

  • Candidate DAGs are sampled by considering potential edges sequentially, adding each with its parameterized probability unless doing so would create a cycle.The construction begins with required nodes and edges and rejects cycle-forming additions.Source: §2.3.2 · pp. 3–4

2.3.3. OPTIMIZATION ALGORITHM

  • REINFORCE estimates the gradient of expected graph utility from sampled DAGs and updates the distribution parameters with gradient ascent.The estimator uses independently sampled graphs and unbiased utility estimates, with Algorithm 2 implementing iterative parameter updates.Source: §2.3.3 · p. 4

2.4. Node Optimization

  • Node optimization improves each node’s prompt using its function description and execution history while holding the graph structure and other prompts fixed during each update.Each history records node inputs, predecessor context, and outputs; an improver then maps that history, the current prompt, and its description to an updated prompt.Source: §2.4 · p. 4

2.5. General Applicability

  • GPTSwarm emphasizes reusable modular components, supporting capabilities such as file analysis, web search, and index-based memory within composable agent systems.The framework is presented as applicable to varied language-agent systems through recombinable nodes and agents.Source: §2.5 · pp. 4–5

3. Experiments

Across MMLU, Mini Crosswords, HumanEval, and GAIA, graph optimization improves agent performance by learning orchestration, prompts, or modular tool use. The experiments also show that gains depend on agent diversity, graph structure, and computational resources.

3.1.2. COLLABORATIVE SETTING

  • 2.1% ± 1.1% improvement over the single-agent baseline emerged when seven role-diverse IO agents were combined with adversarial agents and optimized over five seeds.Identically prompted IO agents produced no improvement over the single-agent baseline, motivating role diversity in the collaborative setting.Source: §3.1.2 · p. 5

3.2. Mini Crosswords

  • On Mini Crosswords, edge probabilities changed chaotically early in optimization but became almost monotonic after iteration 6.The composite graph was optimized with REINFORCE using an initial edge probability of 10%, learning rate 0.4, and 20 sampled graphs per iteration.Source: Figure 3 · p. 6, §3.2 · p. 6
  • 0.575(±0.0275) average accuracy after ten Mini Crosswords optimization iterations exceeded the initial distribution’s 0.465(±0.0509).A distribution with a similar expected edge count achieved 0.510(±0.0552), indicating that the gain was not explained by edge density alone.Source: §3.2 · p. 6
  • 0.800(±0.0616) accuracy with GPT-4-Turbo exceeded Tree of Thought with GPT-4 at 0.675 on Mini Crosswords.The same optimized distribution scored 0.668 when Tree of Thought was implemented with GPT-4-Turbo.Source: §3.2 · p. 6, Figure 4 · p. 6

3.3. HumanEval

  • 0.88(±0.007) HumanEval accuracy improved over 0.76 without optimization in online learning, with most gains occurring during the first five iterations.The node optimizer adds effective input-output demonstrations to prompts for a ReAct-style coding agent.Source: §3.3 · p. 7, Figure 5 · p. 7

3.4. GAIA

  • GAIA performance significantly outperformed GPT-Series with plugins and AutoGPT baselines across several difficulty levels.The reported swarm used seven Tree of Thought agents with prompt-based self-consistency; Table 1 reports means and standard deviations across five runs.Source: §3.4 · p. 7, Table 1 · p. 7
  • GAIA swarms improved as agent count and node-operation variety increased, while runtime grew approximately linearly with the number of agents.Web browsing was required for 43.9% of tasks, but the implementation only downloaded provided URLs or queried Google without further navigation; these experiments used no graph optimization.Source: §3.4 · pp. 7–8

4. Related Work

Prior work improves language agents through prompting, communication structures, and multi-agent frameworks, but GPTSwarm distinguishes itself by modeling agents as optimizable graphs and learning both prompts and inter-agent connectivity.

4.1. LLM-based Autonomous Agents

  • LLM agent research spans structured prompting methods, single-agent tool frameworks, and multi-agent systems with varied communication or role-based structures.Examples include Chain of Thought, ReAct, Reflexion, Tree of Thought, AutoGPT, LangChain, CAMEL, ChatDev, and AutoGen.Source: §4.1 · p. 8

4.2. Language Agents with Graphs

  • GPTSwarm represents language agents as graphs that can compose hierarchically into swarms, extending graph-based prompting to external tools and agent collaboration.Nodes can represent prompting or other agent capabilities, while graph composition supports societies of agents.Source: §4.2 · p. 8
  • Unlike approaches that describe components additively or use fixed collaboration schemes, GPTSwarm focuses on automatically optimizing agent nodes and edges for orchestration and routing.The framework applies prompt optimization at nodes and REINFORCE to potential edges between agents.Source: §4.2 · p. 8, §4.1 · p. 8

4.3. Optimizing LLM Inference and Self-Improvement

  • Prompt and inference-structure optimization can be viewed as meta-learning because LLM prompting configures the effective inference procedure.Related methods include OPRO, PromptBreeder, DSPy, DyLAN, and STOP; GPTSwarm uses iterative node optimization and reinforcement learning over graph edges.Source: §4.3 · p. 9
  • GPTSwarm addresses DSPy’s combinatorial optimization challenge by improving each node iteratively according to graph execution history and current prompts.This decomposes optimization across nodes rather than searching the Cartesian product of candidate solutions for the whole graph.Source: §4.3 · p. 9

5. Conclusion

GPTSwarm is an open-source framework for constructing language agents and agent societies from graph compositions, with automatic optimization at both node and edge levels. Experiments report benefits on several benchmarks.

  • GPTSwarm constructs language agents from computational graphs and agent societies from graph compositions, enabling node-level prompt improvement and edge-level REINFORCE optimization.The framework supports implementation of existing methods from basic node operations and evaluates automatic optimization across several benchmarks.Source: §5 · p. 9

Impact Statement

The paper presents GPTSwarm as a modular framework for composing and optimizing language-agent graphs, with a vision aimed at improving integration and routing as swarms scale.

Impact Statement

  • The impact statement identifies potential benefits in machine-learning efficiency and effectiveness alongside ethical, employment, bias, misuse, and oversight concerns from more autonomous LLM agents.The authors call for safeguards and ethical guidelines as these systems become more capable and automated.Source: Impact Statement · p. 9

A.1. The Vision

  • GPTSwarm frames component integration as graph connectivity and uses edge optimization to learn agent orchestration and routing, especially as swarm size increases.The vision contrasts this with additive descriptions that list capabilities without specifying how components interact.Source: §A.1 · p. 13

A.2. Class Diagram

  • GPTSwarm’s class structure separates graph objects, agent and operation types, LLM interfaces, dataset integration, prompt sets, and evaluation of node and edge optimization.The framework includes classes such as DirectAnswer, WebSearch, IO, TOT, Dataset, PromptSet, and Evaluator.Source: §A.2 · p. 13
  • The implementation is extensible through additional LLM backends, datasets, prompt sets, agents, and nodes, and uses asynchronous computation for task parallelism.These design choices support customization of the framework beyond its included components.Source: §A.2 · p. 13

B. Swarm examples

  • The supplementary examples illustrate a swarm combining Tree-of-Thought, Input-Output, and Decision agents, alongside visualizations of other agents and swarms.Figure 8 shows the three-agent example, while Figures 7 and 9 provide framework and agent-system visualizations.Source: Figure 7 · p. 14, B. Swarm examples · p. 15, Figure 8 · p. 15

D.1. Comparing Our Method with Multiagent Debate and DYLAN on MMLU

On MMLU with truthful and adversarial agents, GPTSwarm is compared with Multiagent Debate and DyLAN, while a second experiment composes edge and node optimization on Mini Crosswords. DyLAN slightly outperforms GPTSwarm in the comparison, whereas subsequent node optimization raises Mini Crosswords accuracy substantially.

D.1. Comparing Our Method with Multiagent Debate and DYLAN on MMLU

  • The MMLU experiment initializes equal numbers of truthful and adversarial agents and compares GPTSwarm with Multiagent Debate and DyLAN.DyLAN scores agents and prunes low-scoring agents, with results averaged across pruning settings from one to five agents.Source: §D.1 · p. 17
  • DyLAN achieves a 0.0065 accuracy improvement over GPTSwarm on the MMLU adversarial-agent setup, while Multiagent Debate is less effective in this setting.The authors attribute DyLAN’s advantage to its more complex debate scheme and prompts, which also increase computational cost.Source: §D.1 · p. 17, Table 3 · p. 17

D.2. Applying Node Optimization after Edge Optimization

  • 0.668(±0.0060) accuracy follows node optimization after edge optimization, improving from 0.575(±0.0275) after ten REINFORCE edge steps on Mini Crosswords.Node prompts are updated using demonstrations selected with UCB1 from executions on 20 Mini Crosswords problems.Source: §D.2 · p. 17

E. Experimental Details

The experiments use a virtual decision-aggregator node and restrict candidate communication edges to cross-agent pairs, while excluding output-node connections.

  • A virtual agent aggregates multiple-agent outputs through majority vote or self-consistency and serves as the composite graph’s output node.Source: E. Experimental Details · p. 17

E.1. MMLU

The MMLU experiments evaluate adversarial swarm optimization, including its convergence, edge pruning, prompts, and agent-role configurations.

E.1. MMLU

  • The 3T3A adversarial swarm’s train utility converges toward the baseline, with validation using the first 10% of the dataset, or 153 questions.The convergence is shown in Figure 10, which smooths the training score with an unbiased exponential moving average.Source: §E.1 · p. 18, Figure 10 · p. 18

E.1.1. HYPER-PARAMETERS & PROMPTS

E.1.2. ADVERSARIAL SWARM OPTIMIZATION CASE STUDY

  • Optimization prunes disconnected agents and edges, retaining only the connections realized after optimizing all potential edges in the 2T2A swarm.Figure 11 contrasts the pre-optimization swarm containing all potential edges with the post-optimization connected subgraph.Source: §E.1.2 · p. 19, Figure 11 · p. 19

E.1.3. SWARM ROLES

E.2.1. AGENTS SETTING

  • Mini Crosswords nodes return one or two conditionally independent updated or unchanged solutions, and the composite output node forwards all received solutions.Edges from every agent output node to the composite output node are required for integration.Source: §E.2.1 · p. 20

E.2.2. HYPER-PARAMETERS & PROMPTS

  • The Tree of Thought agent searches a depth-eight perfect binary tree through eight branching nodes, each generating two solutions per input.This chain representation avoids explicitly constructing the tree’s 2^9 − 1 nodes; prompts are adapted from the original TOT work.Source: §E.2.1 · p. 20, §E.2.2 · p. 20

E.3.1. THE NODE OPTIMIZATION METHOD

Node optimization updates demonstration prompts from recent task feedback, while the experiments cover ReAct-style prompts, GAIA agents, and resource requirements.

E.3.1. THE NODE OPTIMIZATION METHOD

  • Every four problem executions, each node updates its demonstrations using recent positive and negative outcomes, retaining or randomly selecting up to four examples.The procedure considers the last ten node inputs and evaluates candidate demonstration sets by their program performance on unit tests.Source: §E.3.1 · p. 20
  • Mini Crosswords utility is best-state word accuracy shifted by −0.4 to reduce REINFORCE gradient variance, yielding 0.6 for perfect and −0.4 for empty solutions.Source: §E.3.1 · p. 20

E.3.2. HYPER-PARAMETERS & PROMPTS

E.4.1. AGENT SETTING

  • The experiments design different agents and swarms for GAIA, using GPT-4-Turbo and distinct node operations to solve the tasks.GAIA task-solving prompts are provided in Tables 9 and 10.Source: §E.4.1 · p. 20, §E.4.2 · p. 20, Table 7 · p. 21

F. Resource Requirements

G. Limitation and Future Work

The paper treats communication optimization between agents as groundwork for broader graph optimization, while identifying internal topology and large-scale coordination as future challenges.

  • The framework currently optimizes communication between agents rather than each agent’s internal node topology, which may matter for task planning.The authors propose dynamically changing internal topology as a direction for more extensive graph optimization.Source: G. Limitation and Future Work · p. 22
  • Scaling beyond 100 agents is identified as a challenge because communication efficiency and system robustness become difficult to maintain.Source: G. Limitation and Future Work · p. 22
Loading 2402.16823v3…