Skip to content

Add SkillExecutor.Hybrid() skill script execution mode in AgentSkills sample #4133

@SergeyMenshykh

Description

@SergeyMenshykh

Summary

Add support for conditional routing of skill script execution between the hosted code interpreter and a user-provided executor, encapsulated as SkillExecutor.Hybrid(). This mode lives in the AgentSkills sample project, not in the Microsoft.Agents.AI library.

Background

With SkillExecutor.HostedCodeInterpreter() (#4131) and SkillExecutor.External() (#4132) established in the core library, this issue adds a third execution mode that conditionally routes each script to one of the two based on a user-provided predicate. This mode lives in the AgentSkills sample project and serves as a reference for how to extend SkillExecutor from consuming code. This is the third of three planned execution modes:

  1. SkillExecutor.HostedCodeInterpreter() — LLM code interpreter (Add SkillExecutor.HostedCodeInterpreter() skill script execution mode #4131)
  2. SkillExecutor.External() — user-provided executor (Add SkillExecutor.External() skill script execution mode #4132)
  3. SkillExecutor.Hybrid() ← this issue (sample only)

Requirements

  • Add a static Hybrid() factory method on SkillExecutor in the AgentSkills sample project that accepts:
    • A route selector predicate — given script context (extension, skill name, etc.), returns whether to use the hosted code interpreter or the external executor.
    • A user-provided execution delegate — called when the route selector chooses external execution.
  • The Hybrid mode (concrete sealed subclass) must:
    • Provide instructions that direct the LLM to call resolve_executor before executing a script to determine which execution path to use.
    • Register both resolve_executor and execute_script tools.
    • When resolve_executor is invoked, call the route selector predicate and return the result to the LLM.
    • When execute_script is invoked, delegate to the user-provided execution callback.
  • This class should not be added to Microsoft.Agents.AI. It should demonstrate how to extend SkillExecutor from consuming code.
  • The execute_script tool should be wrapped with ApprovalRequiredAIFunction by default to require user approval before executing scripts externally.
    • The Hybrid() factory method should accept an optional parameter to disable approval (e.g., requireApproval: bool = true). When enabled: new
      ApprovalRequiredAIFunction(AIFunctionFactory.Create(executeScript)). When disabled, the tool is registered directly.
    • Note: resolve_executor does not require approval as it only determines routing, not execution.

Acceptance Criteria

  • Hybrid() static factory method implemented in the AgentSkills sample project
  • Hybrid mode is a sealed concrete subclass of SkillExecutor
  • Hybrid mode registers resolve_executor and execute_script tools
  • resolve_executor invocations delegate to the user-provided route selector predicate
  • execute_script invocations delegate to the user-provided execution callback
  • Hybrid mode provides instructions guiding the LLM to call resolve_executor before script execution
  • Sample demonstrates usage with routing based on script extension or skill name
  • Serves as a reference for extending SkillExecutor outside the core library
  • execute_script tool is wrapped with ApprovalRequiredAIFunction by default
    • Approval can be disabled via Hybrid(routeSelector, execute, requireApproval: false)
    • resolve_executor tool does not require approval
    • Unit tests cover both approval-enabled and approval-disabled paths

Part of #3499
Depends on #4131 and #4132

Metadata

Metadata

Labels

No labels
No labels

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions