Backend
Orion - Knowledge Organization

Orion - Knowledge Organization Agent

Overview

Orion is the Folder Organization agent in the TKM AI Agency Platform, responsible for intelligently organizing files and documents into appropriate folder structures. It analyzes document content and metadata to determine optimal categorization and file placement.

Directory Structure

Backend/CRM/Orion/
├── data/                # Organization decisions and logs
├── orion.py            # Main agent implementation
├── tools.py            # Organization utilities
├── tools_schema.py     # Data models and schemas
└── tools_definitions.py # Constants and definitions

Main Components

OrionAgent Class

The core component that handles file organization:

  • Document analysis
  • Folder structure determination
  • Category assignment
  • Metadata management

Processing Pipeline

  1. Document Reception

    • File metadata extraction
    • Content analysis
    • Context gathering
    • Request validation
  2. Organization Analysis

    • Content categorization
    • Structure determination
    • Confidence scoring
    • Category mapping
  3. Structure Management

    • Folder creation decisions
    • Path generation
    • Metadata updates
    • Structure validation

API Operations

Process Organization

  • Endpoint: /process_request
  • Method: POST
  • Purpose: Analyzes and determines folder structure for documents
  • Request Format:
    {
      "file_name": "document.pdf",
      "conversation_id": "conversation_identifier",
      "document_data": {
        "extracted_text": "document content",
        "summary": "document summary"
      },
      "user_id": "user_identifier",
      "organization_id": "org_identifier"
    }
  • Response Format:
    {
      "folder_name": "determined_folder",
      "file_name": "document.pdf",
      "category": "main_category",
      "subcategory": "sub_category",
      "state": "processed",
      "confidence": 0.95
    }

Key Features

  1. Document Analysis

    • Content understanding
    • Metadata extraction
    • Category detection
    • Context analysis
  2. Structure Determination

    • Intelligent categorization
    • Folder hierarchy
    • Path optimization
    • Naming conventions
  3. Organization Management

    • Decision tracking
    • Structure validation
    • History logging
    • Metadata updates

Integration

Platform Integration

  • Interfaces with other CRM agents
  • Event-based communication
  • Metadata sharing
  • Structure coordination

LLM Integration

  • Groq primary provider
  • OpenAI fallback support
  • Content analysis
  • Category determination

Error Handling

  1. Input Validation

    • File validation
    • Data verification
    • Request formatting
    • Recovery procedures
  2. Processing Errors

    • Analysis failures
    • Structure conflicts
    • Category mismatches
    • Error reporting

Performance Features

  1. Optimization

    • Quick categorization
    • Efficient processing
    • Cache utilization
    • Resource management
  2. Configuration

    • Category rules
    • Structure templates
    • Model selection
    • Provider settings

Data Models

Folder Request

{
    "file_name": str,
    "conversation_id": str,
    "document_data": dict,
    "user_id": str,
    "organization_id": str
}

Folder Structure

{
    "folder_name": str,
    "file_name": str,
    "category": str,
    "subcategory": str,
    "state": str,
    "confidence": float
}