arXiv:2512.14805cs.PLcs.AI2025-12被引 3

让提示词直接访问程序变量,实现自然语言编程与代码的无缝交互。

Sharing State Between Prompts and Programs

  • 提出共享程序状态抽象,让提示词可直接读写程序变量。
  • 相比手动实现,任务准确率提升4%-19%,代码量减少39.6%。
  • 适合想简化自然语言编程的开发者,尤其在代码生成场景中高效。

大语言模型(LLMs)推动了自然语言编程的发展,用户通过自然语言提示指令驱动模型完成文本处理、代码生成、推理等任务。现有研究致力于提升提示与程序间的互操作性。本文提出一种新型编程抽象——共享程序状态,使提示词能直接访问程序变量、操作程序对象并控制程序流程,无需手动对接。我们设计了自然函数接口规范,将共享程序状态作为该接口的实现,并在Nightjar编程系统中实现。Nightjar支持在Python程序中嵌入提示词,共享其程序状态。实验表明,相较于手动实现,Nightjar程序在任务准确率上提升4%-19%,平均代码量减少39.6%;代价是运行时开销增加0.4-4.3倍。

原文摘要 · Abstract (English)

The rise of large language models (LLMs) has introduced a new type of programming: natural language programming. Users write prompts, which are instructions in natural language, to direct LLMs to perform tasks such as natural language processing, code generation, reasoning, etc. An emerging area of research enables interoperability between prompts and programs. We present a novel programming abstraction, shared program state, that removes the manual work required to enable interoperability between prompts and program states. With shared program state, programmers can write prompts that directly access program variables, compute with program objects, and implement control flow in the program. We present a schema for specifying natural function interfaces that extend programming systems to support programs with prompts 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 containing prompts that share 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 is that Nightjar may incur runtime overhead (0.4-4.3x manual implementations).

自然语言编程提示词程序状态Python

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。