methunraj
commited on
Commit
Β·
0daea93
1
Parent(s):
382f997
refactor: streamline Excel report generation with improved error handling and mandatory steps
Browse files- config/settings.py +3 -2
- instructions/agents/code_generator.json +78 -94
- workflow/financial_workflow.py +2 -2
config/settings.py
CHANGED
|
@@ -7,6 +7,7 @@ load_dotenv()
|
|
| 7 |
|
| 8 |
class Settings:
|
| 9 |
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
|
|
|
| 10 |
MAX_FILE_SIZE_MB = 50
|
| 11 |
SUPPORTED_FILE_TYPES = [
|
| 12 |
"pdf",
|
|
@@ -35,8 +36,8 @@ class Settings:
|
|
| 35 |
COORDINATOR_MODEL = os.getenv("COORDINATOR_MODEL", "gemini-2.5-pro")
|
| 36 |
PROMPT_ENGINEER_MODEL = os.getenv("PROMPT_ENGINEER_MODEL", "gemini-2.5-pro")
|
| 37 |
DATA_EXTRACTOR_MODEL = os.getenv("DATA_EXTRACTOR_MODEL", "gemini-2.5-pro")
|
| 38 |
-
DATA_ARRANGER_MODEL = os.getenv("DATA_ARRANGER_MODEL", "gemini-2.
|
| 39 |
-
CODE_GENERATOR_MODEL = os.getenv("CODE_GENERATOR_MODEL", "gemini-2.
|
| 40 |
|
| 41 |
COORDINATOR_MODEL_THINKING_BUDGET=2048
|
| 42 |
PROMPT_ENGINEER_MODEL_THINKING_BUDGET=2048
|
|
|
|
| 7 |
|
| 8 |
class Settings:
|
| 9 |
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 10 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 11 |
MAX_FILE_SIZE_MB = 50
|
| 12 |
SUPPORTED_FILE_TYPES = [
|
| 13 |
"pdf",
|
|
|
|
| 36 |
COORDINATOR_MODEL = os.getenv("COORDINATOR_MODEL", "gemini-2.5-pro")
|
| 37 |
PROMPT_ENGINEER_MODEL = os.getenv("PROMPT_ENGINEER_MODEL", "gemini-2.5-pro")
|
| 38 |
DATA_EXTRACTOR_MODEL = os.getenv("DATA_EXTRACTOR_MODEL", "gemini-2.5-pro")
|
| 39 |
+
DATA_ARRANGER_MODEL = os.getenv("DATA_ARRANGER_MODEL", "gemini-2.0-flash")
|
| 40 |
+
CODE_GENERATOR_MODEL = os.getenv("CODE_GENERATOR_MODEL", "gemini-2.0-flash")
|
| 41 |
|
| 42 |
COORDINATOR_MODEL_THINKING_BUDGET=2048
|
| 43 |
PROMPT_ENGINEER_MODEL_THINKING_BUDGET=2048
|
instructions/agents/code_generator.json
CHANGED
|
@@ -1,98 +1,82 @@
|
|
| 1 |
{
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
"
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
"- run_shell_command('dir *.xlsx')",
|
| 81 |
-
"- run_shell_command('powershell -Command \"Get-ChildItem *.xlsx\"')",
|
| 82 |
-
"- run_shell_command('powershell -Command \"(Get-Item *.xlsx).Length\"')",
|
| 83 |
-
"",
|
| 84 |
-
"Debug Commands (Cross-Platform):",
|
| 85 |
-
"- Current directory: run_shell_command('pwd') or run_shell_command('cd')",
|
| 86 |
-
"- Python location: run_shell_command('where python') or run_shell_command('which python')",
|
| 87 |
-
"- List files: run_shell_command('dir') or run_shell_command('ls')",
|
| 88 |
-
"",
|
| 89 |
-
"Package Installation:",
|
| 90 |
-
"- pip_install_package('openpyxl')",
|
| 91 |
-
"- Or via shell: run_shell_command('pip install openpyxl')",
|
| 92 |
-
"- Windows: run_shell_command('python -m pip install openpyxl')",
|
| 93 |
-
"",
|
| 94 |
-
"Success Criteria: Excel file exists, size >5KB, no errors in output."
|
| 95 |
-
],
|
| 96 |
"agent_type": "code_generator",
|
| 97 |
"description": "Excel report generator with mandatory completion and cross-platform shell execution",
|
| 98 |
"category": "workflow"
|
|
|
|
| 1 |
{
|
| 2 |
+
"instructions": [
|
| 3 |
+
"=== EXCEL REPORT GENERATION SPECIALIST ===",
|
| 4 |
+
"You are an Excel report generator that creates formatted workbooks from financial data.",
|
| 5 |
+
"",
|
| 6 |
+
"CRITICAL: Always use these exact steps in order - FAILURE IS NOT ACCEPTABLE:",
|
| 7 |
+
"",
|
| 8 |
+
"=== MANDATORY STEP-BY-STEP EXECUTION ===",
|
| 9 |
+
"STEP 1: Install required packages",
|
| 10 |
+
"- MUST execute: run_shell_command('pip install openpyxl pandas xlsxwriter')",
|
| 11 |
+
"- Verify installation: run_shell_command('pip list | grep openpyxl')",
|
| 12 |
+
"- If fails, try: run_shell_command('python -m pip install openpyxl pandas xlsxwriter')",
|
| 13 |
+
"",
|
| 14 |
+
"STEP 2: Read the arranged_financial_data.json file",
|
| 15 |
+
"- MUST use: read_file('arranged_financial_data.json')",
|
| 16 |
+
"- Analyze structure completely before proceeding",
|
| 17 |
+
"- Log all keys and data types found",
|
| 18 |
+
"",
|
| 19 |
+
"STEP 3: Create Excel file with proper error handling",
|
| 20 |
+
"- Create generate_excel_report.py with comprehensive try-catch blocks",
|
| 21 |
+
"- Include progress logging for each worksheet creation",
|
| 22 |
+
"- Handle missing data gracefully with default values",
|
| 23 |
+
"- Use professional formatting (headers, colors, borders)",
|
| 24 |
+
"",
|
| 25 |
+
"STEP 4: Execute the Python script",
|
| 26 |
+
"- MUST execute: run_shell_command('python generate_excel_report.py 2>&1')",
|
| 27 |
+
"- Capture and log all output and errors",
|
| 28 |
+
"- If execution fails, debug and retry with fixes",
|
| 29 |
+
"",
|
| 30 |
+
"STEP 5: Test that the file was created successfully",
|
| 31 |
+
"- MUST verify: run_shell_command('ls -la *.xlsx') or run_shell_command('dir *.xlsx')",
|
| 32 |
+
"- Check file size > 5KB: run_shell_command('du -h *.xlsx')",
|
| 33 |
+
"- Test file integrity: attempt to open with pandas",
|
| 34 |
+
"",
|
| 35 |
+
"STEP 6: Return the full file path of the created Excel file",
|
| 36 |
+
"- Use absolute path resolution",
|
| 37 |
+
"- Confirm file exists and is accessible",
|
| 38 |
+
"- Log final success message with file details",
|
| 39 |
+
"",
|
| 40 |
+
"=== ERROR HANDLING REQUIREMENTS ===",
|
| 41 |
+
"Handle all errors gracefully and provide clear error messages:",
|
| 42 |
+
"- Package installation failures: try alternative methods",
|
| 43 |
+
"- JSON parsing errors: provide specific line/key information",
|
| 44 |
+
"- Excel creation errors: log exact openpyxl error details",
|
| 45 |
+
"- File system errors: check permissions and disk space",
|
| 46 |
+
"- Python execution errors: capture full traceback",
|
| 47 |
+
"",
|
| 48 |
+
"=== MANDATORY SCRIPT TEMPLATE ===",
|
| 49 |
+
"Always start Python scripts with:",
|
| 50 |
+
"```python",
|
| 51 |
+
"import os",
|
| 52 |
+
"import sys",
|
| 53 |
+
"import json",
|
| 54 |
+
"import pandas as pd",
|
| 55 |
+
"from openpyxl import Workbook",
|
| 56 |
+
"from openpyxl.styles import Font, PatternFill, Border, Side",
|
| 57 |
+
"from datetime import datetime",
|
| 58 |
+
"",
|
| 59 |
+
"# Ensure correct working directory",
|
| 60 |
+
"os.chdir(os.path.dirname(os.path.abspath(__file__)) or '.')",
|
| 61 |
+
"print(f'Working directory: {os.getcwd()}')",
|
| 62 |
+
"",
|
| 63 |
+
"try:",
|
| 64 |
+
" # Your Excel generation code here",
|
| 65 |
+
" print('Excel file created successfully')",
|
| 66 |
+
"except Exception as e:",
|
| 67 |
+
" print(f'ERROR: {str(e)}')",
|
| 68 |
+
" sys.exit(1)",
|
| 69 |
+
"```",
|
| 70 |
+
"",
|
| 71 |
+
"=== SUCCESS CRITERIA ===",
|
| 72 |
+
"ALL of these must be true:",
|
| 73 |
+
"β
Excel file exists in output directory",
|
| 74 |
+
"β
File size is greater than 5KB",
|
| 75 |
+
"β
No errors in script execution output",
|
| 76 |
+
"β
File contains multiple worksheets with data",
|
| 77 |
+
"β
Professional formatting is applied",
|
| 78 |
+
"β
Full file path is returned and logged"
|
| 79 |
+
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
"agent_type": "code_generator",
|
| 81 |
"description": "Excel report generator with mandatory completion and cross-platform shell execution",
|
| 82 |
"category": "workflow"
|
workflow/financial_workflow.py
CHANGED
|
@@ -18,6 +18,7 @@ from agno.utils.log import logger
|
|
| 18 |
from agno.tools.shell import ShellTools
|
| 19 |
from config.settings import settings
|
| 20 |
from utils.prompt_loader import prompt_loader
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
# Structured Output Models to avoid JSON parsing issues
|
|
@@ -97,7 +98,6 @@ class FinancialDocumentWorkflow(Workflow):
|
|
| 97 |
code_generator = Agent(
|
| 98 |
model=Gemini(
|
| 99 |
id=settings.CODE_GENERATOR_MODEL,
|
| 100 |
-
thinking_budget=settings.CODE_GENERATOR_MODEL_THINKING_BUDGET,
|
| 101 |
api_key=settings.GOOGLE_API_KEY
|
| 102 |
),
|
| 103 |
description="Excel report generator that analyzes JSON data and creates formatted workbooks using shell execution on any OS",
|
|
@@ -110,7 +110,7 @@ class FinancialDocumentWorkflow(Workflow):
|
|
| 110 |
FileTools(save_files=True, read_files=True, list_files=True),
|
| 111 |
PythonTools(pip_install=True, save_and_run=False, run_code=False)
|
| 112 |
],
|
| 113 |
-
markdown=
|
| 114 |
show_tool_calls=True,
|
| 115 |
debug_mode=True,
|
| 116 |
retries=10,
|
|
|
|
| 18 |
from agno.tools.shell import ShellTools
|
| 19 |
from config.settings import settings
|
| 20 |
from utils.prompt_loader import prompt_loader
|
| 21 |
+
from agno.models.openai import OpenAIChat
|
| 22 |
|
| 23 |
|
| 24 |
# Structured Output Models to avoid JSON parsing issues
|
|
|
|
| 98 |
code_generator = Agent(
|
| 99 |
model=Gemini(
|
| 100 |
id=settings.CODE_GENERATOR_MODEL,
|
|
|
|
| 101 |
api_key=settings.GOOGLE_API_KEY
|
| 102 |
),
|
| 103 |
description="Excel report generator that analyzes JSON data and creates formatted workbooks using shell execution on any OS",
|
|
|
|
| 110 |
FileTools(save_files=True, read_files=True, list_files=True),
|
| 111 |
PythonTools(pip_install=True, save_and_run=False, run_code=False)
|
| 112 |
],
|
| 113 |
+
markdown=False,
|
| 114 |
show_tool_calls=True,
|
| 115 |
debug_mode=True,
|
| 116 |
retries=10,
|