Skip to content

feat(skill): add context mode (fork/isolate) and model frontmatter support#739

Merged
hi-pender merged 14 commits intoalpha/08from
feat/skill_frontmatter
Feb 4, 2026
Merged

feat(skill): add context mode (fork/isolate) and model frontmatter support#739
hi-pender merged 14 commits intoalpha/08from
feat/skill_frontmatter

Conversation

@hi-pender
Copy link
Contributor

Summary

This PR extends the skill middleware to support new frontmatter fields: context, agent, and model. These fields enable skills to run in different execution modes with configurable agents and models.

New Frontmatter Fields

Field Type Description
context string Execution mode: fork or isolate
agent string Agent name to use (retrieved from AgentHub)
model string Model name to use (retrieved from ModelHub)

Context Modes

Inline Mode (default)

When context is not specified or has other values, the skill content is returned directly to the parent agent as tool result.

Fork Mode (context: fork)

  • Creates a new agent to execute the skill
  • Forks the parent agent's message history
  • Appends skill content as a tool message to the forked history
  • Returns the agent's output as the tool result

Isolate Mode (context: isolate)

  • Creates a new agent to execute the skill
  • Starts with a clean message history (isolated from parent)
  • Uses skill content as a user message
  • Returns the agent's output as the tool result

New Config Fields

type Config struct {
    Backend       Backend
    SkillToolName *string
    UseChinese    bool
    
    // AgentHub provides agent factories for context mode (fork/isolate) execution.
    // Required when skills use "context: fork" or "context: isolate" in frontmatter.
    // The agent factory is retrieved by agent name (skill.Agent) from this hub.
    // When skill.Agent is empty, AgentHub.Get is called with an empty string,
    // allowing the hub implementation to return a default agent.
    AgentHub AgentHub
    
    // ModelHub provides model instances for skills that specify a "model" field in frontmatter.
    // Currently only used with context mode (fork/isolate).
    // If nil, skills with model specification will return an error.
    ModelHub ModelHub
}

New Interfaces

// AgentFactory creates an agent with the given model.
// The model parameter may be nil if no model is specified in the skill frontmatter.
type AgentFactory func(ctx context.Context, m model.ToolCallingChatModel) (adk.Agent, error)

// AgentHub provides agent factories by name.
type AgentHub interface {
    Get(ctx context.Context, name string) (AgentFactory, error)
}

// ModelHub provides model instances by name.
type ModelHub interface {
    Get(ctx context.Context, name string) (model.ToolCallingChatModel, error)
}

Usage Example

SKILL.md with context mode

---
name: code-review
description: Review code and provide suggestions
context: fork
agent: code-reviewer
model: gpt-4
---

Review the code following these guidelines:
1. Check for bugs and security issues
2. Suggest improvements
...

Configuration

// Implement AgentHub
type myAgentHub struct{}

func (h *myAgentHub) Get(ctx context.Context, name string) (skill.AgentFactory, error) {
    return func(ctx context.Context, m model.ToolCallingChatModel) (adk.Agent, error) {
        if m == nil {
            m = defaultModel // use default model if not specified
        }
        return adk.NewChatModelAgent(ctx, &adk.ChatModelAgentConfig{
            Name:  name,
            Model: m,
            // ... other config
        })
    }, nil
}

// Implement ModelHub
type myModelHub struct{}

func (h *myModelHub) Get(ctx context.Context, name string) (model.ToolCallingChatModel, error) {
    switch name {
    case "gpt-4":
        return openai.NewChatModel(ctx, &openai.ChatModelConfig{Model: "gpt-4"})
    default:
        return nil, fmt.Errorf("unknown model: %s", name)
    }
}

// Create skill handler
handler, err := skill.NewHandler(ctx, &skill.Config{
    Backend:  backend,
    AgentHub: &myAgentHub{},
    ModelHub: &myModelHub{},
})

// Use in ChatModelAgent
agent, err := adk.NewChatModelAgent(ctx, &adk.ChatModelAgentConfig{
    // ...
    Handlers: []adk.ChatModelAgentMiddleware{handler},
})

Notes

  • The model frontmatter currently only takes effect when context mode is specified
  • When agent is empty, AgentHub.Get("") is called, allowing the hub to return a default agent
  • The deprecated New function does not support context mode; use NewHandler instead

@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 11.53846% with 115 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (alpha/08@32a57da). Learn more about missing BASE report.

Files with missing lines Patch % Lines
adk/middlewares/skill/skill.go 8.13% 110 Missing and 3 partials ⚠️
adk/middlewares/skill/filesystem_backend.go 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             alpha/08     #739   +/-   ##
===========================================
  Coverage            ?   79.71%           
===========================================
  Files               ?      145           
  Lines               ?    15745           
  Branches            ?        0           
===========================================
  Hits                ?    12551           
  Misses              ?     2218           
  Partials            ?      976           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hi-pender hi-pender force-pushed the feat/skill_frontmatter branch from 07ba94e to 938029f Compare February 3, 2026 14:19
@hi-pender hi-pender force-pushed the feat/skill_frontmatter branch 2 times, most recently from 5fd9626 to c296c36 Compare February 4, 2026 07:34
@hi-pender hi-pender force-pushed the feat/skill_frontmatter branch from 7e09f14 to 7a3fd1f Compare February 4, 2026 12:44
@hi-pender hi-pender merged commit 2adf661 into alpha/08 Feb 4, 2026
14 checks passed
@hi-pender hi-pender deleted the feat/skill_frontmatter branch February 4, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant