agent-swarm-kit 1.1.128 → 1.1.130

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -451,6 +451,64 @@ addTool({
451
451
 
452
452
  ---
453
453
 
454
+ # 📝 Structured JSON Output With Validation
455
+
456
+ Create structured JSON outputs with precise schemas and robust validation! 📝 Ensure AI responses meet your needs with custom rules and automatic retries. 🔄 Integrate seamlessly with OpenAI, Ollama, or Claude. 🌐 Dynamic history guides consistent results for workflows or chatbots. 🗂️ Simple TypeScript API scales effortlessly with error recovery. 🛠️
457
+
458
+ ```tsx
459
+ import { addOutlineSchema, IOutlineFormat } from "agent-swarm-kit";
460
+
461
+ const format: IOutlineFormat = {
462
+ type: "object",
463
+ properties: {
464
+ take_profit_price: { type: "number", description: "Take profit price in USD" },
465
+ stop_loss_price: { type: "number", description: "Stop-loss price in USD" },
466
+ description: { type: "string", description: "User-friendly explanation of risks, min 10 sentences" },
467
+ reasoning: { type: "string", description: "Technical analysis, min 15 sentences" },
468
+ },
469
+ required: ["take_profit_price", "stop_loss_price", "description", "reasoning"],
470
+ };
471
+
472
+ addOutlineSchema({
473
+ outlineName: "signal_plutus",
474
+ format,
475
+ prompt: "Generate crypto trading signals based on price and volume indicators in JSON format.",
476
+ completion: "grok-mini-outline",
477
+ getOutlineHistory: async ({ history, param }) => {
478
+ const signalReport = await ioc.signalReportService.getSignalReport(param);
479
+ await commitReports(history, signalReport);
480
+ await history.push({ role: "user", content: "Generate JSON based on reports." });
481
+ },
482
+ validations: [
483
+ {
484
+ validate: ({ data }) => {
485
+ if (data.action !== "buy") return;
486
+ const stopLossChange = percentDiff(data.current_price, data.stop_loss_price);
487
+ if (stopLossChange > CC_LADDER_STOP_LOSS) {
488
+ throw new Error(`Stop loss must not exceed -${CC_LADDER_STOP_LOSS}%`);
489
+ }
490
+ },
491
+ docDescription: "Checks stop-loss price against max loss percentage.",
492
+ },
493
+ {
494
+ validate: ({ data }) => {
495
+ if (data.action !== "buy") return;
496
+ const sellChange = percentDiff(data.current_price, data.take_profit_price);
497
+ if (sellChange > CC_LADDER_TAKE_PROFIT) {
498
+ throw new Error(`Take profit must not exceed +${CC_LADDER_TAKE_PROFIT}%`);
499
+ }
500
+ },
501
+ docDescription: "Checks take-profit price against max profit percentage.",
502
+ },
503
+ ],
504
+ });
505
+
506
+ ```
507
+
508
+ P.S. [Outlines by dottxt](https://dottxt-ai.github.io/outlines/1.1.0/) doc 📖
509
+
510
+ ---
511
+
454
512
  ## ✅ Tested & Reliable
455
513
 
456
514
  `agent-swarm-kit` comes with a robust test suite covering: