λA: A Typed Lambda Calculus for LLM Agent Composition
Authors: Qin Liu
Organizations: State Key Laboratory of Novel Software Technology, Nanjing University, Nanjing, Jiangsu, China · Software Institute, Nanjing University, Nanjing, Jiangsu, China
Existing LLM agent frameworks lack formal semantics: there is no principled way to determine whether an agent configuration is well-formed or will terminate. We present λA, a typed lambda calculus for agent composition that extends the simply-typed lambda calculus with oracle calls, bounded fixpoints (the ReAct loop), probabilistic choice, and mutable environments. We prove type safety, termination of bounded fixpoints, and soundness of derived lint rules, with full Coq mechanization (1,519 lines, 42 theorems, 0 Admitted). As a practical application, we derive a lint tool that detects structural configuration errors directly from the operational semantics. An evaluation on 835 real-world GitHub agent configurations shows that 94.1% are structurally incomplete under λA, with YAML-only lint precision at 54%, rising to 96--100% under joint YAML+Python AST analysis on 175 samples. This gap quantifies, for the first time, the degree of semantic entanglement between declarative configuration and imperative code in the agent ecosystem. We further show that five mainstream paradigms (LangGraph, CrewAI, AutoGen, OpenAI SDK, Dify) embed as typed λA fragments, establishing λA as a unifying calculus for LLM agent composition.
Figures & tables
Layer
Formalism
LoC
Key Classes
Core DSL
λA syntax (Def. 3.1 )
575
13 classes: Term, Lam, Compose, Loop, Tool, Route, etc.
Table 7. Real-world agent pattern tests. Each pattern constructs a production-style λA term, executes via real LLM calls, and verifies the output matches the operational semantics prediction. “Output” shows the actual LLM result.
Agent
n
Predicted max
Actual
Tightness
Church factorial (3!)
4
4 calls
4
1.0 ×
Church factorial (5!)
6
6 calls
6
1.0 ×
ReAct research (ex02)
20
40 calls
15
2.7 ×
Self-learning (demo4)
10
20 calls
8
2.5 ×
Refine loop (demo1)
5
10 calls
3
3.3 ×
Table 8. Cost Bound validation: predicted vs. actual oracle calls.
Paradigm
Core Pattern
λA Fragment
Configs
Graph (LangGraph)
Cond. edges, cycles
case + fixn + >>
35
Role-driven (CrewAI)
Role dispatch, handoff
case + >>
441
SDK wrapper (OpenAI)
LLM call + tools
lam + tool
283
Multi-agent (AutoGen)
Group chat, turns
fixn + case
22
Low-code (Dify)
YAML pipeline
from_config
54
Table 9. Five agent architecture paradigms as λA fragments. Each paradigm uses only a subset of the 11 term formers. “Configs” indicates the number of real-world GitHub configurations from our dataset (Section 7 ) that exercise each paradigm’s translation.
λA
DSPy
Agint
CSP/ π
Agentic 2.0
Formal syntax
✓
—
✓
✓
✓
Type system
✓
—
✓
—
✓
Type safety proof
Coq
—
—
—
—
Termination
fixn
—
—
—
—
Static analysis
26 rules
—
—
—
—
Empirical (configs)
835
—
—
—
—
Table 10. Comparison of agent/workflow formalisms.
University of Nottingham, Nottingham, UK · University of Edinburgh, Edinburgh, UK · Chalmers University of Technology and University of Gothenburg, Gothenburg, Sweden