Repository navigation
feat(agent): add structured output, compaction, dynamic tools, usage hooks, and depth limit - #42
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and change
Brings the Looms agent loop to parity with
@swirls/agentand executor requirements:outputschema onAgentDefinitionproviding the schema-validatedsubmit_outputtool with automatic error feedback for validate-and-repair loops, and completing the thread with the validated object.compact) and checkpoint event (agent.context.compacted), with automatic single overflow compact-and-retry when the model returns a context window exceeded error.resolveToolshook resolving dynamic tools (such as MCP tools or skills) per turn.assertCredits) failing the turn cleanly on credit exhaustion, post-turn usage tracking (trackUsage), and durableagent.turn.usageevent.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
outputorresolveToolsrun with existing behavior.Checked with
bun x tsc -p packages/agent/tsconfig.build.json --noEmit,bun x oxlint --deny-warningsacross modified sources, andbun test srcinpackages/agent,packages/ai-vercel,packages/workflow, andpackages/runtime.bun run verifywas not run.Existing contributor checklist
bun run verifypasses@swirls/loomsbehavior changes (bun run changeset)Made with Cursor