Replies: 1 comment
-
|
Task and run hooks are one of those features that seem simple but unlock a lot of patterns when you're building complex workflows. A few use cases where pre/post hooks have been most valuable in agent-style workloads: Cost tracking: A export const myTask = task({
id: "agent-task",
onStart: async ({ payload, ctx }) => {
await db.runs.create({
runId: ctx.run.id,
startedAt: new Date(),
estimatedCost: estimateCost(payload),
});
},
onSuccess: async ({ payload, output, ctx }) => {
await db.runs.update(ctx.run.id, {
completedAt: new Date(),
actualCost: output.tokensUsed * COST_PER_TOKEN,
});
},
run: async (payload) => {
// main logic
},
});Audit receipts: Memory consolidation: After each task, a hook that summarizes what was learned and writes to the agent's long-term memory store. The pattern where hooks can themselves trigger tasks gets powerful quickly — just watch out for cycles. More on economic tracking for autonomous agents: https://blog.kinthai.ai/agent-wallet-economic-models-autonomous-agents |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We should give users the ability to hook into the task and run lifecycle
Beta Was this translation helpful? Give feedback.
All reactions