Introduction
Building reliable Large Language Model (LLM) agents remains a significant challenge due to the inherent stochasticity of model outputs. To improve reliability, developers often employ "inference-time scaling" strategies, such as Best-of-N sampling, iterative refinement, or complex tree searches. However, implementing these strategies typically requires "entangling" the agent's core logic with the search mechanism, often forcing a refactor of clean Python code into complex, state-machine-driven architectures.
The EnCompass Framework
EnCompass is a Python framework designed to decouple an agent's workflow from its search strategy. It introduces a programming model called Probabilistic Angelic Nondeterminism (PAN). In this model, developers write agent logic as if every unreliable LLM call will succeed—the "angelic" assumption—while explicitly marking points of potential failure or divergence using a branchpoint() primitive.
Compilation and Search
The framework utilizes a @encompass.compile decorator to transform standard Python code into a searchable tree of execution paths. This is achieved through Continuation-Passing Style (CPS) compilation, which allows the program to "pause" at branch points, save its state (checkpoint), and resume later.
Key features of the framework include:
- Decoupled Search: Developers can swap search algorithms (e.g., DFS, BFS, Beam Search, or MCTS) by simply changing a parameter in the
.search()call. - Core Primitives: Beyond
branchpoint(), the framework providesrecord_score()to supply reward signals andprotect()to handle exceptions automatically (e.g., during JSON parsing). - State Management: EnCompass manages state copying across paths, though complex shared memory requires specific annotations like
NoCopy.
Evaluation and Results
The researchers evaluated EnCompass across three distinct domains: code translation (Java to Python), visual reasoning (ARC-AGI), and hard programming problems (LeetCodeHard).
Key Findings
- Development Efficiency: EnCompass reduced the lines of code required to implement search strategies by 3–6x compared to manual implementations.
- Performance Scaling: On the Java-to-Python translation task, beam search (easily enabled via EnCompass) significantly outperformed simple sampling for the same compute budget.
- Accuracy Improvements: For the ARC-AGI benchmark, using BFS with EnCompass improved GPT-4o's accuracy from 24.0% to 38.3%.
- Cost-Effectiveness: On LeetCodeHard, the framework achieved the same accuracy as vanilla implementations but at a lower total cost by optimizing the search process.
Discussion and Key Insights
The fundamental insight of EnCompass is that most popular agentic patterns—such as Reflexion or Tree-of-Thought—are essentially search processes over the execution paths of a nondeterministic program. By eliminating the "state machine tax," EnCompass allows for "program-in-control" agents that remain modular and readable while benefiting from sophisticated scaling laws.
Limitations and Future Work
Currently, the framework is optimized for developer-defined workflows rather than "LLM-in-control" agents where the model dynamically chooses every tool call. Additionally, developers must still manually identify branch points and define scoring functions, though future work may explore using LLMs to automate these tasks.
Summary updated