Skip to content

Fix Tool type to support interface return types #281

@Unshure

Description

@Unshure

I am currently testing the creation of an agent. I am trying to return a list of products to my agent, the type definition for my product is:

interface Product {
  id: string;
  name: string;
  price: number;
  stock: number;
}

When I create a tool that returns a set of products:

const viewCatalog = tool({
  name: 'view_catalog',
  description: 'Shows all available products in the catalog',
  inputSchema: z.object({ category: z.string() }),
  callback: () => {
    const products = database.products;
    return { products, totalProducts: products.length };
  }
});

TS is not happy at all. Because is considers Product is not compatible with JSONValue. What I needed to do to fix this:

  • Change interface to type
  • OR, add [key: string]: any; to my Interface

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions