In this tutorial you will create an Agent and run it within a Network with AgentKit.

1

Install AgentKit

Within an existing project, Install AgentKit from npm:

You can always find the latest release version on npm.

2

Create an agent

To start, we’ll create our first “Agent.” An “Agent” is an entity that has a specific role to answer questions or perform tasks (See “tools” further below).

To start, let’s create a new file, index.ts. Using the createAgent constructor, give your agent a name, a description and it’s initial system prompt. The name and description properties are used to allow the LLM to determine which Agent to call.

You’ll also specify which model you want the agent to use. Here we’ll use Anthropic’s Claude 3.5 Haiku model. (Model reference)

Your agent can be whatever you want, but in this quick start, we’ll create a Postgres database administrator agent:

index.ts
import { createAgent, anthropic } from '@inngest/agent-kit';

const dbaAgent = createAgent({
  name: 'Database administrator',
  description: 'Provides expert support for managing PostgreSQL databases',
  system:
    'You are a PostgreSQL expert database administrator. ' +
    'You only provide answers to questions linked to Postgres database schema, indexes, extensions.',
  model: anthropic({
    model: 'claude-3-5-haiku-latest',
    max_tokens: 1000,
  }),
});

We’ll also have to set any provider API keys as environment variables.

terminal
export ANTHROPIC_API_KEY=sk-ant-api03-XXXXXX....
3

Run the server

Next, we’ll create an http server in order to run our agent. In the same file as our Agent definition:

index.ts
import { createAgent, anthropic, createServer } from '@inngest/agent-kit';
// ...
const server = createServer({
  agents: [dbaAgent],
});
server.listen(3000, () => console.log('Agent kit running!'));

Now we can run our AgentKit server using npx and tsx (for easy TypeScript execution).

terminal
npx tsx ./index.ts
4

Test our agent

To test our agent, we’ll use the Inngest dev server to allow us to visually debug our agents. Using npx, we’ll start the server and point it to our AgentKit server:

terminal
npx inngest-cli@latest dev -u http://localhost:3000/api/inngest

Now, open the dev server and select the function’s tab (http://localhost:8288/functions) and click the “Invoke” button:

In the Invoke function modal, specify the input prompt for your agent and click the “Invoke function” button.

Invoke payload
{
  "data": {
    "input": "How do I aggregate an integer column across a date column by week?"
  }
}

You’ll be redirected to watch the agent run and view the output:

5

Creating a Network

A key benefit of AgentKit is the ability to create a system of agents called a “Network.” “Networks” are used to create stateful workflows with one or more Agents that can call tools.

We’ll start by creating a second “Database Security” Agent:

index.ts
import { createAgent, anthropic } from '@inngest/agent-kit';

// ...

const securityAgent = createAgent({
  name: 'Database Security Expert',
  description: 'Provides expert guidance on PostgreSQL security, access control, audit logging, and compliance best practices',
  system: 'You are a PostgreSQL security expert. ' +
    'You only provide answers to questions linked to PostgreSQL security topics such as encryption, access control, audit logging, and compliance best practices.',
  model: anthropic({
    model: 'claude-3-5-haiku-latest',
    max_tokens: 1000,
  }),
});

We can now create a network combining our “Database Administrator” and “Database Security” Agents, which enables us to answer more complex questions.

Create a network using the createNetwork constructor. Define a name include our agent from the previous step in the agents array. You must also configure the defaultModel for which the “router” will use to determine which agent to call.

index.ts
import { /*...*/ createNetwork } from "@inngest/agent-kit";
// ...
const devOpsNetwork = createNetwork({
  name: "DevOps team",
  agents: [dbaAgent, securityAgent],
  defaultModel: anthropic({
    model: "claude-3-5-haiku-latest",
    max_tokens: 1000,
  }),
});
const server = createServer({
  agents: [dbaAgent, securityAgent],
  networks: [devOpsNetwork],
});
6

Test our network

We’ll use the same approach to test our network as we did above to test our network, with the Inngest dev server’s.

Networks are powerful as they include “routing agents” that can coordinate between a system of multiple agents, enabling networks to complete more complex tasks.

Our network enables us to answer more complex or multiple questions such as:

Invoke payload
{
  "data": {
    "input": "I am building a Finance application. Help me answer the following 2 questions: \n - How can I scale my application to millions of request per second? \n - How should I design my schema to ensure the safety of each organization's data?"
  }
}

The network will now run through the Agents to answer the questions:

And provide the final answer in two parts:

As a PostgreSQL expert focused on database schema, indexes, and extensions, I'll provide database-specific recommendations:
...

Thank you for waiting. As a PostgreSQL security expert, I'll focus specifically on the security aspects of your schema design and data isolation:
...

Next steps

Congratulations! You’ve now created your first AgentKit Agents and Network.

In this guide you’ve learned that:

  • Agents are the building blocks of AgentKit. They are used to call a single model to answer specific questions or perform tasks.
  • Networks are a group of agents that can work together to achieve more complex goals.

The following guides will help you to build more advanced AI Agents: