Agents
This section details the responsibilities and logic of each agent in the OpenGIN Tracer system.
Agent 0: Orchestrator
Role: Lifecycle Management & Coordination
The Orchestrator is the entry point for any pipeline run. Its duties include:
- Generating unique
run_ids for tracking. - Creating the directory structure for the pipeline (input, intermediate, output folders).
- invoking the subsequent agents in the correct order.
- Handling global error states and metadata updates.
Agent 1: Scanner
Role: Document Processing & Extraction
The Scanner extracts raw data from the source document.
- Input: A raw PDF file.
- Process:
- Splits the PDF into single-page PDF files using
pypdf. - Iterates through each page.
- Sends the page to Google Gemini 2.0 Flash (configurable via environment variable) with a prompt to "Extract all tables".
- Metadata (Optional): If a schema is provided, it also instructs the model to extract specific metadata fields for each table.
- Parses the JSON response from Gemini.
- Splits the PDF into single-page PDF files using
- Output: A collection of JSON files in the
intermediate/directory, one per page.
Agent 2: Aggregator
Role: Data Consolidation
The Aggregator combines the fragmented page-level data.
- Input: The collection of
intermediate/page_*.jsonfiles. - Process:
- Reads all intermediate files in order.
- Aggregates tables that might span multiple pages (future capability) or simply collects all tables into a master list.
- Metadata Handling: Preserves table-level metadata during aggregation.
- Output: A single
aggregated/tables.jsonfile containing all extracted data.
Agent 3: Exporter
Role: Final Output Generation
The Exporter formats the data for consumption.
- Input: The
aggregated/tables.jsonfile. - Process:
- Transforms the hierarchical JSON structure into a flat format suitable for analysis or database insertion.
- Uses
csvmodule to generate CSV files for each table. - Exports associated metadata as JSON files if present.
- Output: Final files in the
output/directory (e.g.,table_name.csv,table_name_metadata.json).