Quick start
Learn the basics of AgentKit in a few minutes.
In this tutorial, you will create an Agent and run it within a Network using AgentKit.
Follow this guide by forking the quick-start example locally by running:
Creating a single agent
Install AgentKit
Within an existing project, install AgentKit from npm:
You can always find the latest release version on npm.
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” below).
Let’s create a new file, index.ts
. Using the createAgent
constructor, give your agent a name
, a description
, and its initial system
prompt. The name
and description
properties are used to help the LLM 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 PostgreSQL database administrator agent:
You’ll also need to set your provider API keys as environment variables:
Test our agent
To test our agent, we’ll use the Inngest dev server to visually debug our agents. Using npx
, we’ll start the server and point it to our AgentKit server:
Now, open the dev server and select the functions 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:
You’ll be redirected to watch the agent run and view the output:
A key benefit of AgentKit is the ability to create a system of agents called a “Network.” Networks are used to create AI Agents by combining multiple specialized Agents to answer more complex questions. Let’s transform our single agent into a network of two agents, capable of helping with both database administration and security questions.
Creating a multi-agent network
Adding a second Agent
Agents collaborate in a Network by sharing a common State.
Let’s update our Database Administrator Agent to include a tool to save the answer to the question in the database:
Tools are based on Tool Calling, enabling your Agent to interact with the State of the Network, store data in external databases, or dynamically fetch data from third-party APIs.
Let’s now create a second Database Security Agent:
Our second Security Expert Agent is similar to the first, but with a different system prompt specifically for security questions.
We can now create a network combining our “Database Administrator” and “Database Security” Agents, which enables us to answer more complex questions.
Creating a Network
Create a network using the createNetwork
constructor. Define a name
and include our agents from the previous step in the agents
array.
You must also configure a router
that the Router will use to determine which agent to call:
The highlighted lines are the key parts of our AI Agent behavior:
- The
agents
property defines the agents that are part of the network - The
router
function defines the logic for which agent to call next. In this example, we call the Database Administrator Agent followed by the Security Expert Agent before ending the network (by returningundefined
).
Test our network
We’ll use the same approach to test our network as we did above.
With your Inngest dev server running, open the dev server and select the functions tab (http://localhost:8288/functions
) and click the “Invoke” button of the DevOps team function with the following payload:
The network will now run through the Agents to answer the questions:
You can inspect the answers of each Agent by selecting the Finalization step and inspecting the JSON payload in the right panel:
Next steps
Congratulations! You’ve now created your first AI Agent with AgentKit.
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 groups of agents that can work together to achieve more complex goals.
- Routers, combined with State, enable you to control the flow of your Agents.
The following guides will help you build more advanced AI Agents:
Adding Tools to Agents
Let your Agent act and gather data with tools
Implementing reasoning-based routing
Learn how to dynamically route between agents
You can also explore the following examples to see how to use AgentKit in more complex scenarios:
Support Agent with "Human in the loop"
This AgentKit example shows how to build a Support Agent Network with a “Human in the loop” pattern.
AgentKit SWE-bench
This AgentKit example uses the SWE-bench dataset to train an agent to solve coding problems. It uses advanced tools to interact with files and codebases.