Skip to content

Conversation

@0xbbjoker
Copy link
Contributor

@0xbbjoker 0xbbjoker commented Oct 30, 2025

  • Create documentsProvider to show available RAG documents
  • Display document metadata (filename, type, size, source)
  • Static provider for context efficiency
  • Helps agent understand which documents it can reference
  • Avoids displaying base64 content, uses metadata instead

Note

Adds a static documentsProvider that lists available knowledge documents, integrates it into plugin providers/exports, and bumps version to 1.5.13.

  • Providers:
    • Add documentsProvider (src/documents-provider.ts) to list available knowledge documents via KnowledgeService.getMemories, filtering by MemoryType.DOCUMENT and formatting summary output.
    • Register in plugin (src/index.ts) by adding to providers: [knowledgeProvider, documentsProvider] and export it.
  • Version:
    • Bump package.json version from 1.5.12 to 1.5.13.

Written by Cursor Bugbot for commit 15d97c6. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

Release Notes

  • New Features

    • New provider added to list documents from the knowledge base, displaying file information including name, type, size, and source.
  • Chores

    • Patch version bump (1.5.12 → 1.5.13)

@coderabbitai
Copy link

coderabbitai bot commented Oct 30, 2025

Walkthrough

The pull request introduces a new documents provider to the knowledge plugin, enabling agents to discover and list available documents from the knowledge base. The version is bumped to 1.5.13, and the new provider is exported through the plugin's public API.

Changes

Cohort / File(s) Summary
Package maintenance
package.json
Version bumped from 1.5.12 to 1.5.13
New documents provider
src/documents-provider.ts
New Provider export that retrieves and formats a list of available documents from the knowledge service, including filename, type, size, and source metadata; includes error handling and gracefully handles absence of knowledge service
Plugin integration
src/index.ts
Added import and export of documentsProvider; integrated provider into Knowledge plugin's providers array

Sequence Diagram

sequenceDiagram
    participant Agent
    participant Provider as documentsProvider
    participant Runtime as IAgentRuntime
    participant KnowledgeService as Knowledge Service
    
    Agent->>Provider: get(runtime)
    Provider->>Runtime: access knowledge service
    
    alt Knowledge Service exists
        Provider->>KnowledgeService: query documents table
        KnowledgeService-->>Provider: return memories
        Provider->>Provider: filter for documents<br/>(exclude fragments)
        Provider->>Provider: format metadata<br/>(filename, type, size, source)
        Provider-->>Agent: return formatted list +<br/>count + text
    else No Knowledge Service
        Provider-->>Agent: return empty results
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Area of attention: The documents-provider.ts filtering logic to ensure it correctly distinguishes between documents and fragments in the memories data structure
  • Area of attention: Verify the provider integrates correctly with the runtime's knowledge service interface and follows the existing Provider pattern

Poem

🐰 A new eye opens, scanning files with glee,
Documents emerge from knowledge's grand tree,
Listed with care—each title, each size,
The agent now knows what wisdom supplies! 📚✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat: Add static provider for listing available documents" accurately and clearly describes the main functional change in the changeset. The PR adds a new documentsProvider that fetches and formats available documents from the knowledge service, which directly matches what the title conveys. The title is concise, specific, and avoids vague terminology. While the PR also includes a minor version bump in package.json, the title appropriately focuses on the primary feature addition rather than administrative changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/knowledge-documents-list-provider

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@0xbbjoker 0xbbjoker merged commit 9b04019 into 1.x Oct 30, 2025
1 of 2 checks passed
@0xbbjoker 0xbbjoker deleted the feat/knowledge-documents-list-provider branch October 30, 2025 11:41
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
src/documents-provider.ts (3)

38-38: Consider making the document limit configurable.

The hardcoded limit of 100 documents might be insufficient for knowledge bases with many documents. Consider making this configurable or implementing pagination.


42-44: Potentially redundant filtering.

Since you're already querying the documents table, filtering by MemoryType.DOCUMENT might be redundant. However, this defensive approach ensures data integrity if the table contains mixed types.


55-89: Consider defining a proper type for document metadata.

