### Clone Quick Start Example Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/getting-started/quick-start.mdx Fork the quick-start example locally to follow along with the guide. This command downloads the example project files. ```shell npx git-ripper https://github.com/inngest/agent-kit/tree/main/examples/quick-start ``` -------------------------------- ### Run Multi-Agent Example Source: https://github.com/inngest/agent-kit/blob/main/examples/mem0-memory/README.md Execute the multi-agent example using npm. This command starts an agent setup that utilizes multiple agents for complex tasks. ```bash npm run start-multi ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/inngest/agent-kit/blob/main/examples/agentkit-starter/README.md Clone the AgentKit repository, navigate to the starter example, and install project dependencies. ```bash git clone https://github.com/inngest/agent-kit.git cd agent-kit/examples/agentkit-starter npm install cp .env.example .env ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/inngest/agent-kit/blob/main/examples/support-agent-human-in-the-loop/README.md Change directory to the support agent example. ```bash cd examples/support-agent-human-in-the-loop ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/inngest/agent-kit/blob/main/examples/realtime-ui-nextjs/README.md Change directory to the realtime-ui-nextjs example folder. ```bash cd examples/realtime-ui-nextjs ``` -------------------------------- ### Start AgentKit Server Source: https://github.com/inngest/agent-kit/blob/main/examples/swebench/README.md Starts the AgentKit application server. This command should be run after dependencies are installed and API keys are set. ```shell pnpm start ``` -------------------------------- ### Setup AgentKit Network and Agent Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/integrations/browserbase.mdx Define an AgentKit agent and create a network to manage it. This example sets up a Reddit search agent. ```typescript import { anthropic, createAgent, createNetwork, } from "@inngest/agent-kit"; const searchAgent = createAgent({ name: "reddit_searcher", description: "An agent that searches Reddit for relevant information", system: "You are a helpful assistant that searches Reddit for relevant information.", }); // Create the network const redditSearchNetwork = createNetwork({ name: "reddit_search_network", description: "A network that searches Reddit using Browserbase", agents: [searchAgent], maxIter: 2, defaultModel: anthropic({ model: "claude-3-5-sonnet-latest", max_tokens: 4096, }); ``` -------------------------------- ### Install Dependencies Source: https://github.com/inngest/agent-kit/blob/main/docs/README.md Navigate to the docs directory and install project dependencies using npm. ```sh cd docs npm install ``` -------------------------------- ### Run the Agent Locally Source: https://github.com/inngest/agent-kit/blob/main/examples/daytona-coding-agent/README.md Execute this command to start the coding agent in your local environment after installing dependencies. ```bash npm run start ``` -------------------------------- ### Initialize SWE-bench Examples Source: https://github.com/inngest/agent-kit/blob/main/examples/swebench/README.md Initializes the SWE-bench examples by running the 'make init' command. This typically downloads necessary data and prepares the environment for running benchmarks. ```shell make init ``` -------------------------------- ### Code-based Router Example in Agent Kit Source: https://github.com/inngest/agent-kit/blob/main/packages/agent-kit/README.md Demonstrates setting up agents, tools, and a network with a code-based router. This setup orchestrates agents based on a plan generated by a code assistant agent, utilizing shared state for execution flow. ```typescript import { z, anthropic, createAgent, createNetwork, createTool, } from "@inngest/agent-kit"; import { readFileSync } from "fs"; import { join } from "path"; // create a shared tool const saveSuggestions = createTool({ name: "save_suggestions", description: "Save the suggestions made by other agents into the state", parameters: z.object({ suggestions: z.array(z.string()), }), handler: async (input, { network }) => { const suggestions = network?.state.kv.get("suggestions") || []; network?.state.kv.set("suggestions", [ ...suggestions, ...input.suggestions, ]); return "Suggestions saved!"; }, }); // create agents with access to the state via the `saveSuggestions` tool const documentationAgent = createAgent({ name: "documentation_agent", system: "You are an expert at generating documentation for code", tools: [saveSuggestions], }); const analysisAgent = createAgent({ name: "analysis_agent", system: "You are an expert at analyzing code and suggesting improvements", tools: [saveSuggestions], }); const summarizationAgent = createAgent({ name: "summarization_agent", system: ({ network }) => { const suggestions = network?.state.kv.get("suggestions") || []; return `Save a summary of the following suggestions: ${suggestions.join("\n")}`; }, tools: [ createTool({ name: "save_summary", description: "Save a summary of the suggestions made by other agents into the state", parameters: z.object({ summary: z.string(), }), handler: async (input, { network }) => { network?.state.kv.set("summary", input.summary); return "Saved!"; }, }), ], }); // Create the code assistant agent which generates a plan const codeAssistantAgent = createAgent({ name: "code_assistant_agent", system: ({ network }) => { const agents = Array.from(network?.agents.values() || []) .filter( (agent) => !["code_assistant_agent", "summarization_agent"].includes(agent.name) ) .map((agent) => `${agent.name} (${agent.system})`); return `From a given user request, ONLY perform the following tool calls: - read the file content - generate a plan of agents to run from the following list: ${agents.join(", ")} Answer with "done" when you are finished.`; }, tools: [ createTool({ name: "read_file", description: "Read a file from the current directory", parameters: z.object({ filename: z.string(), }), handler: async (input, { network }) => { const filePath = join(process.cwd(), `files/${input.filename}`); const code = readFileSync(filePath, "utf-8"); network?.state.kv.set("code", code); return "File read!"; }, }), createTool({ name: "generate_plan", description: "Generate a plan of agents to run", parameters: z.object({ plan: z.array(z.string()), }), handler: async (input, { network }) => { network?.state.kv.set("plan", input.plan); return "Plan generated!"; }, }), ], }); const network = createNetwork({ name: "code-assistant-v2", agents: [ codeAssistantAgent, documentationAgent, analysisAgent, summarizationAgent, ], // our routing function relies on the shared state to orchestrate agents // first, the codeAssistantAgent is called and then, its plan gets // executed step by step until a summary gets written in the state. router: ({ network }) => { if (!network?.state.kv.has("code") || !network?.state.kv.has("plan")) { return codeAssistantAgent; } else { const plan = (network?.state.kv.get("plan") || []) as string[]; const nextAgent = plan.pop(); if (nextAgent) { network?.state.kv.set("plan", plan); return network?.agents.get(nextAgent); } else if (!network?.state.kv.has("summary")) { return summarizationAgent; } else { return undefined; } } }, defaultModel: anthropic({ model: "claude-3-5-sonnet-latest", defaultParameters: { max_tokens: 4096, }, }), }); ``` -------------------------------- ### Install Dependencies Source: https://github.com/inngest/agent-kit/blob/main/README.md Install all project dependencies using pnpm. ```bash pnpm i ``` -------------------------------- ### Install @inngest/use-agent Source: https://github.com/inngest/agent-kit/blob/main/packages/use-agent/README.md Install the package using npm, pnpm, or yarn. ```bash npm install @inngest/use-agent # or pnpm add @inngest/use-agent # or yarn add @inngest/use-agent ``` -------------------------------- ### Start Development Server Source: https://github.com/inngest/agent-kit/blob/main/docs/README.md Run this command to start a local development server for the documentation. It will be available at http://localhost:4321. ```sh npm run dev ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/inngest/agent-kit/blob/main/examples/mcp-neon-agent/README.md Navigate to the agent's example directory after cloning the repository. ```bash cd examples/mcp-neon-agent ``` -------------------------------- ### Start Production Server Source: https://github.com/inngest/agent-kit/blob/main/examples/deep-research/README.md Launch the application in production mode after building. ```bash pnpm run start ``` -------------------------------- ### Install AgentKit and Inngest with npm Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/getting-started/installation.mdx Use this command to install both packages using npm. ```shell npm install @inngest/agent-kit inngest ``` -------------------------------- ### Start Development Server Source: https://github.com/inngest/agent-kit/blob/main/examples/deep-research/README.md Run the Next.js development server to view the application locally. ```bash pnpm run dev ``` -------------------------------- ### Download Example Code File Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/guided-tour/ai-workflows.mdx Downloads the example.ts file from the specified GitHub URL using wget. This file is used by the Code Assistant example. ```bash wget https://raw.githubusercontent.com/inngest/agent-kit/main/examples/code-assistant-rag/files/example.ts ``` -------------------------------- ### Install AgentKit and Daytona (npm) Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/integrations/daytona.mdx Install the necessary packages for AgentKit and Daytona using npm. ```shell npm install @inngest/agent-kit inngest @daytonaio/sdk ``` -------------------------------- ### Install Dependencies Source: https://github.com/inngest/agent-kit/blob/main/examples/e2b-coding-agent/README.md Install project dependencies using npm. Ensure Node.js v16 or higher is installed. ```bash npm install ``` -------------------------------- ### Install AgentKit and Inngest with yarn Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/getting-started/installation.mdx Use this command to install both packages using yarn. ```shell yarn add @inngest/agent-kit inngest ``` -------------------------------- ### Install Peer Dependencies Source: https://github.com/inngest/agent-kit/blob/main/packages/use-agent/README.md Ensure you have the required peer dependencies installed. ```bash npm install react @inngest/realtime uuid ``` -------------------------------- ### Install Dependencies with yarn Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/guided-tour/ai-agents.mdx Install the required agent-kit and zod packages using yarn. ```bash yarn add @inngest/agent-kit zod ``` -------------------------------- ### Environment Setup Commit Source: https://github.com/inngest/agent-kit/blob/main/examples/swebench/README.md This snippet shows a commit hash used for environment setup. ```json { "environment_setup_commit": "6072e0982c3c0236f532ddfa48fbf461180d834e" } ``` -------------------------------- ### Install Dependencies with npm Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/guided-tour/ai-agents.mdx Install the required agent-kit, inngest, and zod packages using npm. ```bash npm install @inngest/agent-kit inngest zod ``` -------------------------------- ### Install AgentKit and Daytona (yarn) Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/integrations/daytona.mdx Install the necessary packages for AgentKit and Daytona using yarn. ```shell yarn add @inngest/agent-kit inngest @daytonaio/sdk ``` -------------------------------- ### Install AgentKit and Inngest with pnpm Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/getting-started/installation.mdx Use this command to install both packages using pnpm. ```shell pnpm install @inngest/agent-kit inngest ``` -------------------------------- ### Install AgentKit and E2B (npm) Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/integrations/e2b.mdx Install the necessary packages for AgentKit and E2B using npm. ```shell npm install @inngest/agent-kit inngest @e2b/code-interpreter ``` -------------------------------- ### Install AgentKit and Daytona (pnpm) Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/integrations/daytona.mdx Install the necessary packages for AgentKit and Daytona using pnpm. ```shell pnpm install @inngest/agent-kit inngest @daytonaio/sdk ``` -------------------------------- ### Install AgentKit and Smithery SDK Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/integrations/smithery.mdx Install the necessary packages for AgentKit and the Smithery SDK using npm, pnpm, or yarn. ```shell npm install @inngest/agent-kit inngest @smithery/sdk ``` ```shell pnpm install @inngest/agent-kit inngest @smithery/sdk ``` ```shell yarn add @inngest/agent-kit inngest @smithery/sdk ``` -------------------------------- ### Install Dependencies with pnpm Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/guided-tour/ai-agents.mdx Install the required agent-kit, inngest, and zod packages using pnpm. ```bash pnpm install @inngest/agent-kit inngest zod ``` -------------------------------- ### Install AgentKit and E2B (yarn) Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/integrations/e2b.mdx Install the necessary packages for AgentKit and E2B using yarn. ```shell yarn add @inngest/agent-kit inngest @e2b/code-interpreter ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/inngest/agent-kit/blob/main/examples/voice-assistant/README.md Clone the AgentKit repository and navigate to the voice-assistant example directory. ```sh git clone https://github.com/inngest/agent-kit.git cd agent-kit/examples/voice-assistant ``` -------------------------------- ### Start Qdrant Vector Database Source: https://github.com/inngest/agent-kit/blob/main/examples/mem0-memory/README.md Start the Qdrant local vector database using Docker Compose. This is required for storing and retrieving memories. ```bash docker-compose up ``` -------------------------------- ### Install Inngest SDK with npm Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/concepts/deployment.mdx Use npm to install the Inngest SDK. This is the first step in integrating Inngest with your AgentKit network. ```shell npm install inngest ``` -------------------------------- ### Run AgentKit Server Source: https://github.com/inngest/agent-kit/blob/main/examples/gemini-quick-start/README.md Start the AgentKit server using this command. ```shell npm start ``` -------------------------------- ### Environment Variables Setup Source: https://github.com/inngest/agent-kit/blob/main/examples/reddit-search-browserbase-tools/README.md Configure your Browserbase and Anthropic API keys in a .env file. ```env BROWSERBASE_API_KEY=your_browserbase_api_key BROWSERBASE_PROJECT_ID=your_browserbase_project_id ANTHROPIC_API_KEY=your_anthropic_api_key ``` -------------------------------- ### Environment Variables Setup Source: https://github.com/inngest/agent-kit/blob/main/examples/use-agent/README.md Configure environment variables for API keys and Inngest credentials in a .env.local file. ```env # LLM Provider API Keys (at least one required) OPENAI_API_KEY=your-openai-api-key ANTHROPIC_API_KEY=your-anthropic-api-key # Inngest (optional for local development) INNGEST_EVENT_KEY=your-inngest-event-key INNGEST_SIGNING_KEY=your-inngest-signing-key ``` -------------------------------- ### Install AgentKit and Inngest Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/getting-started/quick-start.mdx Install AgentKit and its required peer dependency, Inngest, using npm, pnpm, or yarn. ```shell npm install @inngest/agent-kit inngest ``` ```shell pnpm install @inngest/agent-kit inngest ``` ```shell yarn add @inngest/agent-kit inngest ``` -------------------------------- ### Download Example Code File Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/guided-tour/agentic-workflows.mdx Downloads the example TypeScript file 'example.ts' into a 'files' directory. This file is used by the code assistant for analysis. ```bash mkdir files cd files wget https://raw.githubusercontent.com/inngest/agent-kit/main/examples/code-assistant-agentic/files/example.ts cd - ``` -------------------------------- ### MCP Agent Example with Neon Database Source: https://github.com/inngest/agent-kit/blob/main/packages/agent-kit/README.md Example demonstrating how to build an AgentKit Agent using MCP with the Neon database MCP server. This requires setting up a Smithery URL with your profile and API key. ```tsx import { anthropic, createAgent, createNetwork, createTool, } from "@inngest/agent-kit"; import { createServer } from "@inngest/agent-kit/server"; import { createSmitheryUrl } from "@smithery/sdk/config.js"; import { z } from "zod"; const neonServerUrl = createSmitheryUrl( "https://server.smithery.ai/neon/mcp?profile=bored-catshark-da8hf&api_key=123123123" ); const neonAgent = createAgent({ name: "neon-agent", system: `You are a helpful assistant that help manage a Neon account. IMPORTANT: Call the 'done' tool when the question is answered. `, tools: [ createTool({ name: "done", description: "Call this tool when you are finished with the task.", parameters: z.object({ answer: z.string().describe("Answer to the user's question."), }), handler: async ({ answer }, { network }) => { network?.state.kv.set("answer", answer); }, }), ], mcpServers: [ { name: "neon", transport: { type: "streamable-http", url: neonServerUrl.toString(), }, }, ], }); const neonAgentNetwork = createNetwork({ name: "neon-agent", agents: [neonAgent], defaultModel: anthropic({ model: "claude-3-5-sonnet-20240620", defaultParameters: { max_tokens: 1000, }, }), router: ({ network }) => { if (!network?.state.kv.get("answer")) { return neonAgent; } return; }, }); // Create and start the server const server = createServer({ networks: [neonAgentNetwork], }); server.listen(3010, () => console.log("Support Agent demo server is running on port 3010") ); ``` -------------------------------- ### Example Handler with Network State Update Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/reference/create-tool.mdx This example demonstrates a tool handler that interacts with the agent's network state. It updates `network.state.fileWritten` after successfully writing a file. ```typescript import { createTool } from '@inngest/agent-kit'; const tool = createTool({ name: 'write-file', description: 'Write a file to disk with the given contents', parameters: { type: 'object', properties: { path: { type: 'string' }, contents: { type: 'string' }, }, }, handler: async ({ path, contents }, { agent, network }) => { await fs.writeFile(path, contents); network.state.fileWritten = true; return { success: true }; }, }); ``` -------------------------------- ### Static System Prompt Example Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/concepts/agents.mdx Defines an agent with a simple, static system prompt for a copy editor. ```ts const codeWriterAgent = createAgent({ name: 'Copy editor', system: `You are an expert copy editor. Given a draft article, you provide ` + `actionable improvements for spelling, grammar, punctuation, and formatting.`, model: openai('gpt-3.5-turbo'), }); ``` -------------------------------- ### Install AgentKit and Inngest Source: https://github.com/inngest/agent-kit/blob/main/README.md Install AgentKit and Inngest dependencies. Starting with AgentKit v0.9.0, `inngest` must be installed separately. ```bash npm i @inngest/agent-kit inngest ``` -------------------------------- ### Set Up Environment Variables Source: https://github.com/inngest/agent-kit/blob/main/examples/voice-assistant/README.md Copy the example environment file and populate it with your API keys for services like Anthropic, Google Maps, Notion, and Exa. ```sh cp .env.example .env ``` ```env ANTHROPIC_API_KEY=sk-ant-xxx GOOGLE_MAPS_API_KEY=AIzaSy... NOTION_API_KEY=secret_... EXA_API_KEY=... ``` -------------------------------- ### Build and Preview Documentation Source: https://github.com/inngest/agent-kit/blob/main/docs/README.md Build the documentation for production and then preview the build locally. ```sh npm run build npm run preview # preview the build locally ``` -------------------------------- ### Implement Conversation History Adapter Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/concepts/history.mdx Define a history adapter by implementing the `createThread`, `get`, `appendUserMessage`, and `appendResults` methods. This example demonstrates saving to a PostgreSQL database. ```typescript import { createNetwork, createAgent, createState, openai, } from "@inngest/agent-kit"; import { db } from "./db"; // Your database client // Define your history adapter with all four methods const conversationHistoryAdapter: HistoryConfig = { // 1. Create new conversation threads (or ensure they exist) createThread: async ({ state, input }) => { // If a threadId already exists, upsert to ensure it's in the database if (state.threadId) { await db.thread.upsert({ where: { id: state.threadId }, update: { updatedAt: new Date() }, create: { id: state.threadId, userId: state.data.userId, title: input.slice(0, 50), createdAt: new Date(), }, }); return { threadId: state.threadId }; } // Otherwise, create a new thread const thread = await db.thread.create({ data: { userId: state.data.userId, title: input.slice(0, 50), // First 50 chars as title createdAt: new Date(), }, }); return { threadId: thread.id }; }, // 2. Load conversation history (including user messages) get: async ({ threadId }) => { if (!threadId) return []; const messages = await db.message.findMany({ where: { threadId }, orderBy: { createdAt: "asc" }, }); // Transform ALL messages (user + agent) to AgentResult format // This preserves the complete conversation order return messages.map((msg) => { if (msg.role === "user") { // Convert user messages to AgentResult with agentName: "user" return new AgentResult( "user", [ { type: "text" as const, role: "user" as const, content: msg.content, stop_reason: "stop", }, ], [], new Date(msg.createdAt) ); } else { // Return agent results return new AgentResult( msg.agentName, [ { type: "text" as const, role: "assistant" as const, content: msg.content, }, ], [], new Date(msg.createdAt) ); } }); }, // 3. Save user message immediately (before agents run) appendUserMessage: async ({ threadId, userMessage }) => { if (!threadId) return; await db.message.create({ data: { messageId: userMessage.id, // Use canonical client-generated ID threadId, role: "user", content: userMessage.content, createdAt: userMessage.timestamp, }, }); }, // 4. Save agent results after the run appendResults: async ({ threadId, newResults }) => { if (!threadId) return; // Save only agent responses (user message already saved) for (const result of newResults) { const content = result.output .filter((msg) => msg.type === "text") .map((msg) => msg.content) .join("\n"); await db.message.create({ data: { messageId: result.id || crypto.randomUUID(), // Use result.id if available threadId, role: "assistant", agentName: result.agentName, content, checksum: result.checksum, // For idempotency createdAt: result.createdAt, }, }); } }, }; ``` -------------------------------- ### Daytona Coding Agent Setup Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/integrations/daytona.mdx Initializes an AgentKit coding agent and imports necessary tools for interacting with the Daytona sandbox. This snippet is a partial example showing the agent creation and import of Daytona SDK components. ```typescript import { createAgent, anthropic, createTool, } from "@inngest/agent-kit"; import { z } from "zod"; import { CodeRunParams, DaytonaError } from "@daytonaio/sdk"; import { getSandbox, logDebug } from "./utils.js"; const codingAgent = createAgent({ name: "Coding Agent", description: "An autonomous coding agent for building software in a Daytona sandbox", ``` -------------------------------- ### Hybrid Code and Agent Routing Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/concepts/routers.mdx Combine predictable code-based routing for initial steps with agent-based routing for subsequent decisions. This example uses code to always start with the classifier, then delegates to the default routing agent. ```typescript import { createNetwork, getDefaultRoutingAgent } from "@inngest/agent-kit"; // classifier and writer Agents definition... const network = createNetwork({ agents: [classifier, writer], router: ({ callCount }) => { // Always start with the classifier if (callCount === 0) { return classifier; } // Then let the routing agent take over return getDefaultRoutingAgent(); }, }); ``` -------------------------------- ### Install Dependencies with pnpm Source: https://github.com/inngest/agent-kit/blob/main/examples/voice-assistant/README.md Install project dependencies using pnpm. Ensure pnpm is installed globally. ```sh pnpm install ``` -------------------------------- ### Create a New Project Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/integrations/smithery.mdx Initialize a new project using npm, pnpm, or yarn if you don't have an existing one. ```shell mkdir my-agent-kit-project && npm init ``` ```shell mkdir my-agent-kit-project && pnpm init ``` ```shell mkdir my-agent-kit-project && yarn init ``` -------------------------------- ### Run Network with User Prompt (Example) Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/guided-tour/agentic-workflows.mdx Demonstrates how to initiate the agent network's execution with a user-provided prompt for code analysis. The network orchestrates agents and shares state. ```typescript await network.run( `Analyze the files/example.ts file by suggesting improvements and documentation.` ); ``` -------------------------------- ### Set Up Environment Variables Source: https://github.com/inngest/agent-kit/blob/main/examples/deep-research/README.md Configure necessary API keys for OpenAI and Exa by creating a .env file. ```env # Required: OpenAI API key for AI model inference OPENAI_API_KEY=your_openai_api_key_here # Required: Exa API key for web search in deep research EXA_API_KEY=your_exa_api_key_here ``` -------------------------------- ### Create New Project (npm) Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/integrations/e2b.mdx Initialize a new project with npm if you don't have an existing one. ```shell mkdir my-agent-kit-project && npm init ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/inngest/agent-kit/blob/main/examples/e2b-coding-agent/README.md Set up your E2B and Anthropic API keys by copying the example environment file and filling in your credentials. ```env E2B_API_KEY=your_e2b_api_key ANTHROPIC_API_KEY=your_anthropic_api_key ``` -------------------------------- ### Initialize Database Schema Source: https://github.com/inngest/agent-kit/blob/main/examples/agentkit-starter/README.md Run the provided script to set up the necessary tables in your PostgreSQL database. ```bash npm run setup-db ``` -------------------------------- ### Create New Project (pnpm) Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/integrations/e2b.mdx Initialize a new project with pnpm if you don't have an existing one. ```shell mkdir my-agent-kit-project && pnpm init ``` -------------------------------- ### Start the Inngest CLI Dev Server Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/getting-started/quick-start.mdx Launch the Inngest development server and connect it to your AgentKit server by providing the URL. ```shell npx inngest-cli@latest dev -u http://localhost:3000/api/inngest ``` -------------------------------- ### Initialize Project with npm Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/guided-tour/ai-workflows.mdx Initializes a new Node.js project using npm. This is a prerequisite for installing project dependencies. ```bash npm init ``` -------------------------------- ### Start Development Servers Source: https://github.com/inngest/agent-kit/blob/main/examples/agentkit-starter/README.md Run the Inngest CLI in development mode and the Next.js application concurrently in separate terminals. ```bash # Terminal 1: Start Inngest dev server npx inngest-cli@latest dev ``` ```bash # Terminal 2: Start Next.js app pnpm run dev ``` -------------------------------- ### Create New Project (yarn) Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/integrations/e2b.mdx Initialize a new project with yarn if you don't have an existing one. ```shell mkdir my-agent-kit-project && yarn init ``` -------------------------------- ### Install AgentKit and E2B (pnpm) Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/integrations/e2b.mdx Install the necessary packages for AgentKit and E2B using pnpm. ```shell pnpm install @inngest/agent-kit inngest @e2b/code-interpreter ``` -------------------------------- ### Function Router Example Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/reference/network-router.mdx An example demonstrating how to define a function router for the `defaultRouter` option in `createNetwork`. ```APIDOC ## Function Router A function router is provided to the `defaultRouter` option in `createNetwork`. ### Example ```ts const network = createNetwork({ agents: [classifier, writer], router: ({ lastResult, callCount, network, stack, input }) => { // First call: use the classifier if (callCount === 0) { return classifier; } // Get the last message from the output const lastMessage = lastResult?.output[lastResult?.output.length - 1]; const content = lastMessage?.type === "text" ? (lastMessage?.content as string) : ""; // Second call: if it's a question, use the writer if (callCount === 1 && content.includes("question")) { return writer; } // Otherwise, we're done! return undefined; }, }); ``` ### Parameters - **input** (string) - The original input provided to the network. - **network** (Network) - The network instance, including its state and history. See [`Network.State`](/reference/state) for more details. - **stack** (Agent[]) - The list of future agents to be called. (_internal read-only value_) - **callCount** (number) - The number of agent calls that have been made. - **lastResult** (InferenceResult) - The result from the previously called agent. See [`InferenceResult`](/reference/state#inferenceresult) for more details. ### Return Values | Return Type | Description | | -------------- | -------------------------------------------------- | | `Agent` | Single agent to execute next | | `Agent[]` | Multiple agents to execute in sequence | | `RoutingAgent` | Delegate routing decision to another routing agent | | `undefined` | Stop network execution | ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/inngest/agent-kit/blob/main/examples/deep-research/README.md Clone the AgentKit repository and install project dependencies using pnpm. ```bash git clone cd agentkit-chat pnpm install ``` -------------------------------- ### Install @inngest/use-agent and Peer Dependencies Source: https://github.com/inngest/agent-kit/blob/main/docs/src/content/docs/reference/react-hooks/overview.mdx Install the @inngest/use-agent package along with its peer dependencies: react, @inngest/realtime, and uuid. ```bash npm install @inngest/use-agent # Peer dependencies npm install react @inngest/realtime uuid ``` -------------------------------- ### Example Agent Prompt Source: https://github.com/inngest/agent-kit/blob/main/examples/daytona-coding-agent/README.md This TypeScript code snippet shows how to initiate the agent with a prompt to create a React application. The agent will then scaffold, build, and potentially run the application. ```typescript const result = await network.run( `Create a minimal React app called "Notes" that lets users add, view, and delete notes. Each note should have a title and content. Use Create React App or Vite for setup. Include a simple UI with a form to add notes and a list to display them.` ); ```