Sort
Order arrays using model reasoning. Returns sorted array, index mapping, reasoning, and fallback flags.
Signature
1sort<T>(array: T[], instructions?: string, useContext?: boolean): Promise<{ array: T[]; indexes: number[]; reasoning?: string; warning?: string; fallback?: boolean; }>
Basic sort
1const items = ['Alpha', 'Beta', 'Gamma'];
2
3const response = await agent.sort(items);
4
5console.log(response.array);
With instructions
1const products = [
2 { name: 'Eco', price: 12 },
3 { name: 'Steel', price: 25 }
4];
5
6await agent.sort(products, 'Order by projected conversion likelihood'); // [{ name: 'Eco', price: 12 }, { name: 'Steel', price: 25 }];
7
Inspect reasoning
1const response = await agent.sort(['Basic plan', 'Pro plan'], 'Order by enterprise appeal');
2
3console.log(response.reasoning); // Enterprise plans are typically more appealing to larger organizations due to their advanced features and support.
Common issues
- Long, ambiguous instructions.
- Fallback may return original ordering on error.