#提示词插槽
Prompt slots 是以声明式方式塑造智能体系统提示词的会话选项。请把它们用于宿主级行为—— 角色设定、编码规范、输出风格——这些内容不应写在每次的用户 prompt 里。这些槽位叠加在 智能体内置指令之上,因此核心工具行为(读取、写入、运行命令)会被保留。
共有四个槽位:
| 槽位 | 用途 |
|---|---|
role / role | 智能体采用的角色设定。 |
guidelines / guidelines | 智能体必须遵循的规范与规则。 |
responseStyle / response_style | 智能体回复的格式方式。 |
extra / extra | 逐字追加的自由格式指令。 |
#基本用法
在打开会话时设置任意子集的槽位。它们会应用于该会话的每一轮对话。
Rust
Node.js
Python
Go
use a3s_code_core::{Agent, SessionOptions, SystemPromptSlots};#[tokio::main]async fn main() -> a3s_code_core::Result<()> {let agent = Agent::new("agent.acl").await?;let slots = SystemPromptSlots::default().with_role("发布就绪审查员").with_guidelines("先找阻塞项,再提改进;完成结论必须有命令证据。").with_response_style("简洁,发现优先");let session = agent.session_builder("/repo").options(SessionOptions::new().with_prompt_slots(slots)).build().await?;let result = session.send("这个仓库可以发布了吗?", None).await?;println!("{}", result.text);session.close().await;agent.close().await;Ok(())}
import { Agent } from '@a3s-lab/code';async function main() {// create() 接受 .acl 文件路径或内联 ACL 字符串。const agent = await Agent.create('agent.acl');const session = agent.session('/repo', {role: 'release-readiness reviewer',guidelines:'Find blockers before improvements. Require command evidence for done claims.',responseStyle: 'concise, findings first',});const result = await session.send('Is this repo ready to ship?');console.log(result.text);session.close();}main().catch((err) => {console.error(err);process.exit(1);});
from a3s_code import Agent, SessionOptionsdef main():# create() 接受 .acl 文件路径或内联 ACL 字符串。agent = Agent.create('agent.acl')opts = SessionOptions()opts.role = 'release-readiness reviewer'opts.guidelines = 'Find blockers before improvements. Require command evidence for done claims.'opts.response_style = 'concise, findings first'session = agent.session('/repo', opts)result = session.send('Is this repo ready to ship?')print(result.text)session.close()main()
package mainimport ("context""fmt""log"code "github.com/A3S-Lab/Code/sdk/go/v6")func main() {ctx := context.Background()agent, err := code.Create(ctx, "agent.acl")if err != nil {log.Fatal(err)}defer agent.Close(context.Background())session, err := agent.Session(ctx, "/repo", &code.SessionOptions{PromptSlots: &code.PromptSlots{Role: "发布就绪审查员",Guidelines: "先找阻塞项,再提改进;完成结论必须有命令证据。",ResponseStyle: "简洁,发现优先",},})if err != nil {log.Fatal(err)}defer session.Close(context.Background())result, err := session.Run(ctx, "这个仓库可以发布了吗?")if err != nil {log.Fatal(err)}fmt.Println(result.Text)}
#逐个槽位说明
这四个槽位彼此独立组合。仅设置角色的会话、带有严格准则的评审者、以及追加自由格式指令的 会话,使用的都是同一组选项。
Rust
Node.js
Python
Go
use a3s_code_core::{Agent, SessionOptions, SystemPromptSlots};#[tokio::main]async fn main() -> a3s_code_core::Result<()> {let agent = Agent::new("agent.acl").await?;let role_only = agent.session_builder("/repo").options(SessionOptions::new().with_prompt_slots(SystemPromptSlots::default().with_role("你是擅长异步编程的资深 Rust 开发者。"),)).build().await?;role_only.close().await;let reviewer = agent.session_builder("/repo").options(SessionOptions::new().with_prompt_slots(SystemPromptSlots::default().with_role("你是 Python 代码审查员。").with_guidelines("始终检查类型提示,并标记所有 `eval()` 调用。").with_response_style("使用要点列表,保持简洁。"),)).build().await?;reviewer.close().await;let extra_only = agent.session_builder("/repo").options(SessionOptions::new().with_prompt_slots(SystemPromptSlots::default().with_extra("每次回复都以“-- A3S”结尾。"),)).build().await?;extra_only.close().await;let file_manager = agent.session_builder("/repo").options(SessionOptions::new().with_prompt_slots(SystemPromptSlots::default().with_role("你是极简文件管理员。").with_guidelines("只有用户明确要求时才创建文件。"),)).build().await?;let result = file_manager.send("创建 test.txt,写入“prompt slots work”,然后读回内容。",None,).await?;println!("{}", result.text);file_manager.close().await;agent.close().await;Ok(())}
// 1. Custom role only.let session = agent.session(workspace, {role: 'You are a senior Rust developer who specializes in async programming.',});// 2. Role + guidelines + response style.session = agent.session(workspace, {role: 'You are a Python code reviewer.',guidelines: 'Always check for type hints. Flag any use of `eval()`.',responseStyle: 'Reply in bullet points. Be concise.',});// 3. Extra freeform instructions only.session = agent.session(workspace, {extra: "Always end your response with '-- A3S'",});// 无论如何配置插槽,核心工具行为都保持不变。session = agent.session(workspace, {role: 'You are a minimalist file manager.',guidelines: 'Only create files when explicitly asked.',});const result = await session.send("Create a file called test.txt with the content 'prompt slots work'. Then read it back.",);
# 1. Custom role only.opts = SessionOptions()opts.role = 'You are a senior Rust developer who specializes in async programming.'session = agent.session(workspace, opts)# 2. Role + guidelines + response style.opts = SessionOptions()opts.role = 'You are a Python code reviewer.'opts.guidelines = 'Always check for type hints. Flag any use of `eval()`.'opts.response_style = 'Reply in bullet points. Be concise.'session = agent.session(workspace, opts)# 3. Extra freeform instructions only.opts = SessionOptions()opts.extra = "Always end your response with '-- A3S'"session = agent.session(workspace, opts)# 无论如何配置插槽,核心工具行为都保持不变。opts = SessionOptions()opts.role = 'You are a minimalist file manager.'opts.guidelines = 'Only create files when explicitly asked.'session = agent.session(workspace, opts)result = session.send("Create a file called test.txt with the content 'prompt slots work'. Then read it back.",)
package mainimport ("context""fmt""log"code "github.com/A3S-Lab/Code/sdk/go/v6")func open(ctx context.Context,agent *code.Agent,slots code.PromptSlots,) *code.Session {session, err := agent.Session(ctx, "/repo", &code.SessionOptions{PromptSlots: &slots,})if err != nil {log.Fatal(err)}return session}func main() {ctx := context.Background()agent, err := code.Create(ctx, "agent.acl")if err != nil {log.Fatal(err)}defer agent.Close(context.Background())roleOnly := open(ctx, agent, code.PromptSlots{Role: "你是擅长异步编程的资深 Rust 开发者。",})roleOnly.Close(ctx)reviewer := open(ctx, agent, code.PromptSlots{Role: "你是 Python 代码审查员。",Guidelines: "始终检查类型提示,并标记所有 `eval()` 调用。",ResponseStyle: "使用要点列表,保持简洁。",})reviewer.Close(ctx)extraOnly := open(ctx, agent, code.PromptSlots{Extra: "每次回复都以“-- A3S”结尾。",})extraOnly.Close(ctx)fileManager := open(ctx, agent, code.PromptSlots{Role: "你是极简文件管理员。",Guidelines: "只有用户明确要求时才创建文件。",})defer fileManager.Close(context.Background())result, err := fileManager.Run(ctx,"创建 test.txt,写入“prompt slots work”,然后读回内容。",)if err != nil {log.Fatal(err)}fmt.Println(result.Text)}
槽位用于定制角色设定与行为规则;它们不会禁用工具,也不会改变智能体的核心循环。请把
任务相关的请求保留在 send 消息中,而把应在会话每一轮都生效的行为交给这些槽位。
可运行版本位于 sdk/node/examples/skills/test_prompt_slots.ts。