Skip to content

feat(platform): Add document_list agent tool #658

@larryro

Description

@larryro

Summary

Add a new document_list agent tool that allows the AI agent (and workflow LLM nodes) to query and filter documents from the knowledge base. Currently, the agent has no way to list, filter, or browse documents — it can only search by semantic relevance via rag_search.

Motivation

Many advanced workflows require the agent to identify specific documents before processing them:

  • "Find the last 10 contracts uploaded this month"
  • "List all documents in folder X"
  • "Show me all PDF files tagged with team Y"

Without this tool, the agent cannot perform document-level operations like comparison, batch analysis, or systematic review.

Proposed Tool Design

Tool name: document_list
Registration: Add to agent_tools/tool_names.ts and agent_tools/tool_registry.ts

Input Schema

{
  folderPath?: string;       // Filter by folder path (e.g., "/contracts/2024")
  extension?: string;        // Filter by file extension (e.g., "pdf", "docx")
  dateFrom?: string;         // ISO date string, filter by creation date
  dateTo?: string;           // ISO date string, filter by creation date
  query?: string;            // Optional name/title search
  sortBy?: "createdAt" | "name";  // Sort order (default: "createdAt")
  sortOrder?: "asc" | "desc";     // Sort direction (default: "desc")
  limit?: number;            // Max results (default: 20, max: 50)
}

Output

{
  documents: Array<{
    id: string;
    name: string;
    folderPath: string;
    extension: string;
    createdAt: string;      // ISO timestamp
    sizeBytes: number;
    teamTags: string[];
  }>;
  totalCount: number;
  hasMore: boolean;
}

Implementation Notes

  • Query the Convex documents table directly (no RAG service call needed)
  • Scope by organizationId from tool context
  • Filter by teamTags using userTeamIds from tool context for access control
  • Leverage existing indexes on organizationId + extension
  • Follow patterns from existing tools like customer_read_tool.ts and product_read_tool.ts

Key Files

  • services/platform/convex/agent_tools/documents/document_list_tool.ts (new)
  • services/platform/convex/agent_tools/tool_names.ts (register name)
  • services/platform/convex/agent_tools/tool_registry.ts (register tool)
  • services/platform/convex/documents/ (existing queries to reference)

Acceptance Criteria

  • New document_list tool registered in tool registry
  • Supports all filter parameters (folder, extension, date range, query)
  • Supports sorting and pagination (limit)
  • Respects organization and team-based access control
  • Works both as a chat agent tool and in workflow LLM nodes
  • Unit tests covering: filtering, sorting, access control, empty results, limit boundaries

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions