【opencode】代理的使用

张开发
2026/4/13 12:41:05 15 分钟阅读

分享文章

【opencode】代理的使用
1. 主代理OpenCode内置了Build和Plan两个主代理通过tab进行切换2. 子代理OpenCode内置了General和Explore两个子代理通过提及他们来手动调用或者主代理根据描述自动调用2.1Subagent General一个用于研究复杂问题和执行多步骤任务的通用代理。拥有完整的工具访问权限todo 除外因此可以在需要时修改文件。可用于并行运行多个工作单元。2.2SubagentExplore一个用于探索代码库的快速只读代理。无法修改文件。当您需要按模式快速查找文件、搜索代码中的关键字或回答有关代码库的问题时请使用此代理。3. 配置方式3.1opencode.json中配置代理{$schema:https://opencode.ai/config.json,agent:{build:{mode:primary,model:anthropic/claude-sonnet-4-20250514,prompt:{file:./prompts/build.txt},tools:{write:true,edit:true,bash:true}},plan:{mode:primary,model:anthropic/claude-haiku-4-20250514,tools:{write:false,edit:false,bash:false}},code-reviewer:{description:Reviews code for best practices and potential issues,mode:subagent,model:anthropic/claude-sonnet-4-20250514,prompt:You are a code reviewer. Focus on security, performance, and maintainability.,tools:{write:false,edit:false}}}}3.2Markdown文件定义代理全局~/.config/opencode/agents/项目级.opencode/agents/--- description: Reviews codeforquality and best practices mode: subagent model: anthropic/claude-sonnet-4-20250514 temperature:0.1tools: write:falseedit:falsebash:false--- You areincode review mode. Focus on: - Code quality and best practices - Potential bugs and edge cases - Performance implications - Security considerations Provide constructive feedback without making direct changes.

更多文章