The AI agent
Groq-powered Llama 3.3 reasons over the live on-chain snapshot and returns structured insight.
Reasoning loop
The agent runs server-side on each dashboard load. It reads the live snapshot via readProtocolSnapshot(), feeds it to Groq's Llama 3.3 70B model with a structured Zod schema, and returns a typed insight. There is no hidden state — the LLM only sees on-chain numbers.
ts
// app/api/ai/insights/route.ts
const snapshot = await readProtocolSnapshot()
const { object } = await generateObject({
model: groq("llama-3.3-70b-versatile"),
schema: InsightSchema,
system: "You are YieldMind's autonomous AI yield agent...",
prompt: `Live snapshot at block ${snapshot.network.blockNumber}...`,
})
return Response.json({ insight: object, snapshot })Output schema
ts
const InsightSchema = z.object({
headline: z.string(),
riskBand: z.enum(["low","medium","high"]),
confidence: z.number().min(0).max(1),
recommendation: z.enum(["hold","rebalance","reduce","expand"]),
allocation: z.array(z.object({
protocol: z.string(),
weight: z.number().min(0).max(1),
})),
signals: z.array(z.object({
label: z.string(),
severity: z.enum(["info","warn","alert"]),
detail: z.string(),
})),
})Streaming reasoning
The dashboard's rebalance panel uses POST /api/ai/rebalance. The endpoint streams chain-of-thought text via streamText() so the UI can render reasoning token-by-token.