Multi-steps tools
In this guide, we’ll learn how to create a multi-steps tool that can be used in your AgentKit Tools to reliably perform complex operations.
By combining your AgentKit network with Inngest, each step of your tool will be retried automatically and you’ll be able to configure concurrency and throttling.
Creating a multi-steps tool
Section titled “Creating a multi-steps tool”Creating a multi-steps tool is done by creating an Inngest Function that will be used as a tool in your AgentKit network.
To create an Inngest Function, you’ll need to create an Inngest Client:
import { Inngest } from 'inngest';
const inngest = new Inngest({ id: 'my-agentkit-network',});Then, we will implement our AgentKit Tool as an Inngest Function with multiple steps. For example, we’ll create a tool that searches for perform a research by crawling the web:
import { inngest } from '../client';
export const researchWebTool = inngest.createFunction({ id: 'research-web-tool',}, { event: "research-web-tool/run"}, async ({ event, step }) => { const { input } = event.data;
const searchQueries = await step.ai.infer('generate-search-queries', { model: step.ai.models.openai({ model: "gpt-4o" }), // body is the model request, which is strongly typed depending on the model body: { messages: [{ role: "user", content: `From the given input, generate a list of search queries to perform. \n ${input}`, }], }, });
const searchResults = await Promise.all( searchQueries.map(query => step.run('crawl-web', async (query) => { // perform crawling... }) ));
const summary = await step.ai.infer('summarize-search-results', { model: step.ai.models.openai({ model: "gpt-4o" }), body: { messages: [{ role: "user", content: `Summarize the following search results: \n ${searchResults.join('\n')}`, }], }, });
return summary.choices[0].message.content;});Our researchWebTool Inngest defines 3 main steps.
- The
step.ai.infer()call will offload the LLM requests to the Inngest infrastructe which will also handle retries. - The
step.run()call will run thecrawl-webstep in parallel.
All the above steps will be retried automatically in case of failure, resuming the AgentKit network upon completion of the tool.
Using the multi-steps tool in your AgentKit network
Section titled “Using the multi-steps tool in your AgentKit network”We can now add our researchWebTool to our AgentKit network:
import { createAgent, createNetwork, openai } from '@inngest/agent-kit';import { createServer } from '@inngest/agent-kit/server';
import { researchWebTool } from './inngest/tools/research-web';
const deepResearchAgent = createAgent({ name: 'Deep Research Agent', tools: [researchWebTool],});
const network = createNetwork({ name: 'My Network', defaultModel: openai({ model: "gpt-4o" }), agents: [deepResearchAgent],});
const server = createServer({ networks: [network], functions: [researchWebTool],});
server.listen(3010, () => console.log("Agent kit running!"));We first import our researchWebTool function and pass it to the deepResearchAgent tools array.
Finally, we also need to pass the researchWebTool function to the createServer()’s functions array.