蓝色天空网mbsky.com · 知识 · 实践 · 创造Pi Agent · 本地阅读预览
教程 / AI / 智能开发 / Pi Agent

Pi Agent 配置详解

核对可信项目与全局配置、各字段默认值和当前运行的覆盖。

本站独立整理的内容草稿。实例显示的是预期结果;浏览器、服务端运行与技术内容验收尚待完成,本页只用于阅读和图文核对。

学完这一章,你能够

用两层 JSON 管理默认值

个人配置位于代理配置目录的 settings.json,可信项目的覆盖文件位于 .pi/settings.json。通常先读全局,再把项目的精确字段合并进相应对象。数组按设置自身的规则处理,例如 enabledModels 由项目数组整体覆盖。进程级覆盖可只在本次有效。该实验写入两个临时文件,并用可信与未信任两种条件核对有效值。常用界面项也可在 /settings 中调整。

模型、推理档位和候选范围

用 defaultProvider 和 defaultModel 选择可用的模型组合,defaultThinkingLevel 设置初始推理档位。推理能力和有效档位取决于模型与提供方。thinkingBudgets 的数值用于支持预算的运行时,可分别设 minimal、low、medium 和 high。表中数值是教学输入,旧示例和本站都只用于解释配置。enabledModels 影响模型循环范围,可用名称、提供方/模型名或通配模式。

显示与图片处理分别配置

固定版缺省使用 system 主题。quietStartup 可用布尔值或 header 模式,后者保留启动头,隐藏模型范围和加载资源列表。externalEditor 可写自选编辑器命令。使用 VS Code 的调用可以加 --wait,通常用来让 Pi 等待编辑完成后再读回。terminal 字段控制本地显示,images 字段控制发送给模型之前的处理,两者各自设定。

网络、上下文和重试

httpProxy 属于代理配置目录的全局字段,用于 Pi 管理的 HTTP 请求。把它保留为受控环境的配置。本站样例只读取一个本机地址作为配置值,网络请求不经该地址。

压缩来自上下文预算。重试分代理工作流和提供方 SDK 两层,计数、请求超时与等待上限可分别设置。依实际网络和提供商文档确定是否需要提供方层重试。多层重试叠加可能延后配额错误处理或拉长等待。

消息队列和本地工具配置

steeringMode 管理运行时追加的指令,followUpMode 管理当前工作结束后送出的请求,transport 则是通信偏好。shellPath 与 shellCommandPrefix 会影响本地 Shell 启动及命令。npmCommand 用数组定义 npm 程序和固定参数,例如在既有版本管理器启动的环境里使用指定 Node。实验只核对有效配置,不运行该演示 Shell 或 npm 命令。

完整配置可把已选模型、主题、压缩、重试、警告和资源声明放入同一个有效 JSON 文件。warnings.anthropicExtraUsage 在使用适用的 Anthropic 订阅鉴权时提示可能产生的额外用量。packages 声明 Pi 要加载的包,还可为包选择需要的资源。敏感凭据由独立的认证流程和配置管理。

全局与项目文件

路径作用与条件
<配置目录>/settings.json提供用户默认设置,适用全局字段。
.pi/settings.json可信项目可覆盖允许的设置。

模型与推理

字段类型默认与作用
defaultProvider字符串自动选择。指定模型提供方。
defaultModel字符串自动选择。指定可用模型的 ID。
defaultThinkingLevel字符串常用默认 medium,档位包括 off、minimal、low、medium、high、xhigh、max,受模型支持限制。
hideThinkingBlock布尔值默认 false。设置为 true 时折叠终端推理块。
showCacheMissNotices布尔值默认 false。打开后显示达到条件的缓存和恢复提示、压缩用量等。
thinkingBudgets对象省略使用内置值。各档位预算需模型接口支持。

示例推理档位

档位示例 token理解方式
minimal1100示例最低启用预算,适合尝试轻量处理。
low3900示例较少的推理预算。
medium8200示例中间档位。
high12300示例更多推理空间,适合分析多个相互影响的条件。

界面与启动

