SkillKit.Agent.SkillActivation (SkillKit v0.1.0)

Copy Markdown View Source

Runs an activated skill as a forked sub-conversation in the parent agent's process.

A skill activation is not a new agent and does not spawn a new supervision tree. Instead, it runs a synchronous LLM loop in-process using a forked copy of the parent's messages and an expanded tool list.

The sub-loop:

  • Uses the parent's system prompt with the rendered skill body appended.
  • Inherits the parent's :tools and adds the skill's underlying tool module (deduplicated by module).
  • Does NOT expose activate_skill or subagent-delegation tools — nested skill activation is not supported.
  • Loops LLM.stream/2 plus in-process tool execution until the LLM returns a final assistant message with no tool calls.
  • Returns that final text as the activate_skill tool's result.

Events streamed by the sub-loop (%Delta{}, tool call events, tool results, token usage) are forwarded to the parent's caller pid tagged with a synthetic agent name "<parent>/skill:<skill_name>", so chat printers that match by agent-name prefix surface them alongside the parent's own events.

Wrapped in Hooks.call(:skill_activation) so [:skill_kit, :skill_activation, :start/:stop] telemetry fires and :pre_skill_activation / :post_skill_activation hooks can observe or deny the activation.

Implementation

The LLM + tool-dispatch loop is the shared SkillKit.Agent.SubLoop primitive. This module's responsibility is preparing the skill-specific scope (tool list with skill's tool appended, fork the parent messages to drop the trailing activate_skill tool use, compose the skill-prefixed sub-agent name) and wrapping the run in the :skill_activation hook.

Summary

Functions

Resolves the skill named in input["name"], renders its body in the parent's scope, and runs it as a sub-loop. Used by both the parent agent's tool dispatcher and event sub-loops that opt into activate_skill exposure.

Functions

dispatch(parent_state, tool_call_id, input)

Resolves the skill named in input["name"], renders its body in the parent's scope, and runs it as a sub-loop. Used by both the parent agent's tool dispatcher and event sub-loops that opt into activate_skill exposure.

Returns a %ToolResult{} (always — errors are formatted as error results, not raised).

run(parent_state, skill, body, tool_call_id)