|
| 1 | +--- |
| 2 | +title: Build a fact finder agent with code |
| 3 | +sidebarTitle: Fact Finder Agent |
| 4 | +icon: LuFileText |
| 5 | +--- |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +In this tutorial, you'll build a fact finder agent using code and the Inkeep SDK. When you ask "What is Inkeep?", the agent will: |
| 10 | +1. Search your knowledge base using the Inkeep RAG MCP tool |
| 11 | +2. Present relevant facts about Inkeep |
| 12 | + |
| 13 | +## Prerequisites |
| 14 | + |
| 15 | +- An existing Inkeep project running (follow the [quick start guide](/get-started/quick-start) to get started) |
| 16 | +- Or access to Inkeep Cloud |
| 17 | + |
| 18 | +## Setting up the project |
| 19 | + |
| 20 | +### Step 1: Create the project directory |
| 21 | + |
| 22 | +<Steps> |
| 23 | + <Step> |
| 24 | + Navigate to your projects directory: |
| 25 | +```bash |
| 26 | +cd src/projects |
| 27 | +``` |
| 28 | +</Step> |
| 29 | + <Step> |
| 30 | + Create a new directory for your fact finder project: |
| 31 | +```bash |
| 32 | +mkdir fact-finder |
| 33 | +``` |
| 34 | +</Step> |
| 35 | + <Step> |
| 36 | + Navigate into the new directory: |
| 37 | +```bash |
| 38 | +cd fact-finder |
| 39 | +``` |
| 40 | +</Step> |
| 41 | +</Steps> |
| 42 | + |
| 43 | +### Step 2: Create the project configuration |
| 44 | + |
| 45 | +Create an `index.ts` file with the following content: |
| 46 | + |
| 47 | +```typescript |
| 48 | +import { project } from "@inkeep/agents-sdk"; |
| 49 | + |
| 50 | +export const myProject = project({ |
| 51 | + id: "<project-id>", |
| 52 | + name: "<project-name>", |
| 53 | + description: "Fact finder project template", |
| 54 | + models: { |
| 55 | + base: { |
| 56 | + model: "<model-name>", |
| 57 | + }, |
| 58 | + structuredOutput: { |
| 59 | + model: "<model-name>", |
| 60 | + }, |
| 61 | + summarizer: { |
| 62 | + model: "<model-name>", |
| 63 | + }, |
| 64 | + }, |
| 65 | +}); |
| 66 | +``` |
| 67 | + |
| 68 | +<Note> |
| 69 | +Replace the placeholder values (`<project-id>`, `<project-name>`, `<model-name>`) with your actual project details. If you need help recreating the boilderplate, you can reuse the index.ts file from the default activities planner project. |
| 70 | +</Note> |
| 71 | + |
| 72 | +### Step 3: Push the project to Visual Builder |
| 73 | + |
| 74 | +<Steps> |
| 75 | + <Step> |
| 76 | + From the `fact-finder` directory, run: |
| 77 | +```bash |
| 78 | +inkeep push |
| 79 | +``` |
| 80 | +</Step> |
| 81 | + <Step> |
| 82 | + Verify in the Visual Builder that the project is created successfully. |
| 83 | + </Step> |
| 84 | +</Steps> |
| 85 | + |
| 86 | +## Creating the agent |
| 87 | + |
| 88 | +### Step 1: Create the agent directory |
| 89 | + |
| 90 | +```bash |
| 91 | +mkdir agents |
| 92 | +``` |
| 93 | + |
| 94 | +### Step 2: Create the fact finder agent |
| 95 | + |
| 96 | +Create `agents/fact-finder-agent.ts` with the following content: |
| 97 | + |
| 98 | +```typescript |
| 99 | +import { agent, subAgent } from "@inkeep/agents-sdk"; |
| 100 | +import { inkeepRagMcpTool } from "../tools/inkeep-rag-mcp.js"; |
| 101 | + |
| 102 | +const mySubAgent = subAgent({ |
| 103 | + id: 'fact-finder-sub-agent', |
| 104 | + name: 'Fact Finder SubAgent', |
| 105 | + description: 'A sub agent that can help you find facts about the moon', |
| 106 | + prompt: 'You are a fact finder sub agent that can help you find facts about the moon', |
| 107 | + canUse: () => [inkeepRagMcpTool] |
| 108 | +}); |
| 109 | + |
| 110 | +export const factFinderAgent = agent({ |
| 111 | + id: "fact-finder-agent", |
| 112 | + name: "Fact Finder Agent", |
| 113 | + description: "A agent that can help you find facts about the moon", |
| 114 | + defaultSubAgent: mySubAgent, |
| 115 | + subAgents: () => [mySubAgent], |
| 116 | +}); |
| 117 | +``` |
| 118 | + |
| 119 | +## Adding the MCP tool |
| 120 | + |
| 121 | +### Step 1: Create the tools directory |
| 122 | +```bash |
| 123 | +mkdir tools |
| 124 | +``` |
| 125 | + |
| 126 | + |
| 127 | +### Step 2: Create the Inkeep RAG MCP tool |
| 128 | + |
| 129 | +Create `tools/inkeep-rag-mcp.ts` with the following content: |
| 130 | + |
| 131 | +```typescript |
| 132 | +import { mcpTool } from "@inkeep/agents-sdk"; |
| 133 | + |
| 134 | +export const inkeepRagMcpTool = mcpTool({ |
| 135 | + id: "inkeep-rag-mcp", |
| 136 | + name: "Inkeep RAG MCP", |
| 137 | + serverUrl: "https://mcp.inkeep.com/inkeep/mcp", |
| 138 | +}); |
| 139 | +``` |
| 140 | + |
| 141 | +This tool enables your agent to search your Inkeep knowledge base for relevant information. |
| 142 | + |
| 143 | +### Step 3: Register the fact finder agent and rag mcp tool in the project |
| 144 | + |
| 145 | +```typescript |
| 146 | +import { project } from "@inkeep/agents-sdk"; |
| 147 | +import { factFinderAgent } from "./agents/fact-finder-agent"; |
| 148 | +import { inkeepRagMcpTool } from "./tools/inkeep-rag-mcp"; |
| 149 | + |
| 150 | +export const myProject = project({ |
| 151 | + id: "<project-id>", |
| 152 | + name: "<project-name>", |
| 153 | + description: "Fact finder project template", |
| 154 | + agents: () => [factFinderAgent], |
| 155 | + tools: () => [inkeepRagMcpTool], |
| 156 | + models: { |
| 157 | + base: { |
| 158 | + model: "<model-name>", |
| 159 | + }, |
| 160 | + structuredOutput: { |
| 161 | + model: "<model-name>", |
| 162 | + }, |
| 163 | + summarizer: { |
| 164 | + model: "<model-name>", |
| 165 | + }, |
| 166 | + }, |
| 167 | +}); |
| 168 | +``` |
| 169 | + |
| 170 | +## Deploying your agent |
| 171 | + |
| 172 | +<Steps> |
| 173 | + <Step> |
| 174 | + From the `fact-finder` directory, run: |
| 175 | +```bash |
| 176 | +inkeep push |
| 177 | +``` |
| 178 | +</Step> |
| 179 | + <Step> |
| 180 | + Verify in the Visual Builder that the fact finder agent is created successfully. |
| 181 | + </Step> |
| 182 | +</Steps> |
| 183 | + |
| 184 | +## Testing your agent |
| 185 | + |
| 186 | +<Steps> |
| 187 | + <Step> |
| 188 | + In the Visual Builder, click the **Try it** button to open the chat interface. |
| 189 | + </Step> |
| 190 | + <Step> |
| 191 | + Test your agent by asking questions like: |
| 192 | + - "What is Inkeep?" |
| 193 | + - "Tell me about Inkeep's features" |
| 194 | + - "How does Inkeep work?" |
| 195 | + </Step> |
| 196 | +</Steps> |
| 197 | + |
| 198 | +When working correctly, the agent will search your knowledge base and present relevant facts about Inkeep. |
0 commit comments