Quickstart
Build an AI agent that reasons about your business data. By the end of this guide, you'll have an agent that doesn't just retrieve documents—it understands them.
What You'll Build
- An AI agent with reasoning capabilities
- A datastore with your documents
- Logic definitions that encode your domain knowledge
- A query that returns answers you can actually use
Step 1: Create an Agent
Create an agent that will reason about your documents:
1const agent = await client.agents.create({2 name: 'Contract Analyst',3 description: 'An agent that reasons about contracts and business agreements',4 system_prompt: 'You are a contract analyst. Answer questions by reasoning about the documents and applying business rules. Always cite your sources.',5});67console.log('Agent created:', agent.id);Agents can be customized with specific behaviors, reasoning approaches, and response formats. See the Creating Agents guide for advanced configuration.
Step 2: Create a Datastore
Datastores hold the documents your agent reasons about:
1const datastore = await client.datastores.create({2 name: 'Contracts',3 description: 'Collection of business contracts and agreements',4});56console.log('Datastore created:', datastore.id);Step 3: Upload Documents
Upload documents to your datastore. Orka supports PDF, DOCX, TXT, and more.
1const document = await client.documents.upload({2 datastore_id: datastore.id,3 file: fs.createReadStream('./contract.pdf'),4 name: 'Acme Corp Agreement',5});67console.log('Document uploaded:', document.id);8console.log('Processing status:', document.status);Processing Time
Documents need to be processed before they can be queried. This typically takes a few seconds to a few minutes depending on document size.
Check Processing Status
Wait for the document to finish processing:
1async function waitForProcessing(documentId) {2 while (true) {3 const doc = await client.documents.get(documentId);45 if (doc.status === 'completed') {6 console.log('Document ready!');7 return doc;8 }910 if (doc.status === 'failed') {11 throw new Error('Document processing failed');12 }1314 console.log('Processing...', doc.status);15 await new Promise(r => setTimeout(r, 2000));16 }17}1819await waitForProcessing(document.id);Step 4: Connect Agent to Datastore
Link your agent to the datastore so it can access the documents:
1await client.agents.connectDatastore({2 agent_id: agent.id,3 datastore_id: datastore.id,4});56console.log('Agent connected to datastore');Step 5: Add Logic Definitions
This is where Orka differs from basic RAG. Define logic (metrics, terms, and rules) so your agent understands your domain:
1// Define what "high-risk" means in your organization (a Rule)2await client.definitions.create({3 name: 'High-risk contract',4 definition_type: 'rule',5 definition: 'A contract with liability exceeding $1M OR containing a termination amendment',6});78// Define customer tiers (a Term)9await client.definitions.create({10 name: 'Enterprise customer',11 definition_type: 'term',12 definition: 'A customer with annual contract value over $100K',13});1415// Define a metric calculation16await client.definitions.create({17 name: 'Monthly Recurring Revenue',18 definition_type: 'metric',19 definition: 'Sum of all active monthly subscription values',20});2122console.log('Logic definitions configured');Now when you ask "which contracts are high-risk?", the agent knows exactly what "high-risk" means—no guessing, no keyword matching.
Logic definitions can be scoped to the entire workspace (available to all agents) or to specific datastores. See the Logic guide for more details.
Step 6: Ask a Question
Query your agent and get answers you can use:
1const response = await client.chat.query({2 agent_id: agent.id,3 message: 'Which contracts are high-risk?',4});56console.log('Answer:', response.content);7console.log('Citations:', response.citations);Example Response
1{2 "content": "Based on your high-risk criteria (liability > $1M or termination amendment), I found 2 high-risk contracts:\n\n1. **Acme Corp Agreement** - Liability cap of $2.1M [1]\n2. **Beta Inc Contract** - Contains termination amendment in Section 12 [2]\n\nThe remaining 3 contracts in your datastore do not meet the high-risk threshold.",3 "citations": [4 {5 "id": 1,6 "document_name": "Acme Corp Agreement",7 "page_number": 8,8 "excerpt": "Total liability under this agreement shall not exceed $2,100,000..."9 },10 {11 "id": 2,12 "document_name": "Beta Inc Contract",13 "page_number": 12,14 "excerpt": "Either party may terminate this agreement with 30 days notice..."15 }16 ]17}Notice how the response applies your business rules, not just keyword matching. That's the difference between retrieval and reasoning.
Complete Example
Here's the complete code:
1import { Orka } from '@orka/sdk';2import fs from 'fs';34const client = new Orka({5 apiKey: process.env.ORKA_API_KEY,6});78async function main() {9 // 1. Create agent10 const agent = await client.agents.create({11 name: 'Contract Analyst',12 system_prompt: 'You are a contract analyst. Apply business rules when answering questions. Cite your sources.',13 });1415 // 2. Create datastore16 const datastore = await client.datastores.create({17 name: 'Contracts',18 });1920 // 3. Upload document21 const document = await client.documents.upload({22 datastore_id: datastore.id,23 file: fs.createReadStream('./contract.pdf'),24 });2526 // 4. Wait for processing27 await waitForProcessing(document.id);2829 // 5. Connect agent to datastore30 await client.agents.connectDatastore({31 agent_id: agent.id,32 datastore_id: datastore.id,33 });3435 // 6. Add logic definitions36 await client.definitions.create({37 name: 'High-risk contract',38 definition_type: 'rule',39 definition: 'Liability > $1M OR termination amendment',40 });4142 // 7. Ask a question43 const response = await client.chat.query({44 agent_id: agent.id,45 message: 'Which contracts are high-risk?',46 });4748 console.log(response.content);49}5051main();Next Steps
Now that you've built a reasoning agent, explore these resources:
- Creating Agents - Advanced agent configuration
- Logic - Encode complex domain logic with metrics, terms, and rules
- API Reference - Complete API documentation
- Chat API - Streaming, citations, and more