Skip to content

Configuring Retries

Using AgentKit alongside Inngest enables automatic retries for your AgentKit network Agents and Tools calls.

The default retry policy is to retry 4 times with exponential backoff and can be configured by following the steps below.

Configuring a custom retry policy is done by transforming your AgentKit network into an Inngest function.

Transforming your AgentKit network into an Inngest function

Section titled “Transforming your AgentKit network into an Inngest function”

First, you’ll need to create an Inngest Client:

import { Inngest } from "inngest";
const inngest = new Inngest({
id: "my-agentkit-network",
});

Then, transform your AgentKit network into an Inngest function as follows:

import { createAgent, createNetwork, openai } from "@inngest/agent-kit";
import { createServer } from "@inngest/agent-kit/server";
import { inngest } from "./inngest/client";
const deepResearchAgent = createAgent({
name: "Deep Research Agent",
tools: [
/* ... */
],
});
const network = createNetwork({
name: "My Network",
defaultModel: openai({ model: "gpt-4o" }),
agents: [deepResearchAgent],
});
const deepResearchNetworkFunction = inngest.createFunction(
{
id: "deep-research-network",
},
{
event: "deep-research-network/run",
},
async ({ event, step }) => {
const { input } = event.data;
return network.run(input);
}
);
const server = createServer({
functions: [deepResearchNetworkFunction],
});
server.listen(3010, () => console.log("Agent kit running!"));

The network.run() is now performed by the Inngest function.

Don’t forget to register the function with createServer’s functions property.

We can now configure the capacity by user by adding concurrency and throttling configuration to our Inngest function:

import { createAgent, createNetwork, openai } from '@inngest/agent-kit';
import { createServer } from '@inngest/agent-kit/server';
import { inngest } from './inngest/client';
// network and agent definitions..
const deepResearchNetworkFunction = inngest.createFunction({
id: 'deep-research-network',
retries: 1
}, {
event: "deep-research-network/run"
}, async ({ event, step }) => {
const { input } = event.data;
return network.run(input);
})
const server = createServer({
functions: [deepResearchNetworkFunction],
});
server.listen(3010, () => console.log("Agent kit running!"));

Your AgentKit network will now retry once on any failure happening during a single execution cycle of your network.