Inngest AgentKit Integration
Learn how to integrate AgentKit agents with the Scenario testing framework
Inngest AgentKit makes it easy to build multi-agent systems and orchestrate them in an event-driven architecture.
AgentKit agents work seamlessly with Scenario through the AgentAdapter[ts]
interface.
Basic Integration Pattern
First, create your agent using AgentKit:
import { createAgent, createTool, openai } from "@inngest/agent-kit";
// Define a simple tool
const getCompanyPolicy = createTool({
name: "get-company-policy",
description: "Get the company policy document",
parameters: {},
handler: async () => ({ policy: "Company policy goes here." }),
});
// Create your agent
export const customerSupportAgent = createAgent({
name: "Customer Support Agent",
description: "Helps customers with their questions.",
system: "You are a helpful customer support agent.",
model: openai({ model: "gpt-4o-mini", apiKey: process.env.OPENAI_API_KEY }),
tools: [getCompanyPolicy],
});
Then, wrap your agent for Scenario:
import scenario, { type AgentAdapter, AgentRole } from "@langwatch/scenario";
import { customerSupportAgent } from "./customer-support-agent";
import { createState, Message } from "@inngest/agent-kit";
const createAgent = (): AgentAdapter => {
const agentState = createState();
return {
role: AgentRole.AGENT,
call: async (input) => {
const latestMessage = input.messages.at(-1)?.content || "";
const messageContent =
typeof latestMessage === "string"
? latestMessage
: JSON.stringify(latestMessage);
let lastMessage: Message | undefined;
while (!lastMessage || lastMessage?.type === "tool_call") {
const result = await customerSupportAgent.run(messageContent, {
state: agentState,
});
agentState.appendResult(result);
lastMessage = result.output.at(-1);
}
if (lastMessage?.type === "text") {
return lastMessage.content as string;
}
return JSON.stringify(lastMessage);
},
};
};
Full Example Project
For a complete working example with a customer support agent, including tools, system prompts, and comprehensive tests, check out the create-agent-app project.
Next Steps
- Explore Scenario Basics for advanced testing patterns
- Learn about Scripted Simulations for precise control
- Check out more Agent Integration patterns for other frameworks