Modular Agents
Modular agent support for OpenCode — define agents as folders with multiple prompt files
1
51
近 7 天 11
28.1
生态多维模型
3 个月前
2026-07-02
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["modular-agents@0.1.5"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["modular-agents@0.1.5"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D modular-agentsOpenCode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
Define agents as folders with multiple maintainable prompt files.
Features
- Agents as folders instead of single files
- Recursively includes all
.mdand.txtfiles - Supports all agent configuration fields via YAML frontmatter
- Works alongside native single-file agents
Installation
From npm (Recommended)
opencode plugin modular-agents --global
Or add it to your opencode.json:
{
"plugin": ["modular-agents"]
}
Local Development
Place modular-agents.ts and package.json in:
.opencode/plugins/(project level)- or
~/.config/opencode/plugins/(global)
Usage
Create folders inside .opencode/agents/ (project) or ~/.config/opencode/agents/ (global).
Folder Structure Example
.opencode/agents/rust-expert/
├── index.md # Recommended
├── rules/
│ ├── core.md
│ └── security.md
├── examples/
│ └── good-patterns.md
├── constraints.md
└── test/
└── index.md # Included as normal content
index.md – Recommended, Not Strictly Required
- If
index.mdexists in the folder root, OpenCode parses it (frontmatter + base prompt). - The plugin then enriches that prompt with all other
.md/.txtfiles found recursively. - If there is no
index.md, the plugin will still create the agent using the folder name and all other files as the prompt. This is useful for trait-only / composable agents.
Example without index.md (trait composition):
.opencode/agents/code-reviewer/
├── pragmatic.txt
├── security-focused.txt
└── concise.txt
This creates an agent called code-reviewer composed purely from the trait files.
How Files Are Merged
- OpenCode handles the
index.md(if present). - The plugin appends every other
.mdand.txtfile (includingindex.mdfiles inside subfolders). - YAML frontmatter in additional files is stripped.
- Files are sorted alphabetically by relative path.
- Subfolder
index.mdfiles become regular sections (e.g.### test/index.md).
Resulting Prompt
You are a senior Rust developer...
### constraints.md
...
### rules/core.md
...
### test/index.md
...
This design lets you build large, maintainable agents from smaller reusable pieces.
Limitations
- Changes require restarting the session.
- Best suited for complex or large agents.
License
This project is open source and available under the MIT license.
同类生态推荐
Tell Sessions
opencode-tell-sessions
Inter-session direct messaging (DM) for OpenCode V1 & V2: agents in different sessions can message each other
Caveman
@miguelmartens/opencode-caveman
Caveman for OpenCode: terse output mode, always on, with /caveman level switching. why use many token when few do trick.
Fusion
@carson2222/fusion
Fan a hard prompt out to a panel of models in parallel as read-only explorers, then aggregate their findings into one answer. An OpenCode plugin.