Package Exports
- @elizaos/plugin-knowledge
- @elizaos/plugin-knowledge/package.json
Readme
Knowledge Plugin for ElizaOS
This plugin gives your agent the ability to learn from documents and answer questions based on that knowledge.
🚀 Quick Start (No Configuration Needed!)
If you already have plugin-openai configured in your agent, this plugin works automatically! Just add it to your agent and you're done.
import { knowledgePlugin } from '@elizaos/plugin-knowledge';
// Add to your agent's plugins
plugins: [
'@elizaos/plugin-knowledge',
// ... other plugins
];That's it! Your agent can now process and learn from documents.
📁 Auto-Load Documents on Startup
Want your agent to automatically learn from documents when it starts? Just:
Add this to your
.envfile:LOAD_DOCS_ON_STARTUP=trueCreate a
docsfolder in your project root and add your documents:your-project/ ├── .env ├── docs/ <-- Create this folder │ ├── guide.pdf │ ├── manual.txt │ └── notes.md └── ... other filesStart your agent - it will automatically load all documents from the
docsfolder!
Supported File Types
- 📄 Documents: PDF, TXT, MD, DOC, DOCX
- 💻 Code: JS, TS, PY, and many more
- 📊 Data: JSON, CSV, XML, YAML
💬 How to Use
Once documents are loaded, just ask your agent questions naturally:
- "What does the guide say about setup?"
- "Search your knowledge for information about configuration"
- "What do you know about [topic]?"
Your agent will search through all loaded documents and provide relevant answers!
🎯 Actions Available
The plugin provides these actions that your agent can use:
PROCESS_KNOWLEDGE - Add new documents or text to the knowledge base
- "Process the document at /path/to/file.pdf"
- "Remember this: The sky is blue"
SEARCH_KNOWLEDGE - Search the knowledge base
- "Search your knowledge for quantum computing"
🌐 Web Interface
The plugin includes a web interface for managing documents! Access it at:
http://localhost:3000/api/agents/[your-agent-id]/plugins/knowledge/display⚠️ Advanced Configuration (Developers Only)
Note: If you're not a developer, don't use the settings below! The plugin works great with just the quick start setup above.
Click to show advanced configuration options
Custom Document Path
Change where documents are loaded from:
KNOWLEDGE_PATH=/path/to/your/documentsEnhanced Contextual Knowledge
For better understanding of complex documents:
CTX_KNOWLEDGE_ENABLED=true
TEXT_PROVIDER=openrouter
TEXT_MODEL=anthropic/claude-3.5-sonnet
OPENROUTER_API_KEY=your-api-keyCustom Embedding Configuration
If not using plugin-openai:
EMBEDDING_PROVIDER=openai
TEXT_EMBEDDING_MODEL=text-embedding-3-small
OPENAI_API_KEY=your-api-keyAll Configuration Options
# Document Loading
LOAD_DOCS_ON_STARTUP=true # Auto-load from docs folder
KNOWLEDGE_PATH=/custom/path # Custom document path
# Contextual Enhancement (improves understanding)
CTX_KNOWLEDGE_ENABLED=true # Enable contextual embeddings
# Embedding Provider (if not using plugin-openai)
EMBEDDING_PROVIDER=openai # or google
TEXT_EMBEDDING_MODEL=text-embedding-3-small
EMBEDDING_DIMENSION=1536
# Text Generation Provider (for contextual mode)
TEXT_PROVIDER=openai # or anthropic, openrouter, google
TEXT_MODEL=gpt-4o # Model name for your provider
# API Keys (based on providers used)
OPENAI_API_KEY=your-key
ANTHROPIC_API_KEY=your-key
OPENROUTER_API_KEY=your-key
GOOGLE_API_KEY=your-key
# Rate Limiting
MAX_CONCURRENT_REQUESTS=30
REQUESTS_PER_MINUTE=60
TOKENS_PER_MINUTE=150000
# Token Limits
MAX_INPUT_TOKENS=4000
MAX_OUTPUT_TOKENS=4096API Routes Reference
POST /api/agents/{agentId}/plugins/knowledge/documents- Upload documentsGET /api/agents/{agentId}/plugins/knowledge/documents- List documentsGET /api/agents/{agentId}/plugins/knowledge/documents/{id}- Get specific documentDELETE /api/agents/{agentId}/plugins/knowledge/documents/{id}- Delete documentGET /api/agents/{agentId}/plugins/knowledge/display- Web interface
Programmatic Usage
import { KnowledgeService } from '@elizaos/plugin-knowledge';
// Add knowledge programmatically
const result = await knowledgeService.addKnowledge({
clientDocumentId: 'unique-id',
content: documentContent,
contentType: 'application/pdf',
originalFilename: 'document.pdf',
worldId: 'world-id',
roomId: 'room-id',
entityId: 'entity-id',
});📝 License
See the ElizaOS license for details.