The use of as any on line 57 (and lines 98-102) bypasses type checking. While this may be necessary due to flexible metadata structures, consider defining an interface for expected document metadata fields to improve type safety.

Example:

interface DocumentMetadata {
  filename?: string;
  title?: string;
  fileExt?: string;
  fileType?: string;
  source?: string;
  fileSize?: number;
}

However, the formatting logic itself is well-structured with appropriate fallbacks and the file size calculation is correct.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 13426d3 and 15d97c6.

📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/documents-provider.ts (1 hunks)
  • src/index.ts (3 hunks)
🔇 Additional comments (6)
package.json (1)

4-4: LGTM! Appropriate version bump.

The minor version increment from 1.5.12 to 1.5.13 is appropriate for adding the new documents provider feature.

src/index.ts (3)

10-10: LGTM! Clean import.

The documentsProvider is properly imported for use in the plugin.


77-77: LGTM! Provider correctly registered.

The documentsProvider is appropriately added to the providers array alongside the existing knowledgeProvider, making it available to all plugin configurations.


149-149: LGTM! Provider properly exported.

The documentsProvider is correctly exported from the module's public API, enabling external consumers to access it.

src/documents-provider.ts (2)

16-20: LGTM! Clear provider metadata.

The provider name, description, and static flag are well-defined. Setting dynamic: false is appropriate since the available documents don't change based on individual messages.


35-39: No issues identified. The usage is semantically correct and follows the established codebase pattern.

The search results confirm that using runtime.agentId as roomId is the standard pattern throughout the entire codebase. This pattern is consistently applied in:

  • Memory creation and retrieval across all document operations
  • Service layer (defaulting roomId to agentId when not specified)
  • Route handlers for document fetching and searching
  • Test suites for memory verification
  • Document processing pipeline

The roomId parameter semantically represents the agent scope for memories—not a chat room. The consistent application and the service layer's implementation (which defaults roomId to agentId) demonstrate this is intentional design, not an error.

Likely an incorrect or invalid review comment.

@@ -0,0 +1,121 @@
import type { IAgentRuntime, Memory, Provider } from '@elizaos/core';
import { addHeader, logger, MemoryType } from '@elizaos/core';
import { KnowledgeService } from './service.ts';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove file extension from import statement.

The .ts extension in the import path may cause module resolution issues in certain build configurations. TypeScript imports should typically omit the file extension.

Apply this diff:

-import { KnowledgeService } from './service.ts';
+import { KnowledgeService } from './service';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { KnowledgeService } from './service.ts';
import { KnowledgeService } from './service';
🤖 Prompt for AI Agents
In src/documents-provider.ts around line 3, the import uses a '.ts' extension
which can break some module resolvers; remove the file extension so the line
reads import { KnowledgeService } from './service'; and save; ensure the
relative path still points to the same module and update any other imports
following this project convention if needed.

Comment on lines +25 to +32
if (!knowledgeService) {
logger.warn('Knowledge service not available for documents provider');
return {
data: { documents: [] },
values: { documents: '' },
text: '',
};
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Inconsistent error handling in return values.

When the knowledge service is unavailable (lines 25-32), the return object doesn't include an error field in data, but when an exception occurs (lines 112-119), it does. This inconsistency may confuse consumers trying to distinguish between "no documents available" and "error occurred."

Consider adding an error field when the service is unavailable:

 if (!knowledgeService) {
   logger.warn('Knowledge service not available for documents provider');
   return {
-    data: { documents: [] },
+    data: { documents: [], error: 'Knowledge service not available' },
     values: { documents: '' },
     text: '',
   };
 }

Also applies to: 112-119

🤖 Prompt for AI Agents
In src/documents-provider.ts around lines 25-32 (and similarly ensure
consistency with lines 112-119), the return value when the knowledge service is
unavailable lacks the data.error field that the exception path sets; update the
early-return object to include a data.error string (e.g. 'Knowledge service not
available') and keep the same shape as the error-return in the catch block so
consumers can reliably detect an error versus an empty result; make the message
explicit and ensure values and text remain as currently returned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant