SkillKit.Agent.ToolDispatch (SkillKit v0.1.0)

Copy Markdown View Source

Tool execution dispatch. Classifies, executes, and returns results for tool calls from the LLM. Handles plain tools, skill activation, and subagent spawning.

execute_one/2 runs a single tool call and returns {result, side_effects} where side effects are tagged tuples applied by ToolRunner after collection. This design supports parallel execution — children can't share or modify Server state, so state changes are deferred as data.

Skill activation runs the skill as a forked sub-conversation in the parent agent's process via SkillKit.Agent.SkillActivation. The parent receives the sub-loop's final text as the activate_skill tool's result. No child agent supervision tree is spawned.

Subagent delegation returns immediately (the subagent runs independently). Tools that need external input return {:suspended, execution, side_effects} to suspend rather than blocking.

Summary

Functions

Builds the context map passed to Tool.execute/1 for a given tool call name.

Executes a single tool call. Returns {result, side_effects} or {:suspended, execution, side_effects}.

Types

side_effect()

@type side_effect() :: {:subagent, pid(), map()}

Functions

build_context(state, tool_name)

Builds the context map passed to Tool.execute/1 for a given tool call name.

The context contains:

  • :agent — the full agent struct (scope, name, etc.).
  • :agent_name — the root agent's name. For an activate_skill child this is the parent's name, not the ephemeral child name — so state that outlives the child (e.g. a webhook registration) is bound to the right agent.
  • :scope — shortcut to agent.scope.
  • Tool-specific metadata merged in (e.g., :cwd, :env for Shell; :supervisor, :verifiers for Webhook).

execute_one(state, tc)

Executes a single tool call. Returns {result, side_effects} or {:suspended, execution, side_effects}.

Side effects are applied by ToolRunner after collection.