Skip to content

Implement Explicit Prototypal Agent Extends #63

@riatzukiza

Description

@riatzukiza

Summary

This feature adds inheritance support to Markdown-based agent definitions in Opencode, allowing agents to extend and override parent agents.

Context

  • packages/opencode/src/config/config.ts:203-244 currently loads Markdown-Based agent definitions but only builds flat objects; nested folders simply prefix the agent name. There is no notion of inheritance between agent files.
  • packages/opencode/src/config/config.ts:348-370 defines the Agent zod schema without an extends field, so frontmatter cannot declare parentage.
  • packages/opencode/src/agent/agent.ts:97-172 merges built-in agents with user-defined entries. This would be the point where resolved inheritance chains need to be flattened into the final runtime Agent.Info map.
  • packages/opencode/src/config/markdown.ts:6-32 holds the existing path token logic (@ references) used elsewhere for file/wiki-like references; a similar resolver (but using [[wiki/style]] tokens with shortest-unique paths) is needed for the new extends syntax.

Requirements

  1. Support an optional extends frontmatter field inside agent Markdown files. The value uses wiki-link syntax ([[agent-path]]) that should resolve to another agent file.
  2. Path resolution must allow referencing agents by the shortest unique suffix (e.g., [[auth]], [[nested/auth]]). When two different folders contain auth.md, automatically expand the link to the minimal path segments needed to uniquely identify the target, similar to Obsidian-style wiki links.
  3. When extends is present, the child agent inherits all prompt content, metadata, permissions, tools, and options from the referenced parent unless explicitly overridden in the child file. Circular references must be detected and reported as a configuration error.
  4. Update runtime agent assembly so inherited properties are merged before Agent.Info objects are consumed by the TUI, commands, or SDK consumers. Ensure disable: true still removes agents even if other agents attempt to extend them.
  5. Document the new capability (docs page + sample snippet) and add automated tests (unit tests in packages/opencode/test/config) that cover successful inheritance, conflict resolution when duplicates exist, and error cases for unresolved/ambiguous wiki links.

Definition of Done

  • Agent schema validates extends values and errors with helpful messages for invalid wiki links or circular parentage.
  • Wiki-link resolver can find any agent Markdown file via the shortest unambiguous [[path]], even when duplicate filenames exist under different folders.
  • Child agent inherits parent settings and prompt text before being exposed through Agent.list() / CLI UI; overrides replace the inherited values as expected.
  • Comprehensive tests cover resolver behavior, inheritance merging, and failure paths, and all existing tests continue to pass.
  • Documentation (docs + changelog/README snippet if applicable) explains how to declare extends: [[agent-name]] and how conflicts are handled.

Implementation Files Referenced

  • packages/opencode/src/config/config.ts:203-244
  • packages/opencode/src/config/config.ts:348-370
  • packages/opencode/src/agent/agent.ts:97-172
  • packages/opencode/src/config/markdown.ts:6-32

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions