Skip to content

Commit fc4bdb1

Browse files
committed
docs
1 parent 8174ee1 commit fc4bdb1

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,54 @@ addTool({
451451

452452
---
453453

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 } from "agent-swarm-kit";
460+
461+
const format = {
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+
({ data }) => {
484+
if (data.action !== "buy") return;
485+
if (percentDiff(data.current_price, data.stop_loss_price) > CC_LADDER_STOP_LOSS) {
486+
throw new Error(`Stop loss must not exceed -${CC_LADDER_STOP_LOSS}%`);
487+
}
488+
},
489+
({ data }) => {
490+
if (data.action !== "buy") return;
491+
if (percentDiff(data.current_price, data.take_profit_price) > CC_LADDER_TAKE_PROFIT) {
492+
throw new Error(`Take profit must not exceed +${CC_LADDER_TAKE_PROFIT}%`);
493+
}
494+
},
495+
],
496+
});
497+
498+
```
499+
500+
---
501+
454502
## ✅ Tested & Reliable
455503

456504
`agent-swarm-kit` comes with a robust test suite covering:

0 commit comments

Comments
 (0)