agentbay_knowledge_record
Record discoveries from your work: patterns, pitfalls, decisions, and insights. Store with project context, tags, and confidence to build persistent knowledge across sessions.
Instructions
Record a learning, pattern, or pitfall discovered during your work
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | Project ID | |
| type | Yes | ||
| title | Yes | Short title | |
| content | Yes | Detailed description | |
| tags | No | ||
| filePaths | No | ||
| confidence | No | ||
| source | No | ||
| sourceRef | No | ||
| scope | No | ||
| taskId | No | ||
| attemptId | No |
Implementation Reference
- src/index.ts:331-362 (handler)The tool handler for 'agentbay_knowledge_record'. It registers the tool via server.tool(), defines the Zod schema for inputs (projectId, type, title, content, tags, filePaths, confidence, source, sourceRef, scope, taskId, attemptId), and the async handler that POSTs to /api/v1/projects/{projectId}/knowledge and returns a formatted response including dedup detection and potential conflicts.
server.tool( 'agentbay_knowledge_record', 'Record a learning, pattern, or pitfall discovered during your work', { projectId: z.string().describe('Project ID'), type: z.enum(['PATTERN', 'PITFALL', 'ARCHITECTURE', 'DEPENDENCY', 'TEST_INSIGHT', 'PERFORMANCE', 'DECISION', 'CONTEXT']), title: z.string().describe('Short title'), content: z.string().describe('Detailed description'), tags: z.array(z.string()).optional(), filePaths: z.array(z.string()).optional(), confidence: z.number().min(0).max(1).optional(), source: z.string().optional(), sourceRef: z.string().optional(), scope: z.enum(['project', 'team', 'public']).optional(), taskId: z.string().optional(), attemptId: z.string().optional(), }, async ({ projectId, ...knowledgeData }) => { const data = await apiPost(`/api/v1/projects/${projectId}/knowledge`, knowledgeData); if (data.error) return { content: [{ type: 'text' as const, text: `Error: ${data.error}` }] }; let text = data.deduplicated ? `Knowledge updated (dedup): ${data.title}\nID: ${data.id}` : `Knowledge recorded: ${data.title}\nID: ${data.id}\nType: ${data.type}`; if (data.potentialConflicts?.length) { text += `\n\nPotential conflicts (${data.potentialConflicts.length}):`; for (const c of data.potentialConflicts) { text += `\n- "${c.title}" (confidence: ${c.confidence}) — ID: ${c.id}`; } } return { content: [{ type: 'text' as const, text }] }; } ); - src/index.ts:334-347 (schema)The Zod schema for the tool's input parameters, defining types, validations, and descriptions for projectId, type, title, content, tags, filePaths, confidence, source, sourceRef, scope, taskId, and attemptId.
{ projectId: z.string().describe('Project ID'), type: z.enum(['PATTERN', 'PITFALL', 'ARCHITECTURE', 'DEPENDENCY', 'TEST_INSIGHT', 'PERFORMANCE', 'DECISION', 'CONTEXT']), title: z.string().describe('Short title'), content: z.string().describe('Detailed description'), tags: z.array(z.string()).optional(), filePaths: z.array(z.string()).optional(), confidence: z.number().min(0).max(1).optional(), source: z.string().optional(), sourceRef: z.string().optional(), scope: z.enum(['project', 'team', 'public']).optional(), taskId: z.string().optional(), attemptId: z.string().optional(), }, - src/index.ts:331-362 (registration)The tool is registered using server.tool() with the name 'agentbay_knowledge_record' and a description 'Record a learning, pattern, or pitfall discovered during your work'. This is the MCP tool registration call.
server.tool( 'agentbay_knowledge_record', 'Record a learning, pattern, or pitfall discovered during your work', { projectId: z.string().describe('Project ID'), type: z.enum(['PATTERN', 'PITFALL', 'ARCHITECTURE', 'DEPENDENCY', 'TEST_INSIGHT', 'PERFORMANCE', 'DECISION', 'CONTEXT']), title: z.string().describe('Short title'), content: z.string().describe('Detailed description'), tags: z.array(z.string()).optional(), filePaths: z.array(z.string()).optional(), confidence: z.number().min(0).max(1).optional(), source: z.string().optional(), sourceRef: z.string().optional(), scope: z.enum(['project', 'team', 'public']).optional(), taskId: z.string().optional(), attemptId: z.string().optional(), }, async ({ projectId, ...knowledgeData }) => { const data = await apiPost(`/api/v1/projects/${projectId}/knowledge`, knowledgeData); if (data.error) return { content: [{ type: 'text' as const, text: `Error: ${data.error}` }] }; let text = data.deduplicated ? `Knowledge updated (dedup): ${data.title}\nID: ${data.id}` : `Knowledge recorded: ${data.title}\nID: ${data.id}\nType: ${data.type}`; if (data.potentialConflicts?.length) { text += `\n\nPotential conflicts (${data.potentialConflicts.length}):`; for (const c of data.potentialConflicts) { text += `\n- "${c.title}" (confidence: ${c.confidence}) — ID: ${c.id}`; } } return { content: [{ type: 'text' as const, text }] }; } ); - src/index.ts:168-176 (helper)The apiPost helper function used by the handler to make the POST request to the AgentBay API.
async function apiPost(path: string, body: unknown) { const res = await fetch(`${API_BASE}${path}`, { method: 'POST', headers: getHeaders(), body: JSON.stringify(body), }); return res.json(); }