SIGN IN SIGN UP

feat(quickjs): add swarm task tool (#500)

### Summary

Adds the swarm task tool to @langchain/quickjs and fixes skill module
loading for the agentskills.io spec, enabling parallel subagent dispatch
from inside the QuickJS code interpreter.

Swarm task tool (tools/swarm-task.ts) is a PTC-only tool that bridges
the code interpreter to the host runtime for subagent dispatch. It
supports two modes:
1. Direct model calls with structured output (invoke mode) for
classification/extraction tasks
2. Full agentic loops with tools (agent mode) for multi-step reasoning.
It handles schema normalization, model variant caching with TTL-based
sweeping, and structured output binding.

Spec-compliant entrypoint resolution — loadSkill() now resolves the
entrypoint from metadata.entrypoint (the agentskills.io extension point)
first, falling back to the legacy top-level module field. This lets
skills use spec-compliant frontmatter without a top-level module key.

Subdirectory entrypoint support — the QuickJS module normalizer now uses
the entrypoint's directory (not the skill root) when resolving relative
imports from a bare specifier. This fixes import { ... } from
"./sibling.js" when the entrypoint lives in a subdirectory like
scripts/index.ts.

Supporting changes include wiring skills metadata through the middleware
and session layers, extending the transform pipeline to strip import
type/export type declarations, adding requiredPtcTools validation, and
session improvements (extractToolText, stripLineNumbers, __sessionId__).

The swarm skill itself (table management, batching, filtering,
interpolation) is distributed separately and not included here.

### Tests
- 41 tests for the swarm task tool covering both dispatch modes, schema
normalization, variant caching and TTL sweeping, error handling, and
edge cases around model binding
- 3 new tests for entrypoint resolution (metadata.entrypoint preferred
over module, subdirectory relative imports)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
C
Colin Francis committed
bfb6eecdfe617645b3bdebf9a60d4b08e575cef7
Parent: 945b362
Committed by GitHub <noreply@github.com> on 5/19/2026, 6:43:04 PM