feat(agents): add agent override configuration support
- Add AgentName, AgentOverrideConfig, AgentOverrides types - Implement createBuiltinAgents with disabled_agents and overrides support - Support oh-my-opencode.json config for: - disabled_agents: disable specific built-in agents - agents: override model, temperature, tools, permission per agent - Tools and permission objects are shallow-merged with base config - Export types for external consumers - Update README with agent override documentation
This commit is contained in:
36
README.en.md
36
README.en.md
@@ -5,6 +5,7 @@ English | [한국어](README.ko.md)
|
|||||||
- [Oh My OpenCode](#oh-my-opencode)
|
- [Oh My OpenCode](#oh-my-opencode)
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
- [Configuration](#configuration)
|
- [Configuration](#configuration)
|
||||||
|
- [Disable specific MCPs](#disable-specific-mcps)
|
||||||
- [TL;DR](#tldr)
|
- [TL;DR](#tldr)
|
||||||
- [Why OpenCode \& Why Oh My OpenCode](#why-opencode--why-oh-my-opencode)
|
- [Why OpenCode \& Why Oh My OpenCode](#why-opencode--why-oh-my-opencode)
|
||||||
- [Features](#features)
|
- [Features](#features)
|
||||||
@@ -58,6 +59,36 @@ If you want to disable specific built-in MCPs, you can use the `disabled_mcps` o
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Disable specific Agents
|
||||||
|
|
||||||
|
If you want to disable specific built-in agents, you can use the `disabled_agents` option.
|
||||||
|
Available agents: `oracle`, `librarian`, `explore`, `frontend-ui-ux-engineer`, `document-writer`
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"disabled_agents": ["oracle", "librarian"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Override Agents
|
||||||
|
|
||||||
|
You can override the configuration of built-in agents using the `agents` option.
|
||||||
|
Overridable properties: `model`, `temperature`, `tools`, `permission`, `color`, `disable`, `mode`.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"agents": {
|
||||||
|
"oracle": {
|
||||||
|
"model": "anthropic/claude-3-7-sonnet-20250219",
|
||||||
|
"temperature": 0.5
|
||||||
|
},
|
||||||
|
"frontend-ui-ux-engineer": {
|
||||||
|
"tools": ["playwright_browser_take_screenshot"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## TL;DR
|
## TL;DR
|
||||||
|
|
||||||
- **Model Setup Required**
|
- **Model Setup Required**
|
||||||
@@ -163,11 +194,8 @@ If this sounds arrogant and you have a superior solution, send a PR. You are wel
|
|||||||
|
|
||||||
As of now, I have no affiliation with any of the projects or models mentioned here. This plugin is purely based on personal experimentation and preference.
|
As of now, I have no affiliation with any of the projects or models mentioned here. This plugin is purely based on personal experimentation and preference.
|
||||||
|
|
||||||
|
I constructed 99% of this project using OpenCode. I focused on functional verification. This documentation has been personally reviewed and comprehensively rewritten, so you can rely on it with confidence.
|
||||||
## Warnings
|
## Warnings
|
||||||
|
|
||||||
- If you are on [1.0.132](https://github.com/sst/opencode/releases/tag/v1.0.132) or lower, OpenCode has a bug that might break config.
|
- If you are on [1.0.132](https://github.com/sst/opencode/releases/tag/v1.0.132) or lower, OpenCode has a bug that might break config.
|
||||||
- [The fix](https://github.com/sst/opencode/pull/5040) was merged after 1.0.132, so use a newer version.
|
- [The fix](https://github.com/sst/opencode/pull/5040) was merged after 1.0.132, so use a newer version.
|
||||||
|
|
||||||
- I constructed 99% of this project using OpenCode. I focused on functional verification. This documentation has been personally reviewed and comprehensively rewritten, so you can rely on it with confidence.
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,3 +12,6 @@ export const builtinAgents: Record<string, AgentConfig> = {
|
|||||||
"frontend-ui-ux-engineer": frontendUiUxEngineerAgent,
|
"frontend-ui-ux-engineer": frontendUiUxEngineerAgent,
|
||||||
"document-writer": documentWriterAgent,
|
"document-writer": documentWriterAgent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export * from "./types"
|
||||||
|
export { createBuiltinAgents } from "./utils"
|
||||||
|
|||||||
12
src/agents/types.ts
Normal file
12
src/agents/types.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import type { AgentConfig } from "@opencode-ai/sdk"
|
||||||
|
|
||||||
|
export type AgentName =
|
||||||
|
| "oracle"
|
||||||
|
| "librarian"
|
||||||
|
| "explore"
|
||||||
|
| "frontend-ui-ux-engineer"
|
||||||
|
| "document-writer"
|
||||||
|
|
||||||
|
export type AgentOverrideConfig = Partial<AgentConfig>
|
||||||
|
|
||||||
|
export type AgentOverrides = Partial<Record<AgentName, AgentOverrideConfig>>
|
||||||
55
src/agents/utils.ts
Normal file
55
src/agents/utils.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import type { AgentConfig } from "@opencode-ai/sdk"
|
||||||
|
import type { AgentName, AgentOverrideConfig, AgentOverrides } from "./types"
|
||||||
|
import { oracleAgent } from "./oracle"
|
||||||
|
import { librarianAgent } from "./librarian"
|
||||||
|
import { exploreAgent } from "./explore"
|
||||||
|
import { frontendUiUxEngineerAgent } from "./frontend-ui-ux-engineer"
|
||||||
|
import { documentWriterAgent } from "./document-writer"
|
||||||
|
|
||||||
|
const allBuiltinAgents: Record<AgentName, AgentConfig> = {
|
||||||
|
oracle: oracleAgent,
|
||||||
|
librarian: librarianAgent,
|
||||||
|
explore: exploreAgent,
|
||||||
|
"frontend-ui-ux-engineer": frontendUiUxEngineerAgent,
|
||||||
|
"document-writer": documentWriterAgent,
|
||||||
|
}
|
||||||
|
|
||||||
|
function mergeAgentConfig(
|
||||||
|
base: AgentConfig,
|
||||||
|
override: AgentOverrideConfig
|
||||||
|
): AgentConfig {
|
||||||
|
return {
|
||||||
|
...base,
|
||||||
|
...override,
|
||||||
|
tools: override.tools !== undefined
|
||||||
|
? { ...(base.tools ?? {}), ...override.tools }
|
||||||
|
: base.tools,
|
||||||
|
permission: override.permission !== undefined
|
||||||
|
? { ...(base.permission ?? {}), ...override.permission }
|
||||||
|
: base.permission,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createBuiltinAgents(
|
||||||
|
disabledAgents: AgentName[] = [],
|
||||||
|
agentOverrides: AgentOverrides = {}
|
||||||
|
): Record<string, AgentConfig> {
|
||||||
|
const result: Record<string, AgentConfig> = {}
|
||||||
|
|
||||||
|
for (const [name, config] of Object.entries(allBuiltinAgents)) {
|
||||||
|
const agentName = name as AgentName
|
||||||
|
|
||||||
|
if (disabledAgents.includes(agentName)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
const override = agentOverrides[agentName]
|
||||||
|
if (override) {
|
||||||
|
result[name] = mergeAgentConfig(config, override)
|
||||||
|
} else {
|
||||||
|
result[name] = config
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
14
src/index.ts
14
src/index.ts
@@ -1,5 +1,5 @@
|
|||||||
import type { Plugin } from "@opencode-ai/plugin"
|
import type { Plugin } from "@opencode-ai/plugin"
|
||||||
import { builtinAgents } from "./agents"
|
import { createBuiltinAgents, type AgentName, type AgentOverrides } from "./agents"
|
||||||
import { createTodoContinuationEnforcer, createContextWindowMonitorHook, createSessionRecoveryHook } from "./hooks"
|
import { createTodoContinuationEnforcer, createContextWindowMonitorHook, createSessionRecoveryHook } from "./hooks"
|
||||||
import { updateTerminalTitle } from "./features/terminal"
|
import { updateTerminalTitle } from "./features/terminal"
|
||||||
import { builtinTools } from "./tools"
|
import { builtinTools } from "./tools"
|
||||||
@@ -9,6 +9,8 @@ import * as path from "path"
|
|||||||
|
|
||||||
interface OhMyOpenCodeConfig {
|
interface OhMyOpenCodeConfig {
|
||||||
disabled_mcps?: McpName[]
|
disabled_mcps?: McpName[]
|
||||||
|
disabled_agents?: AgentName[]
|
||||||
|
agents?: AgentOverrides
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadPluginConfig(directory: string): OhMyOpenCodeConfig {
|
function loadPluginConfig(directory: string): OhMyOpenCodeConfig {
|
||||||
@@ -48,9 +50,14 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
|
|||||||
tool: builtinTools,
|
tool: builtinTools,
|
||||||
|
|
||||||
config: async (config) => {
|
config: async (config) => {
|
||||||
|
const agents = createBuiltinAgents(
|
||||||
|
pluginConfig.disabled_agents,
|
||||||
|
pluginConfig.agents
|
||||||
|
)
|
||||||
|
|
||||||
config.agent = {
|
config.agent = {
|
||||||
...config.agent,
|
...config.agent,
|
||||||
...builtinAgents,
|
...agents,
|
||||||
}
|
}
|
||||||
config.tools = {
|
config.tools = {
|
||||||
...config.tools,
|
...config.tools,
|
||||||
@@ -176,3 +183,6 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default OhMyOpenCodePlugin
|
export default OhMyOpenCodePlugin
|
||||||
|
|
||||||
|
export type { AgentName, AgentOverrideConfig, AgentOverrides } from "./agents"
|
||||||
|
export type { McpName } from "./mcp"
|
||||||
|
|||||||
Reference in New Issue
Block a user