字段类型默认与作用
theme字符串默认 system。可固定主题或用浅/深配对。
externalEditor字符串省略时参考 VISUAL、EDITOR 和平台默认程序。用于打开草稿。
quietStartup布尔值或 header默认 false,控制启动头及加载资源信息。
collapseChangelog布尔值默认 false,改为 true 可折叠更新记录。
editorPaddingX整数默认0,作用于编辑区水平留白,常用范围0–3。
outputPad数字默认1,设置0去掉消息区域的水平留白。
autocompleteMaxVisible整数默认5,控制补全最多可见项,界面范围3–20。

Pi 的 HTTP 代理

字段类型默认与作用
httpProxy字符串省略时没有此配置指定的代理。仅全局文件可设置。

自动压缩

字段类型默认与作用
compaction.enabled布尔值默认 true,启用自动阈值检查。
compaction.reserveTokens数字默认16384,从窗口减去它得到常用触发阈值。
compaction.keepRecentTokens数字默认20000,用于选择保留较新上下文的切点。

重试和请求时限

字段类型默认与作用
retry.enabled布尔值默认 true,处理可恢复的工作流错误。
retry.maxRetries整数默认3,代理层的最大重试次数。
retry.baseDelayMs毫秒默认2000,退避计算从此基数开始,还要考虑服务返回的时限。
retry.provider.timeoutMs毫秒可指定提供方请求超时,省略时按有效 HTTP 空闲超时及对应提供方规则。
retry.provider.maxRetries整数常用默认0,控制提供方 SDK 重试次数。

消息与传输

字段类型默认与作用
steeringMode字符串默认 one-at-a-time,处理运行过程中的追加指令,也支持 all。
followUpMode字符串默认 one-at-a-time,控制工作结束后怎样出队。
transport字符串默认 auto。可选 SSE、WebSocket 等有效模式,取决于提供方。

终端显示与模型图片

字段类型默认与作用
terminal.showImages布尔值默认 true。允许支持的终端内联显示图片。
terminal.imageWidthCells数字默认60,为终端内联图片偏好宽度,单位为字符格。
images.autoResize布尔值默认 true,发送前最多缩到2000×2000像素。
images.blockImages布尔值默认 false。设 true 时阻止把图片提供给模型。

工具启动参数

字段类型默认与作用
shellPath字符串省略时按平台查找 Shell。
shellCommandPrefix字符串省略时无此自定义前缀,用来在命令前准备环境。
npmCommand字符串数组常用默认 npm。数组第一项为程序,后面是固定参数。

模型循环

字段类型默认与作用
enabledModels字符串数组省略可用所有已配置模型。可用名称、通配模式及提供方限定。

观察两个临时设置文件怎样合并

javascript · 阅读源码
import assert from 'node:assert/strict';
import {mkdir,mkdtemp,readFile,rm,writeFile} from 'node:fs/promises';
import {tmpdir} from 'node:os';
import {basename,dirname,join,resolve} from 'node:path';
import {pathToFileURL} from 'node:url';

