> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pilottai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Document processor

# Document Processing Agent Example

This example demonstrates how to set up and use a document processing agent with the PilottAI framework.

## Features

* Text extraction from various document formats
* Content analysis capabilities
* Document summarization
* Configurable processing tools

## Setup

1. Install required dependencies:

```bash theme={null}
pip install pilott
```

2. Configure your environment:

```bash theme={null}
export OPENAI_API_KEY="your-api-key"
```

## Tools Included

### Text Extractor

Extracts text content from documents:

```python theme={null}
text_extractor = Tool(
    name="text_extractor",
    parameters={
        "file_path": "str",
        "format": "str"
    }
)
```

### Content Analyzer

Analyzes document content:

```python theme={null}
content_analyzer = Tool(
    name="content_analyzer",
    parameters={
        "text": "str",
        "analysis_type": "str"
    }
)
```

### Summarizer

Generates document summaries:

```python theme={null}
summarizer = Tool(
    name="summarizer",
    parameters={
        "text": "str",
        "max_length": "int"
    }
)
```

## Quick Start

```python theme={null}
from pilottai import Serve
from pilottai.core import AgentConfig, LLMConfig

# Initialize and run
async def main():
    pilott = Serve(name="DocumentProcessor")

    # Add document processing agent
    doc_processor = await pilott.add_agent(
        title="document_processor",
        goal="Process documents efficiently",
        tools=["text_extractor", "content_analyzer", "summarizer"]
    )

    # Process a document
    job = {
        "type": "document_analysis",
        "document": {
            "path": "document.pdf",
            "type": "pdf"
        }
    }

    result = await pilott.execute([job])
```

## Supported Document Types

* PDF files
* Text documents
* Word documents (docx)
* HTML files

## Common Use Cases

1. **Document Analysis**
   ```python theme={null}
   job = {
       "type": "document_analysis",
       "description": "Analyze quarterly report"
   }
   ```

2. **Text Extraction**
   ```python theme={null}
   job = {
       "type": "text_extraction",
       "document": {"path": "file.pdf"}
   }
   ```

3. **Content Summarization**
   ```python theme={null}
   job = {
       "type": "summarization",
       "document": {"path": "article.txt"}
   }
   ```

## Configuration Options

Customize agent behavior:

```python theme={null}
config = AgentConfig(
    title="document_processor",
    goal="Process documents efficiently",
    max_concurrent_jobs=5,
    job_timeout=300
)
```

## Best Practices

1. **Document Handling**
   * Validate document formats before processing
   * Handle large documents in chunks
   * Implement proper error handling

2. **Performance**
   * Configure appropriate timeouts
   * Use concurrent processing when possible
   * Monitor memory usage for large documents

3. **Error Handling**
   * Validate input documents
   * Handle unsupported formats gracefully
   * Implement retry logic for failed operations

## Troubleshooting

Common issues and solutions:

1. **File Access Errors**
   * Ensure proper file permissions
   * Verify file paths are correct
   * Check file format compatibility

2. **Processing Timeouts**
   * Adjust job\_timeout in configuration
   * Process large documents in smaller chunks
   * Monitor system resources

## Example Output

```python theme={null}
# Example result
{
    'success': True,
    'output': {
        'summary': 'Document summary...',
        'analysis': 'Content analysis...',
        'metadata': {
            'pages': 5,
            'format': 'pdf',
            'processing_time': '2.3s'
        }
    }
}
```

## Code

Ready to use code [document\_processor.py](../../pilott/agents/document_processing.py)
