Human in the Loop
Enable your Agents to wait for human input.
Agents such as Support Agents, Coding or Research Agents might require human oversight.
By combining AgentKit with Inngest, you can create Tools that can wait for human input.
Creating a “Human in the Loop” tool
“Human in the Loop” tools are implemented using Inngest’s waitForEvent()
step method:
The ask_developer
tool will wait up to 4 hours for a "developer.response"
event to be received, pausing the execution of the AgentKit network.
The incoming "developer.response"
event will be matched against the data.ticketId
field of the event that trigger the AgentKit network.
For this reason, the AgentKit network will need to be wrapped in an Inngest function as demonstrated in the next section.
Example: Support Agent with Human in the Loop
Let’s consider a Support Agent Network automously triaging and solving tickets:
You can find the complete example code in the examples/support-agent-human-in-the-loop directory.
To avoid the Support Agent to be stuck or classifying tickets incorrectly, we’ll implement a “Human in the Loop” tool to enable a human to add some context.
To implement a “Human in the Loop” tool, we’ll need to embed our AgentKit network into an Inngest function.
Transforming your AgentKit network into an Inngest function
First, you’ll need to create an Inngest Client:
Then, transform your AgentKit network into an Inngest function as follows:
The network.run()
is now performed by the Inngest function.
Don’t forget to register the function with createServer
’s functions
property.
Add a ask_developer
tool to the network
Our AgentKit network is now ran inside an Inngest function triggered by the "app/support.ticket.created"
event which carries
the data.ticketId
field.
The Technical Support
Agent will now use the ask_developer
tool to ask a developer for input on a technical issue:
Our ask_developer
tool will now wait for a "developer.response"
event to be received (ex: from a Slack message), and match it against the data.ticketId
field.
The result of the ask_developer
tool will be returned to the Technical Support
Agent.
Look at the Inngest step.waitForEvent()
documentation for more details and examples.
Try it out
Support Agent with "Human in the loop"
This Support AgentKit Network is composed of two Agents (Customer Support and Technical Support) and a Supervisor Agent that routes the ticket to the correct Agent. The Technical Support Agent can wait for a developer response when facing complex technical issues.