Skip to content

fix(#37): add proper type inference to functional tool parameters t…#40

Merged
copybara-service[bot] merged 1 commit into
google:mainfrom
jagadhis:fix/replace-any-type-in-toolinputparameters
Dec 30, 2025
Merged

fix(#37): add proper type inference to functional tool parameters t…#40
copybara-service[bot] merged 1 commit into
google:mainfrom
jagadhis:fix/replace-any-type-in-toolinputparameters

Conversation

@jagadhis
Copy link
Copy Markdown
Contributor

Summary:

This PR replaces any types in FunctionTool with proper Zod generics, enabling automatic type inference from schemas to execute functions.

Changes

  • Replaced ZodObject<any> with ZodObject<ZodRawShape> in ToolInputParameters
  • Updated ToolExecuteArgument to properly infer types using infer T, U, V
  • Removed unnecessary any cast in constructor

Impact

const tool = new FunctionTool({
  parameters: z.object({ 
    studentId: z.number(),
    name: z.string()
  }),
  execute: async ({ studentId, name }) => {
    // studentId and name are now automatically typed from schema
    return { studentId, name };
  },
});

Testing

Added test to verify type inference works without explicit type annotations. All existing tests continue to pass.

Benefits

  • Automatic type inference from Zod schemas
  • Full autocomplete/IntelliSense support
  • Compile-time type checking

Fixes #37

Comment thread core/test/tools/function_tool_test.ts Outdated
@jagadhis jagadhis force-pushed the fix/replace-any-type-in-toolinputparameters branch from efc072d to e5812a6 Compare December 24, 2025 08:36
@jagadhis jagadhis force-pushed the fix/replace-any-type-in-toolinputparameters branch from e5812a6 to 0afb8f3 Compare December 24, 2025 08:38
@jagadhis jagadhis requested a review from kalenkevich December 24, 2025 08:41
@jagadhis
Copy link
Copy Markdown
Contributor Author

@kalenkevich Thanks for the approval! The comment has been resolved and the branch is now rebased with main. can you re-approve it again

@kalenkevich kalenkevich added the ready to pull Ready to pull for final review. label Dec 30, 2025
@copybara-service copybara-service Bot merged commit a102e3e into google:main Dec 30, 2025
3 checks passed
@jagadhis jagadhis deleted the fix/replace-any-type-in-toolinputparameters branch December 30, 2025 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to pull Ready to pull for final review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace 'any' type in ToolInputParameters with proper generic constraints

2 participants