Citations

Track sources in agent responses

Agents can cite their sources – show where information comes from.

Diagram

Citation Flow

📚 Sources

🤖 Agent

💬 Answer

📖 Citations

Quick Start

  1. Simple Usage
    typescript
    import { Agent } from 'praisonai';
    
    const agent = new Agent({
      instructions: 'Answer using the provided documents',
      knowledge: './docs/',
      citations: true
    });
    
    const result = await agent.chat('What is the return policy?');
    console.log(result.content);
    // "You can return items within 30 days [1]"
    console.log(result.citations);
    // [{ id: 1, source: 'returns.md', text: '...' }]
  2. With Configuration
    typescript
    const agent = new Agent({
      citations: {
        format: 'inline',  // or 'footnote', 'endnotes'
        includePageNumbers: true
      }
    });

User Interaction Flow

Diagram
KnowledgeAgentUserKnowledgeAgentUser“What’s the return policy?”Search documentsRelevant passagesGenerate answerAnswer + citations

Configuration Levels

typescript
// Level 1: Bool - Enable citations
const agent = new Agent({
  citations: true
});

// Level 2: String - Citation style
const agent = new Agent({
  citations: 'inline'  // 'inline', 'footnote', 'endnotes'
});

// Level 3: Dict - Full options
const agent = new Agent({
  citations: {
    format: 'footnote',
    includePageNumbers: true,
    maxCitations: 5,
    minRelevanceScore: 0.7
  }
});

Citation Formats

FormatExample
inline“Returns within 30 days [1]”
footnote“Returns within 30 days¹”
endnotesCitations listed at end

API Reference

Knowledge Module

Knowledge and citation support


Best Practices

Use with knowledge base

Citations work best when agent has documents to reference.

Set relevance threshold

Use minRelevanceScore to ensure quality citations.

Limit citation count

Too many citations can clutter responses.


Related