For a more sophisticated agent that can decide when to search vs. add knowledge, use tool calling:
# Tool-calling agents require programmatic control flow.# Use the Go or TypeScript SDK for agent loops.# For simple questions, pipe vault search into LLM:casedev vault search --id $VAULT_ID --query "What deadlines are coming up?"casedev llm:v1:chat create-completion \ --model anthropic/claude-sonnet-4.5 \ --message '{role: system, content: "You are a document intelligence agent."}' \ --message '{role: user, content: "Based on these documents: <search results>\n\nWhat deadlines are coming up?"}'
// Add some knowledgeawait addToKnowledgeBase( 'The Smith v. Jones case was filed on March 15, 2024. The plaintiff alleges negligence in the maintenance of the property.', { topic: 'case-facts' });await addToKnowledgeBase( 'Deposition of John Smith on April 2, 2024: Witness stated he observed water damage on the ceiling two weeks before the incident.', { topic: 'depositions' });// Ask questionsconst result = await answerQuestion('When was the Smith v. Jones case filed?');console.log(result.answer);// "The Smith v. Jones case was filed on March 15, 2024 [1]."const result2 = await answerQuestion('What did John Smith observe?');console.log(result2.answer);// "John Smith observed water damage on the ceiling two weeks before the incident [1]."// Using the agentconst response = await runAgent('My favorite pizza topping is pepperoni. Remember that.');console.log(response);// "I've added that to my knowledge base. Your favorite pizza topping is pepperoni."const response2 = await runAgent('What is my favorite pizza topping?');console.log(response2);// "According to my knowledge base, your favorite pizza topping is pepperoni."
Chunking is automatic. Case.dev Vaults automatically chunk documents into semantic segments optimized for retrieval. You don’t need to implement chunking yourself.
const systemPrompt = `You are a legal research assistant.Rules:- ONLY use information from the provided context- If information is not in the context, say "I don't have that information"- Always cite sources using [1], [2], etc.- Never make up or infer facts not explicitly stated`;