Skip to content

feat(agent): add structured output, compaction, dynamic tools, usage hooks, and depth limit - #42

Merged
dylnslck merged 4 commits into
mainfrom
feat/agent-parity
Oct 24, 2026
Merged

dylnslck merged 4 commits into
mainfrom
feat/agent-parity

Conversation

@dylnslck

Copy link
Copy Markdown
Contributor

Problem and change

Brings the Looms agent loop to parity with @swirls/agent and executor requirements:

  1. Structured output: First-class output schema on AgentDefinition providing the schema-validated submit_output tool with automatic error feedback for validate-and-repair loops, and completing the thread with the validated object.
  2. Context compaction: Context compaction hook (compact) and checkpoint event (agent.context.compacted), with automatic single overflow compact-and-retry when the model returns a context window exceeded error.
  3. Dynamic tool sets per turn: resolveTools hook resolving dynamic tools (such as MCP tools or skills) per turn.
  4. Usage hooks and credit gate: Pre-turn credit gate (assertCredits) failing the turn cleanly on credit exhaustion, post-turn usage tracking (trackUsage), and durable agent.turn.usage event.
  5. Subagent depth limit: Enforces TEAM_MEMBER_MAX_DEPTH = 3, returning an explicit tool error when an agent attempts to spawn subagents beyond depth 3.

Review notes

All agent features are backwards compatible. Agents without output or resolveTools run with existing behavior.

Checked with bun x tsc -p packages/agent/tsconfig.build.json --noEmit, bun x oxlint --deny-warnings across modified sources, and bun test src in packages/agent, packages/ai-vercel, packages/workflow, and packages/runtime. bun run verify was not run.

Existing contributor checklist

  • bun run verify passes
  • Changeset added if @swirls/looms behavior changes (bun run changeset)
  • Docs updated for API / architecture changes

Made with Cursor

dylnslck and others added 4 commits October 23, 2026 12:35
…hooks, and depth limit

Add first-class structured output via submit_output tool, context compaction with single overflow retry, dynamic tool resolution per turn, pre-turn credit gate assertCredits, post-turn usage tracking with agent.turn.usage, and TEAM_MEMBER_MAX_DEPTH = 3 subagent depth enforcement.

Co-authored-by: Cursor <cursoragent@cursor.com>
…esolution

Depth was merged into the child's input, where input schemas stripped it (so nested agents never hit the limit) and inputToLine leaked it into the prompt. The parent now sends an agent.lineage event to agent children instead.

Model calls and tool execution resolve tools through one helper with the agent input, so a dynamic tool is found when it runs, and resolution failures become tool errors. The new callbacks use method syntax so specific agent definitions stay assignable to AgentDefinition, which had broken the examples and the demo. The default compactor no longer keeps a tool result without its request, overflow detection no longer matches any 'overflow', and trackUsage failures are logged. End-to-end tests run each feature on the runtime.

Co-authored-by: Cursor <cursoragent@cursor.com>
@dylnslck
dylnslck merged commit edd3c5c into main Oct 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant