Skip to content

LOU-X1: defineTool with inferred types - #39

Merged
LinuxDevil merged 2 commits into
mainfrom
lou-x1-define-tool
Oct 1, 2026
Merged

LinuxDevil merged 2 commits into
mainfrom
lou-x1-define-tool

Conversation

@LinuxDevil

Copy link
Copy Markdown
Owner

What

defineTool({ name, description, input, needsApproval, execute, displayName, requiresSandbox, sandboxExecute }): one function with full inference. execute/needsApproval args are typed from z.output<input>, the execute return type is preserved (ToolInput<typeof t> / ToolOutput<typeof t>). The result is a ToolDescriptor, accepted by createAgent({ tools: [t] }) (array and existing record form), ToolRegistry.register(t) / registerMany([...]), and AgentBuilder.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: clean
  • npm run lint: 0 errors (439 warnings, none added)
  • npm run build + create-loushy-agent build: success
  • npm run test:coverage: 89 files passed; all-files 83.61 / 87.28 / 86.01 / 83.61, thresholds met
  • npm run fallow: exit 0 (no issues, no duplication)
  • npm run docs:verify-snippets: all 5 snippet(s) type-check and run cleanly
  • New npm run test:types (vitest typecheck of *.test-d.ts): 4 passed, no type errors

Notes for reviewer

  • Compile-time assertions live in src/tools/defineTool.test-d.ts (excluded from tsc/build in tsconfig, added as a fallow entry); run with npm run test:types. Not wired into CI.
  • ctx is typed as the AI SDK ToolExecutionOptions, but sandboxGuard currently passes {} at runtime (pre-existing); populating it needs toolCallExecution.ts, left alone. Follow-up candidate.
  • GitHubTools/JiraTools override register; they gained the single-arg overload to stay type-compatible.
  • The (name, descriptor) form keeps its warn-and-overwrite behavior; only register(tool) throws on duplicates.

🤖 Generated with Claude Code

LinuxDevil and others added 2 commits October 1, 2026 09:05
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>
@LinuxDevil
LinuxDevil merged commit 6ebacd1 into main Oct 1, 2026
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