const modules = process.argv[2];
if (!modules) throw new Error('Supply the installed node_modules path.');
const pi = resolve(modules, '@earendil-works', 'pi-coding-agent');
const load = file => import(pathToFileURL(join(pi,'dist',file)).href);
const {SettingsManager} = await load('index.js');
const {SETTINGS_DEFAULTS} = await load('core/settings-defaults.js');
const {resolveModelScopeFromModels} = await load('core/model-resolver.js');
const {version} = JSON.parse(await readFile(join(pi,'package.json'),'utf8'));
const cases = [];
function check(name,input,expected,actual) {
  assert.deepStrictEqual(actual,expected,name);
  cases.push({name,input,expected,actual,passed:true});
}
const base = resolve(tmpdir());
const root = await mkdtemp(join(base,'mbsky-pi-settings-'));
assert.equal(dirname(resolve(root)),base);
assert.ok(basename(root).startsWith('mbsky-pi-settings-'));
try {
  const agentDir = join(root,'profile');
  const cwd = join(root,'project');
  const localDir = join(cwd,'.pi');
  await mkdir(agentDir);
  await mkdir(localDir,{recursive:true});
  const save = (file,value) => writeFile(file,JSON.stringify(value),'utf8');
  const globalFile = join(agentDir,'settings.json');
  const projectFile = join(localDir,'settings.json');
  const user = {
    defaultProvider:'demo-provider',defaultModel:'demo-small',defaultThinkingLevel:'medium',
    hideThinkingBlock:true,showCacheMissNotices:true, thinkingBudgets:{minimal:1100,low:3900,medium:8200,high:12300},
    theme:'light',externalEditor:'local-editor --wait',quietStartup:'header',collapseChangelog:true,
    editorPaddingX:2,outputPad:0,autocompleteMaxVisible:9,httpProxy:'http://127.0.0.1:9999',
    compaction:{enabled:true,reserveTokens:16384},retry:{enabled:true,maxRetries:4,baseDelayMs:750,
      provider:{timeoutMs:4500,maxRetries:1,maxRetryDelayMs:2400}},
    steeringMode:'all',followUpMode:'one-at-a-time',transport:'sse',
    terminal:{showImages:false,imageWidthCells:52},images:{autoResize:false,blockImages:true},
    shellPath:'local-shell',shellCommandPrefix:'Set-Location .',npmCommand:['local-node','npm'],
    enabledModels:['demo-*'],warnings:{anthropicExtraUsage:false},packages:[],
  };
  const project = {defaultModel:'demo-large',compaction:{reserveTokens:8000},retry:{provider:{timeoutMs:5000}},
    enabledModels:['demo-large','demo-mini']};
  await save(globalFile,user);
  await save(projectFile,project);
  const scoped = SettingsManager.create(cwd,agentDir,{projectTrusted:true});
  const untrusted = SettingsManager.create(cwd,agentDir,{projectTrusted:false});
  check('configured_files_and_project_trust', {trust:[true,false]}, ['demo-large','demo-small'],
    [scoped.getDefaultModel(),untrusted.getDefaultModel()]);
  check('model_settings_and_example_thinking_budgets', {exampleBuiltInValues:false},
    ['demo-provider','demo-large','medium',true,true,{minimal:1100,low:3900,medium:8200,high:12300}],
    [scoped.getDefaultProvider(),scoped.getDefaultModel(),scoped.getDefaultThinkingLevel(),
      scoped.getHideThinkingBlock(),scoped.getShowCacheMissNotices(),scoped.getThinkingBudgets()]);
  const defaults = SettingsManager.inMemory();
  check('stock_theme_and_ui_values', {settings:{}},
    [null,false,false,0,1,5], [
      defaults.getThemeSetting() ?? null,defaults.getQuietStartup(),defaults.getCollapseChangelog(),
      defaults.getEditorPaddingX(),defaults.getOutputPad(),defaults.getAutocompleteMaxVisible()]);
  check('ui_preferences_read_exact_values', {theme:'light',quiet:'header'},
    ['light','local-editor --wait','header',true,2,0,9], [
     scoped.getTheme(),scoped.getExternalEditorCommand(),scoped.getQuietStartup(),scoped.getCollapseChangelog(),
     scoped.getEditorPaddingX(),scoped.getOutputPad(),scoped.getAutocompleteMaxVisible()]);
  const before = await readFile(globalFile,'utf8');
  scoped.applyOverrides({theme:'dark'});
  check('runtime_override_does_not_rewrite_global_file',{themeOverride:'dark'},
    ['dark',true],[scoped.getTheme(),(await readFile(globalFile,'utf8'))===before]);
  check('project_and_user_layers_merge_nested_fields',{override:'compaction.reserveTokens'},
    {enabled:true,reserveTokens:8000,keepRecentTokens:20000},scoped.getCompactionSettings());
  check('stock_compaction_values',{settings:{}},{enabled:true,reserveTokens:16384,keepRecentTokens:20000},
    defaults.getCompactionSettings());
  check('user_proxy_value_selected_without_client_network',{globalField:'httpProxy'},
    'http://127.0.0.1:9999',scoped.getGlobalSettings().httpProxy);
  const retry = scoped.getRetrySettings();
  const provider = scoped.getProviderRetrySettings();
  check('separate_agent_and_provider_retry_options',{files:['global','project']},
    [true,4,750,5000,1,2400],[retry.enabled,retry.maxRetries,retry.baseDelayMs,
      provider.timeoutMs,provider.maxRetries,provider.maxRetryDelayMs]);
  check('stock_agent_retry_values',{settings:{}},[true,3,2000,60000],
    [defaults.getRetryEnabled(),defaults.getRetrySettings().maxRetries,defaults.getRetrySettings().baseDelayMs,
      defaults.getProviderRetrySettings().maxRetryDelayMs]);
  check('message_transport_and_queue_modes',{example:'queue settings'},
    ['all','one-at-a-time','sse'],[scoped.getSteeringMode(),scoped.getFollowUpMode(),scoped.getTransport()]);
  check('image_display_and_provider_flags_are_separate',{inputs:'display off and provider blocked'},
    [false,52,false,true],[scoped.getShowImages(),scoped.getImageWidthCells(),scoped.getImageAutoResize(),scoped.getBlockImages()]);
  check('stock_image_flags_and_width',{settings:{}},[true,60,true,false],
    [defaults.getShowImages(),defaults.getImageWidthCells(),defaults.getImageAutoResize(),defaults.getBlockImages()]);
  check('shell_and_npm_are_configuration_not_execution',{variables:'synthetic settings'},
    ['local-shell','Set-Location .',['local-node','npm']],[scoped.getShellPath(),scoped.getShellCommandPrefix(),scoped.getNpmCommand()]);
  check('project_array_replaces_user_array',{field:'enabledModels'},['demo-large','demo-mini'],scoped.getEnabledModels());
  const models = [
    {id:'demo-small',provider:'demo-provider',name:'Small'},
    {id:'demo-large',provider:'demo-provider',name:'Large'},
    {id:'other-accent',provider:'other',name:'Other'},
  ];
  const scopedModels = resolveModelScopeFromModels(['demo-provider/demo-*'],models);
  check('scoped_model_filter_uses_provider_and_pattern',{pattern:'demo-provider/demo-*'},
    ['demo-small','demo-large'],scopedModels.scopedModels.map(x=>x.model.id));
  check('warnings_and_package_configuration',{settings:'profile'},[true,false,[]],
    [SETTINGS_DEFAULTS.warnings.anthropicExtraUsage,scoped.getWarnings().anthropicExtraUsage,scoped.getGlobalSettings().packages]);
  await save(projectFile,{...project,compaction:{reserveTokens:9000}});
  await scoped.reload();
  check('reload_rereads_project_file',{changedReserve:9000},[9000,true],
    [scoped.getCompactionReserveTokens(),scoped.getCompactionEnabled()]);
  process.stdout.write(JSON.stringify({nodeVersion:process.version,packageVersion:version,cases})+'\n');
} finally {
  await rm(root,{recursive:true,force:true});
}
预期结果 · 待实际运行核验
  • 可信项目选择 demo-large,将压缩预留覆盖为8000,同时保留自动开启并继承保留长度默认值。切换项目可信条件会改变有效模型。本次主题覆盖不会写回文件。
观察两个临时设置文件怎样合并

所需环境:Windows、Node.js 24.22.3、Pi 1.5.0、独立临时 JSON。

当前源码 SHA256:f8d7aacdd09f2190cdbf62c886db0427e00bb75c89c053b600ce0c9c7755863a

下载本站示例源码

本地复跑

按 README 执行脚本,核对覆盖、回退、重载和模型候选输出。

下载 Pi 设置合并与本地校验实验

所需环境:Windows、Node.js 24.22.3、Pi 1.5.0、独立临时 JSON。

ZIP SHA256:b9fe41c8e4a60db22705465ed261aebfb8a821ea3501c8f065f492987e28db4e

常见错误与边界

  • 有效配置要结合项目是否可信判断。
  • 分清本地图片显示与模型图片输入。

练习与解答

项目只写 compaction.reserveTokens 时,其余压缩参数从哪里来?

展开参考解答

已在全局文件显式设置的同组字段沿用全局值,仍未设置的字段采用内置默认值。

规范与官方依据