ChatPaper.aiChatPaper

提示与程序间的状态共享

Sharing State Between Prompts and Programs

December 16, 2025
作者: Ellie Y. Cheng, Logan Weber, Tian Jin, Michael Carbin
cs.AI

摘要

大型语言模型(LLM)的兴起催生了一种新型编程范式:自然语言编程。通过编写提示词来引导LLM执行自然语言处理、代码生成、推理等任务,用户实际上是在用自然语言编写代码——即自然语言代码——交由LLM执行。 新兴研究领域正致力于实现自然语言代码与Python等形式化语言之间的互操作性。我们提出了一种新颖的编程抽象概念——共享程序状态,该概念消除了实现自然语言代码与程序状态互操作所需的手动工作。借助共享程序状态,程序员能够编写直接写入程序变量、使用程序对象进行计算以及实现程序控制流的自然代码。我们提出了一种用于规范自然函数接口的架构,该架构可扩展编程系统以支持自然代码,并利用此架构将共享程序状态定义为自然函数接口。 我们在Nightjar编程系统中实现了共享程序状态。该系统支持程序员编写包含自然代码的Python程序,这些自然代码可与Python程序状态实现共享。实验表明,Nightjar程序在任务准确率上达到甚至超过手动编写实现的水平(提升4-19%),同时平均减少39.6%的代码行数。使用Nightjar的代价是可能产生运行时开销(达到手动实现运行时间的0.4-4.3倍)。
English
The rise of large language models (LLMs) has introduced a new type of programming: natural language programming. By writing prompts that direct LLMs to perform natural language processing, code generation, reasoning, etc., users are writing code in natural language -- natural language code -- for the LLM to execute. An emerging area of research enables interoperability between natural language code and formal languages such as Python. We present a novel programming abstraction, shared program state, that removes the manual work required to enable interoperability between natural language code and program state. With shared program state, programmers can write natural code that directly writes program variables, computes with program objects, and implements control flow in the program. We present a schema for specifying natural function interfaces that extend programming systems to support natural code and leverage this schema to specify shared program state as a natural function interface. We implement shared program state in the Nightjar programming system. Nightjar enables programmers to write Python programs that contain natural code that shares the Python program state. We show that Nightjar programs achieve comparable or higher task accuracy than manually written implementations (+4-19%), while decreasing the lines of code by 39.6% on average. The tradeoff to using Nightjar is that it may incur runtime overhead (0.4-4.3x runtime of manual implementations).
PDF01December 20, 2025