ACL2025

APPL: A Prompt Programming Language for Harmonious Integration of Programs and Large Language Model Prompts

Honghua Dong, Qidong Su, Yubo Gao, Zhaoyu Li, Yangjun Ruan, Gennady Pekhimenko, Chris J. Maddison, Xujie Si

摘要

Large Language Models (LLMs) have become increasingly capable of handling diverse tasks with the aid of well-crafted prompts and integration of external tools, but as task complexity rises, the workflow involving LLMs can be complicated and thus challenging to implement and maintain. To address this challenge, we propose APPL, A Prompt Programming Language that acts as a bridge between computer programs and LLMs, allowing seamless embedding of prompts into Python functions, and vice versa. APPL provides an intuitive and Python-native syntax, an efficient parallelized runtime with asynchronous semantics, and a tracing module supporting effective failure diagnosis and replaying without extra costs. We demonstrate that APPL programs are intuitive, concise, and efficient through representative scenarios including Chain-of-Thought with self-consistency (CoT-SC) and ReAct tooluse agent. We further use LLMs to judge the language design between APPL and previous work, where the results indicate that codes written in APPL are more readable and intuitive. Our code, tutorial and documentation are available at https://github.com/appl-team/appl . 1 @ppl(ctx="copy") # copy the context from caller 2 def get_answer(question): 3 question # append to the prompt 4 return gen() # return the string response 5 @ppl # marks APPL function 6 def answer_questions(quotation, questions): 7 "Extract the name of the author from the quotation below and answer questions." → 8 quotation # append to the prompt 9 with AIRole(): # assistant message scope 10 f"The name of the author is gen()" 11 return [get_answer(q) for q in questions] # parallelize calls (a) The APPL program for answering questions. 1 def get_answer(messages, question): 2 return gen(messages + [user(question)]) # new message list with addon message → 3 def answer_questions(quotation, questions