Examples

Real-world use cases showing how to combine agent-tools-kit modules to build production AI applications.

This example combines the Reasoning module with Structured Output to analyze financial transactions. The agent reasons step-by-step about why a transaction might be suspicious, then outputs a structured risk assessment with confidence scores.

Implementation
import { createReasoningAgent } from 'agent-tools-kit/reasoning'
import { createStructuredOutput, schemas } from 'agent-tools-kit/structured'
import { z } from 'zod'

const riskSchema = z.object({
  riskLevel: z.enum(['low', 'medium', 'high', 'critical']),
  score: z.number().min(0).max(100),
  flags: z.array(z.object({
    type: z.string(),
    description: z.string(),
    severity: z.enum(['info', 'warning', 'danger']),
  })),
  recommendation: z.string(),
})

// Step 1: Reason about the transaction
const reasoner = createReasoningAgent({
  model: 'openai/gpt-4o-mini',
  reasoningStyle: 'chain-of-thought',
  maxSteps: 6,
})

const reasoning = await reasoner.reason({
  problem: 'Analyze this transaction for fraud indicators',
  context: `
    Amount: $45,000 (wire transfer)
    From: Business account, 2 years old
    To: Newly created offshore account
    Time: 3:42 AM local time
    Previous max transaction: $5,000
    IP location: Different country than account holder
  `,
})

// Step 2: Generate structured risk assessment
const assessment = await createStructuredOutput({
  model: 'openai/gpt-4o-mini',
  schema: riskSchema,
  prompt: `Based on this analysis, generate a risk assessment:
    \n\n${reasoning.conclusion}`,
})

console.log(assessment.data)

Example Output

{
  "riskLevel": "critical",
  "score": 92,
  "flags": [
    {
      "type": "amount_anomaly",
      "description": "Transaction 9x higher than historical maximum",
      "severity": "danger"
    },
    {
      "type": "timing_anomaly",
      "description": "Transaction initiated at unusual hour (3:42 AM)",
      "severity": "warning"
    },
    {
      "type": "destination_risk",
      "description": "Recipient is a newly created offshore account",
      "severity": "danger"
    },
    {
      "type": "geo_mismatch",
      "description": "IP location does not match account holder country",
      "severity": "danger"
    }
  ],
  "recommendation": "Block transaction and flag for manual review. Contact account holder to verify identity."
}