Repository navigation
LOU-X1: defineTool with inferred types - #39
Merged
Merged
Conversation
Adds defineTool({ name, description, input, needsApproval, execute, ... }):
one function, args typed from the zod input (output type), execute return
type preserved, with ToolInput/ToolOutput helper types. The result is a
ToolDescriptor, so it works anywhere tools are accepted today.
- createAgent({ tools }) accepts an array of defined tools (plus the
existing record form); AgentBuilder.addTool(tool); ToolRegistry
.register(tool) / registerMany([...]) alongside (name, descriptor).
- Definition-time validation of name (^[a-zA-Z0-9_-]{1,64}$), description,
zod input and execute; duplicate names throw an error naming both tools.
- Type tests (vitest typecheck, npm run test:types) and runtime tests.
- Docs: README, docs/quick-start.md, docs/api-overview.md lead with defineTool.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.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.
What
defineTool({ name, description, input, needsApproval, execute, displayName, requiresSandbox, sandboxExecute }): one function with full inference.execute/needsApprovalargs are typed fromz.output<input>, theexecutereturn type is preserved (ToolInput<typeof t>/ToolOutput<typeof t>). The result is aToolDescriptor, accepted bycreateAgent({ tools: [t] })(array and existing record form),ToolRegistry.register(t)/registerMany([...]), andAgentBuilder.addTool(t); delegation works through the registry.Why
Defining a tool took two concepts plus a registry, and README's
needsApproval: (args) => ...had untyped args.How verified
npx tsc --noEmit: cleannpm run lint: 0 errors (439 warnings, none added)npm run build+ create-loushy-agent build: successnpm run test:coverage: 89 files passed; all-files 83.61 / 87.28 / 86.01 / 83.61, thresholds metnpm run fallow: exit 0 (no issues, no duplication)npm run docs:verify-snippets: all 5 snippet(s) type-check and run cleanlynpm run test:types(vitest typecheck of*.test-d.ts): 4 passed, no type errorsNotes for reviewer
src/tools/defineTool.test-d.ts(excluded fromtsc/build in tsconfig, added as a fallow entry); run withnpm run test:types. Not wired into CI.ctxis typed as the AI SDKToolExecutionOptions, butsandboxGuardcurrently passes{}at runtime (pre-existing); populating it needstoolCallExecution.ts, left alone. Follow-up candidate.GitHubTools/JiraToolsoverrideregister; they gained the single-arg overload to stay type-compatible.(name, descriptor)form keeps its warn-and-overwrite behavior; onlyregister(tool)throws on duplicates.🤖 Generated with Claude Code