关键代码验证
技术研究 人工智能 AI Agent
oh-my-opencode 在 中定义了每个 Agent 的模型能力需求:
4.1 模型需求定义源码
oh-my-opencode 在 src/shared/model-requirements.ts 中定义了每个 Agent 的模型能力需求:
// Agent 能力需求定义
export interface AgentRequirements {
reasoning: number; // 推理能力要求 (1-5)
tool_call: number; // 工具调用能力要求 (1-5)
coding: number; // 编程能力要求 (1-5)
attachment: number; // 多模态能力要求 (1-5)
min_context: number; // 最小上下文窗口 (tokens)
max_latency_ms: number; // 最大可接受延迟 (毫秒)
}
// 内置 Agent 能力需求表
export const AGENT_REQUIREMENTS: Record<string, AgentRequirements> = {
sisyphus: {
reasoning: 5,
tool_call: 5,
coding: 4,
attachment: 2,
min_context: 128000,
max_latency_ms: 30000
},
oracle: {
reasoning: 5,
tool_call: 4,
coding: 5,
attachment: 2,
min_context: 128000,
max_latency_ms: 60000
},
librarian: {
reasoning: 3,
tool_call: 5,
coding: 4,
attachment: 2,
min_context: 32000,
max_latency_ms: 15000
},
explore: {
reasoning: 2,
tool_call: 3,
coding: 3,
attachment: 1,
min_context: 16000,
max_latency_ms: 5000
},
"frontend-ui-ux": {
reasoning: 3,
tool_call: 2,
coding: 5,
attachment: 5,
min_context: 64000,
max_latency_ms: 20000
}
};
// 模型能力评分表
export const MODEL_CAPABILITIES: Record<string, AgentRequirements> = {
"anthropic/claude-opus-4-5": {
reasoning: 5,
tool_call: 5,
coding: 5,
attachment: 3,
min_context: 200000,
max_latency_ms: 30000
},
"openai/gpt-5.2": {
reasoning: 5,
tool_call: 5,
coding: 4,
attachment: 3,
min_context: 256000,
max_latency_ms: 35000
},
"google/gemini-3-flash": {
reasoning: 3,
tool_call: 3,
coding: 3,
attachment: 4,
min_context: 1000000,
max_latency_ms: 5000
},
"opencode/glm-4.7-free": {
reasoning: 3,
tool_call: 4,
coding: 4,
attachment: 2,
min_context: 128000,
max_latency_ms: 10000
}
};
// 模型匹配检查函数
export function checkModelCompatibility(
agent: string,
model: string
): { compatible: boolean; issues: string[] } {
const agentReq = AGENT_REQUIREMENTS[agent];
const modelCap = MODEL_CAPABILITIES[model];
if (!agentReq || !modelCap) {
return {
compatible: false,
issues: ["未知的 Agent 或模型"]
};
}
const issues: string[] = [];
if (modelCap.reasoning < agentReq.reasoning) {
issues.push(`推理能力不足: ${modelCap.reasoning} < ${agentReq.reasoning}`);
}
if (modelCap.tool_call < agentReq.tool_call) {
issues.push(`工具调用能力不足: ${modelCap.tool_call} < ${agentReq.tool_call}`);
}
if (modelCap.coding < agentReq.coding) {
issues.push(`编程能力不足: ${modelCap.coding} < ${agentReq.coding}`);
}
if (modelCap.min_context < agentReq.min_context) {
issues.push(`上下文窗口不足: ${modelCap.min_context} < ${agentReq.min_context}`);
}
return {
compatible: issues.length === 0,
issues
};
}
4.2 Agent 配置示例
完整的 oh-my-opencode.json 配置示例
{
"$schema": "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/assets/oh-my-opencode.schema.json",
"agents": {
"sisyphus": {
"model": "anthropic/claude-opus-4-5",
"variant": "high",
"temperature": 0.7,
"maxTokens": 32768,
"prompt_append": "Always prioritize safety and code quality."
},
"oracle": {
"model": "openai/gpt-5.2",
"temperature": 0.5,
"prompt": "You are an expert software architect..."
},
"librarian": {
"model": "opencode/glm-4.7-free",
"temperature": 0.3
},
"explore": {
"model": "google/gemini-3-flash",
"temperature": 0.2
},
"frontend-ui-ux": {
"model": "anthropic/claude-sonnet-4-5",
"temperature": 0.8
},
"hephaestus": {
"model": "anthropic/claude-opus-4-5",
"temperature": 0.6
}
},
"categories": {
"visual-engineering": {
"model": "google/gemini-3-pro",
"temperature": 0.7
},
"ultrabrain": {
"model": "anthropic/claude-opus-4-5",
"temperature": 0.5
},
"deep": {
"model": "openai/gpt-5.2",
"temperature": 0.4
}
}
}
4.3 动态模型切换实现
在运行时根据任务复杂度动态切换模型的示例代码:
// 动态模型选择器
class DynamicModelSelector {
private costTracker: CostTracker;
constructor() {
this.costTracker = new CostTracker();
}
async selectModelForTask(
task: Task,
agent: string
): Promise<string> {
const baseModel = this.getBaseModel(agent);
const complexity = this.assessComplexity(task);
const budget = this.costTracker.getRemainingBudget();
// 根据任务复杂度和预算选择模型
if (complexity === 'high' && budget > 10) {
return this.getPremiumModel(agent);
} else if (complexity === 'medium' && budget > 5) {
return this.getStandardModel(agent);
} else {
return this.getEconomyModel(agent);
}
}
private assessComplexity(task: Task): 'low' | 'medium' | 'high' {
const factors = [
task.codeSize > 10000 ? 1 : 0,
task.requiresArchitecture ? 1 : 0,
task.tools.length > 5 ? 1 : 0,
task.hasCrossFileDependencies ? 1 : 0
];
const score = factors.reduce((a, b) => a + b, 0);
if (score >= 3) return 'high';
if (score >= 1) return 'medium';
return 'low';
}
private getBaseModel(agent: string): string {
const defaults: Record<string, string> = {
'sisyphus': 'anthropic/claude-opus-4-5',
'oracle': 'openai/gpt-5.2',
'librarian': 'opencode/glm-4.7-free',
'explore': 'google/gemini-3-flash'
};
return defaults[agent] || 'anthropic/claude-sonnet-4-5';
}
private getPremiumModel(agent: string): string {
const premium: Record<string, string> = {
'sisyphus': 'anthropic/claude-opus-4-5',
'oracle': 'openai/gpt-5.2',
'librarian': 'anthropic/claude-sonnet-4-5',
'explore': 'google/gemini-3-pro'
};
return premium[agent] || this.getBaseModel(agent);
}
private getStandardModel(agent: string): string {
const standard: Record<string, string> = {
'sisyphus': 'anthropic/claude-sonnet-4-5',
'oracle': 'anthropic/claude-sonnet-4-5',
'librarian': 'opencode/glm-4.7-free',
'explore': 'google/gemini-3-flash'
};
return standard[agent] || this.getBaseModel(agent);
}
private getEconomyModel(agent: string): string {
const economy: Record<string, string> = {
'sisyphus': 'anthropic/claude-haiku-4-5',
'oracle': 'google/gemini-3-flash',
'librarian': 'opencode/glm-4.7-free',
'explore': 'opencode/glm-4.7-free'
};
return economy[agent] || 'opencode/glm-4.7-free';
}
}
4.4 关键配置参数说明
温度参数 (temperature)
// 不同场景的温度设置建议
const TEMPERATURE_GUIDE = {
// 代码生成 - 较低温度保证准确性
'coding': 0.3,
// 探索性任务 - 中等温度平衡速度和多样性
'exploration': 0.5,
// 创意任务 - 较高温度增加创造性
'creative': 0.8,
// 架构设计 - 低温度保证严谨性
'architecture': 0.4,
// 计划编排 - 低温度保证一致性
'planning': 0.3
};
上下文窗口配置
// 不同 Agent 的上下文需求
const CONTEXT_REQUIREMENTS = {
'sisyphus': {
min_tokens: 128000,
recommended: 200000,
reason: '需要理解整个代码库的全局结构'
},
'oracle': {
min_tokens: 64000,
recommended: 128000,
reason: '架构分析需要跨越多个模块'
},
'librarian': {
min_tokens: 32000,
recommended: 64000,
reason: '文档检索不需要超大上下文'
},
'explore': {
min_tokens: 16000,
recommended: 32000,
reason: '快速搜索,短上下文即可'
}
};
回退链配置
// 当首选模型不可用时,按此顺序回退
const FALLBACK_CHAINS: Record<string, string[]> = {
'sisyphus': [
'anthropic/claude-opus-4-5',
'anthropic/claude-sonnet-4-5',
'openai/gpt-5.2',
'anthropic/claude-haiku-4-5'
],
'oracle': [
'openai/gpt-5.2',
'anthropic/claude-opus-4-5',
'deepseek/deepseek-r1'
],
'librarian': [
'opencode/glm-4.7-free',
'google/gemini-3-flash',
'anthropic/claude-haiku-4-5'
],
'explore': [
'google/gemini-3-flash',
'opencode/grok-code',
'opencode/glm-4.7-free'
]
};
4.5 验证检查清单
在实际部署前,使用以下检查清单验证配置:
## Agent 模型配置验证清单
### Sisyphus (主编排 Agent)
- [ ] 模型支持 tool_calling
- [ ] 上下文窗口 >= 128K tokens
- [ ] 推理能力评分 >= 4/5
- [ ] 延迟 < 30 秒
### Oracle (战略顾问 Agent)
- [ ] 模型支持 reasoning
- [ ] 代码理解能力 >= 4/5
- [ ] 支持长上下文分析
### Librarian (文档研究 Agent)
- [ ] 成本为 FREE 或 CHEAP
- [ ] 支持 webfetch/grep 工具
- [ ] 响应速度 < 10 秒
### Explore (代码探索 Agent)
- [ ] 延迟 < 5 秒
- [ ] 成本为 CHEAP
- [ ] 支持并行执行
参考资料
- oh-my-opencode Model Requirements - 模型需求源码
- Configuration Schema - 配置 JSON Schema