As discussed in the deployment guide, moving an AgentKit network into users’ hands requires configuring usage limits.

To avoid having one user’s usage affect another, you can configure multi-tenancy.

Multi-tenancy consists of configuring limits based on users or organizations (called “tenants”). It can be easily configured on your AgentKit network using Inngest.

Prerequisites

Your AgentKit network must be configured with Inngest.

Configuring Multi-tenancy

Adding multi-tenancy to your AgentKit network is done by transforming your AgentKit network into an Inngest function.

Transforming your AgentKit network into an Inngest function

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

src/inngest/client.ts
import { Inngest } from 'inngest';

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

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

src/inngest/agent-network.ts
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.

Configuring a concurrency per user

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

src/inngest/agent-network.ts
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',
  concurrency: [
      {
        key: "event.data.user_id",
        limit: 10,
      },
    ],
}, {
  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 be limited to 10 concurrent requests per user.

The same can be done to add throttling, rate limiting or priority.

Going further