Tool Categories

Updated

Categories let you organize tools into logical groups. Access category methods through the chaos.tools.categories sub-namespace. All four CRUD operations are supported.

list(params?)

Retrieve a paginated list of categories. Optionally filter by search keyword.

Signature:

categories.list(params?: ToolCategoryListParams): Promise<ToolCategoryListResponse>
list-categories.ts
import { Chaos } from '@chaoslabs/ai-sdk';
 
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
 
// List all categories
const { data: categories, total } = await chaos.tools.categories.list();
console.log(`${total} categories`);
 
for (const cat of categories) {
  console.log(`${cat.name} (${cat.id})`);
}
 
// Paginate
const page2 = await chaos.tools.categories.list({ page: 2, limit: 10 });
 
// Search by keyword
const defiCats = await chaos.tools.categories.list({ search: 'DeFi' });

ToolCategoryListParams

FieldTypeRequiredDescription
pagenumberNoPage number
limitnumberNoResults per page
searchstringNoKeyword search filter

create(params)

Create a new tool category. At minimum, provide a name. Additional properties are accepted and passed through to the API.

Signature:

categories.create(params: CreateToolCategoryParams): Promise<ToolCategory>
create-category.ts
import { Chaos } from '@chaoslabs/ai-sdk';
 
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
 
const defiCat = await chaos.tools.categories.create({ name: 'DeFi Protocols' });
const dataCat = await chaos.tools.categories.create({ name: 'Data & Analytics' });
const riskCat = await chaos.tools.categories.create({ name: 'Risk Management' });
 
console.log(`Created: ${defiCat.name} (${defiCat.id})`);
console.log(`Created: ${dataCat.name} (${dataCat.id})`);
console.log(`Created: ${riskCat.name} (${riskCat.id})`);

update(categoryId, params)

Update a category's properties. Currently supports updating the name.

Signature:

categories.update(categoryId: string, params: UpdateToolCategoryParams): Promise<ToolCategory>
update-category.ts
import { Chaos } from '@chaoslabs/ai-sdk';
 
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
 
const updated = await chaos.tools.categories.update('cat-id', {
  name: 'DeFi Protocol Tools',
});
 
console.log(`Renamed to: ${updated.name}`);

delete(categoryId)

Remove a category.

Signature:

categories.delete(categoryId: string): Promise<void>
delete-category.ts
import { Chaos } from '@chaoslabs/ai-sdk';
 
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
 
await chaos.tools.categories.delete('cat-id');
console.log('Category deleted');
[@portabletext/react] Unknown block type "callout", specify a component for it in the `components.types` prop

Full Example: Organize a Tool Registry

Create categories, register tools, then list tools by category:

organize-registry.ts
import { Chaos } from '@chaoslabs/ai-sdk';
 
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
 
// Set up categories
const defiCat = await chaos.tools.categories.create({ name: 'DeFi Protocols' });
const dataCat = await chaos.tools.categories.create({ name: 'Data & Analytics' });
 
// Register tools
await chaos.tools.create({
  name: 'uniswap-pool-analyzer',
  description: 'Analyzes Uniswap V3/V4 pool liquidity and fee tiers',
});
 
await chaos.tools.create({
  name: 'aave-rate-monitor',
  description: 'Monitors Aave lending and borrowing rates across markets',
});
 
await chaos.tools.create({
  name: 'token-price-aggregator',
  description: 'Aggregates token prices from multiple on-chain and off-chain sources',
});
 
// List tools filtered by category
const { data: defiTools } = await chaos.tools.list({ categoryId: defiCat.id });
console.log(`DeFi tools: ${defiTools.length}`);
 
// Search across all tools
const results = await chaos.tools.searchHybrid({
  queries: ['lending rates', 'token prices'],
});
 
for (const r of results) {
  console.log(`"${r.query}" matched ${r.results.length} tools`);
}
Was this helpful?