JSE:人工智能代理的结构化表达协议

1作者: mars_liu2 个月前原帖
标题:JSE – 一种基于JSON的S表达式格式,用于结构化AI输出 大家好, 我一直在尝试一个关于AI系统结构化输出的小想法,想分享一个早期的规范以获取反馈。 *JSE(JSON结构表达式)* 是一种轻量级约定,允许 *S表达式风格的逻辑嵌入有效的JSON中*。 动机很简单: 现代AI模型能够可靠地生成JSON。然而,JSON通常被视为*数据*,而许多AI交互实际上需要表达*结构化意图或计算*(类似于Lisp表达式、DSL或AST)。 工具调用和MCP解决了一部分问题,但它们往往是*特定于API的协议*,而不是*通用的结构表示*。 JSE试图用最小的规则集填补这一空白。 --- ### 核心思想 在JSE中: * 以`$`开头的字符串被视为*符号* * JSON数组或对象可以表示*S表达式* * 格式保持*100%有效的JSON* * 元数据可以与表达式共存 * `$quote`允许原始数据部分 从概念上讲: > 就像一个*组*由*集合加上定义在其上的操作*组成, > *JSE是应用于JSON数据的S表达式系统。* 示例: ```json ["$add", 1, 2] ``` 或者带有元数据: ```json { "$call": "$search", "query": "JSON S-expression", "top_k": 5 } ``` 理解JSE的系统可以将这些视为结构化操作,而不理解的系统仍然可以将其视为普通的JSON。 --- ### 这对AI可能有用的原因 许多AI系统需要传达诸如: * 推理计划 * 工具管道 * 结构化转换 * 查询语言 * 类DSL指令 如今,这些通常实现为: * 特定的JSON模式 * 工具特定格式 * 嵌入的代码字符串 JSE试图提供一种*结构化意图的统一表示*,其特点是: * 确定性 * 机器可解释 * 易于LLM生成 * 易于人类阅读 重要的是,*JSE并不旨在成为一个完整的Lisp或图灵完备的系统*。每个实现可以选择支持多少表达空间。 --- ### 设计约束 该格式试图满足一些实际目标: * 始终有效的JSON * 易于LLM生成 * 接近S表达式语义 * 可扩展的元数据 * 足够轻量以嵌入提示或API响应中 --- ### 示例用例 一些可能有用的领域: * AI编排系统 * 代理通信协议 * 结构化推理跟踪 * 嵌入式DSL提示 * 跨模型通信格式 --- ### 规范和代码库 早期规范和示例在这里: https://github.com/MarchLiu/jse 该规范有意设计为可以*直接嵌入提示中*,允许模型一致地生成JSE结构。 --- ### 我希望获得反馈的问题 * 是否有我应该研究的先前作品? * 与JSON Schema / 工具调用相比,这是否有用? * `$symbol`的设计是否合理? * 在语义上是否存在明显的边缘案例? 期待听到大家的想法。
查看原文
Title: JSE – A JSON-based S-Expression format for structured AI outputs<p>Hi HN,<p>I’ve been experimenting with a small idea around structured outputs for AI systems and wanted to share an early spec to get feedback.<p>*JSE (JSON Structural Expression)* is a lightweight convention that allows *S-expression style logic to be encoded inside valid JSON*.<p>The motivation is simple:<p>Modern AI models can reliably generate JSON. However, JSON is usually treated purely as *data*, while many AI interactions actually need to express *structured intent or computation* (similar to Lisp expressions, DSLs, or ASTs).<p>Tool calls and MCP solve some of this, but they tend to be *API-specific protocols* rather than a *general structural representation*.<p>JSE tries to fill that gap with a minimal rule set.<p>---<p>### Core idea<p>In JSE:<p>* Strings starting with `$` are treated as *symbols* * JSON arrays or objects can represent *S-expressions* * The format remains *100% valid JSON* * Metadata can coexist with expressions * `$quote` allows raw data sections<p>Conceptually:<p>&gt; Just as a *group* consists of a *set plus operations defined on it*, &gt; *JSE is an S-expression system applied to JSON data.*<p>Example:<p>```json [&quot;$add&quot;, 1, 2] ```<p>Or with metadata:<p>```json { &quot;$call&quot;: &quot;$search&quot;, &quot;query&quot;: &quot;JSON S-expression&quot;, &quot;top_k&quot;: 5 } ```<p>A system that understands JSE can interpret these as structured operations, while systems that don’t can still treat them as ordinary JSON.<p>---<p>### Why this might be useful for AI<p>Many AI systems need to communicate things like:<p>* reasoning plans * tool pipelines * structured transformations * query languages * DSL-like instructions<p>Today these are usually implemented as:<p>* ad-hoc JSON schemas * tool-specific formats * embedded code strings<p>JSE attempts to provide a *uniform representation for structured intent* that is:<p>* deterministic * machine interpretable * easy for LLMs to generate * easy for humans to read<p>Importantly, *JSE does not aim to be a full Lisp or a Turing-complete system*. Each implementation can choose how much of the expression space it supports.<p>---<p>### Design constraints<p>The format tries to satisfy a few practical goals:<p>* Always valid JSON * Easy for LLMs to generate * Close to S-expression semantics * Extensible for metadata * Lightweight enough to embed in prompts or API responses<p>---<p>### Example use cases<p>Some areas where this might be useful:<p>AI orchestration systems Agent communication protocols Structured reasoning traces Prompt-embedded DSLs Cross-model communication formats<p>---<p>### Spec and repo<p>Early spec and examples are here:<p>https:&#x2F;&#x2F;github.com&#x2F;MarchLiu&#x2F;jse<p>The spec is intentionally designed so it can also be *embedded directly inside prompts*, allowing models to generate JSE structures consistently.<p>---<p>### Questions I’d love feedback on<p>* Is there prior art I should study? * Would this be useful compared to JSON Schema &#x2F; tool calling? * Does the `$symbol` design feel reasonable? * Are there obvious edge cases in the semantics?<p>Curious to hear thoughts.