进阶 omnigent.ai 2026-10-14 06:47:13 · 20 阅读

第4章 模型与凭证

模型与凭证

每个 harness 都需要指定一个模型来运行,并需要凭证来访问该模型。你在 Agent 的 YAML 文件中声明模型,Omnigent 则负责管理用于向各供应商进行身份验证的凭证。

选择模型 在 Agent 的 YAML 文件中声明模型: executor: harness: claude-sdk model: claude-sonnet-4-6

你可以在运行时覆盖该设置,无需编辑文件: omni run agent.yaml --model claude-sonnet-4-6

会话中切换模型 在任意运行中的会话内使用 /model 命令即可即时切换模型。Agent 会保留对话历史及工具状态——只有底层模型会发生变化。 对于 Pi harness,网关提供商的模型:层级映射可以限定 /model 选择器只显示精选列表 —— 参见 Pi 配置。

推理强度 在指定模型的同时,为 Agent 设置默认的推理层级: executor: harness: claude-sdk model: claude-sonnet-4-6 reasoning_effort: high # low | medium | high | xhigh

executor.reasoning_effort 是可选的。如果未设置,将应用 harness CLI 自身的默认值。接受的值包括 low、medium、high 和 xhigh;具体哪些值有效取决于 harness 的实际情况,该值会在启动时对照 harness 的推理强度词汇表进行校验(未知值在 spec 校验阶段也会被提前拒绝)。 spec 级别的默认值适用于主会话以及所有未单独指定推理强度的子 Agent 调度。优先级从高到低依次为:

针对 sys_session_send / sys_session_create 的每次调度参数。 spec 中的 executor.reasoning_effort。 harness CLI 默认值。

向后兼容:旧的 llm.reasoning_effort 字段仍然受支持,解析 spec 时会将其提升为 executor.reasoning_effort。新 spec 建议优先使用 executor.reasoning_effort;若两者同时设置,executor.reasoning_effort 优先。

凭证 Omnigent 需要凭证来与模型提供商通信。 omni setup

设置向导引导你添加凭证、设置默认项或移除凭证。它还能自动检测机器上已有的凭证(如环境变量中的 API 密钥、已登录的 CLI、本地服务器等),让你一键确认。 凭证类型 类型说明API key 一方提供商密钥(Anthropic、OpenAI、OpenRouter 等)Subscription 通过官方 claude / codex CLI 订阅的 Claude Pro/Max 或 ChatGPT Plus/Pro 套餐Gateway 自带代理或本地模型。只需粘贴 base URL 和 key。Databricks Databricks 工作区 profile,经由 Foundation Model API 路由 API key 从提供商的控制台获取密钥,通过 omni setup 添加。 支持的提供商: 提供商密钥来源Anthropicconsole.anthropic.comOpenAIplatform.openai.comOpenRouteropenrouter.aiGroqconsole.groq.comDeepSeekplatform.deepseek.comxAIconsole.x.aiMistralconsole.mistral.aiTogether AIapi.together.xyzFireworks AIfireworks.ai Subscription 如果你拥有 Claude Pro/Max 或 ChatGPT Plus/Pro 套餐, Omnigent 可直接使用你现有的 CLI 登录状态,无需 API 密钥。只需确保已登录: claude auth login # 适用于 Claude Pro/Max codex login # 适用于 ChatGPT

omni setup 会自动检测活动的 CLI 登录状态,并将其作为一键选项提供。 对于 Codex,如果 ~/.codex/config.toml 中选择了能自我认证的内置提供商(Amazon Bedrock、Ollama、LM Studio),也可以免登录、免 Omnigent 提供商使用 —— 参见 Codex 配置。

Gateway Omnigent 兼容任何 OpenAI 或 Anthropic 协议网关: Databricks Unity AI GatewayMLflow AI GatewayOpenRouterLiteLLMPortkeyHeliconeCloudflare AI GatewayKong AI GatewayVercel AI GatewayAzure OpenAIOllamaLM StudiovLLMLocalAITGI (Hugging Face)GPT4All omni setup 要求填入 base URL 和 key。不同 Agent 对应的 base URL 不同: 提供商服务对象Base URL密钥OpenRouterClaude Codehttps://openrouter.ai/api你的 OpenRouter 密钥 (sk-or-...)OpenRouterCodex / OpenAI agentshttps://openrouter.ai/api/v1你的 OpenRouter 密钥 (sk-or-...)Ollama (本地)Codex / OpenAI agentshttp://localhost:11434/v1任意值(Ollama 会忽略) 注意:对于 Claude Code,请指向 OpenRouter 的 Anthropic 兼容 端点(.../api,而非 .../api/v1);对于 Codex 和 OpenAI-agents harness,请使用 OpenAI 兼容的 .../api/v1。

自托管模型的成本追踪 自托管及网关模型(Ollama、vLLM、自定义端点)往往不在 Omnigent 的价格目录中,因此相关会话不会显示成本。在配置文件中为提供商系列添加 pricing 块,告知 Omnigent 该模型的成本,它便会像对待目录中的模型一样追踪这些会话的支出。 # ~/.omnigent/config.yaml providers: ollama-local: kind: local openai: base_url: http://localhost:11434/v1 api_key: ollama pricing: input_per_million: 0.0 output_per_million: 0.0 价格以每百万 token 的美元计价。input_per_million 和 output_per_million 为必填项;cache_read_per_million 和 cache_write_per_million 为可选。若省略缓存费率, Omnigent 将基于 input 费率,按标准回退比例推导(cache read ≈ 0.10×, cache write ≈ 1.25×)。所有值必须 >= 0。 pricing: input_per_million: 0.25 output_per_million: 1.0 cache_read_per_million: 0.025 cache_write_per_million: 0.3125 配置的价格优先于目录价格,因此即使网关提供的是目录中已知的模型 ID(例如 claude-sonnet-4-6),只要该网关使用自定义费率,就会按你配置的数值计价,而非供应商官方价格。价格绑定到会话 harness 所使用的提供商系列(anthropic 或 openai)。 注意:自定义价格基于会话 harness 的默认提供商进行解析。如果会话选择了与默认不同的命名提供商,可能不会使用这些费率进行计价。

Databricks 通过 Foundation Model API 将模型路由至你的 Databricks 工作区。 Omnigent 从 ~/.databrickscfg profile 中解析凭证。 executor: harness: claude-sdk model: databricks-claude-sonnet-4-6 auth: type: databricks profile:

模型名称前缀为 databricks-,Omnigent 会自动将其路由至你的 工作区。完整模型列表参见 Databricks Foundation Model API 文档。

评论 (0)