fix(agents): resolve import errors and complete Lampião IBGE integration
Browse filesFixed critical import errors preventing system initialization:
- ExternalAPIError → ExternalServiceError in dados_gov_api.py
- Created ToolResult dataclass in dados_gov_tool.py (removed non-existent base.py dependency)
- Added shutdown() method to LampiaoAgent to comply with BaseAgent abstract interface
Completed Lampião agent IBGE data integration:
- Initialized states_data attribute in __init__
- Added geographic_boundaries, regional_indicators, and spatial indices initialization
- Verified IBGE data loading: 27 states with population, GDP per capita, HDI, and density metrics
- All data sourced from IBGE 2023-2024 estimates
Testing:
- Created test_lampiao_ibge.py validation script
- Confirmed successful loading of all Brazilian state data
- Sample verification: São Paulo with 46.6M population, R$59.3k GDP/capita, 0.826 HDI
- src/agents/lampiao.py +24 -5
- src/tools/dados_gov_api.py +2 -2
- src/tools/dados_gov_tool.py +15 -8
|
@@ -245,12 +245,20 @@ class LampiaoAgent(BaseAgent):
|
|
| 245 |
"significance_level": 0.05
|
| 246 |
}
|
| 247 |
|
| 248 |
-
# Brazilian regions data
|
| 249 |
-
self.
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
# Spatial weights matrices cache
|
| 252 |
self.spatial_weights = {}
|
| 253 |
-
|
| 254 |
# Analysis results cache
|
| 255 |
self.analysis_cache = {}
|
| 256 |
|
|
@@ -900,4 +908,15 @@ class LampiaoAgent(BaseAgent):
|
|
| 900 |
|
| 901 |
except Exception as e:
|
| 902 |
self.logger.error(f"Failed to load IBGE indicators: {e}")
|
| 903 |
-
self.regional_indicators = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
"significance_level": 0.05
|
| 246 |
}
|
| 247 |
|
| 248 |
+
# Brazilian states/regions data (IBGE)
|
| 249 |
+
self.states_data = self._initialize_brazil_regions()
|
| 250 |
+
self.brazil_regions = self.states_data # Alias for compatibility
|
| 251 |
+
|
| 252 |
+
# Geographic data (initialized by initialize())
|
| 253 |
+
self.geographic_boundaries = {}
|
| 254 |
+
self.regional_indicators = {}
|
| 255 |
+
self.region_index = {}
|
| 256 |
+
self.capital_index = {}
|
| 257 |
+
self.state_name_index = {}
|
| 258 |
+
|
| 259 |
# Spatial weights matrices cache
|
| 260 |
self.spatial_weights = {}
|
| 261 |
+
|
| 262 |
# Analysis results cache
|
| 263 |
self.analysis_cache = {}
|
| 264 |
|
|
|
|
| 908 |
|
| 909 |
except Exception as e:
|
| 910 |
self.logger.error(f"Failed to load IBGE indicators: {e}")
|
| 911 |
+
self.regional_indicators = {}
|
| 912 |
+
|
| 913 |
+
async def shutdown(self) -> None:
|
| 914 |
+
"""Cleanup agent resources."""
|
| 915 |
+
self.logger.info("Lampião agent shutting down...")
|
| 916 |
+
# Clear cached data
|
| 917 |
+
self.geographic_boundaries = {}
|
| 918 |
+
self.regional_indicators = {}
|
| 919 |
+
self.region_index = {}
|
| 920 |
+
self.capital_index = {}
|
| 921 |
+
self.state_name_index = {}
|
| 922 |
+
self.logger.info("Lampião agent shutdown complete")
|
|
@@ -14,12 +14,12 @@ import httpx
|
|
| 14 |
from pydantic import BaseModel, Field
|
| 15 |
|
| 16 |
from src.core.config import settings
|
| 17 |
-
from src.core.exceptions import
|
| 18 |
|
| 19 |
logger = logging.getLogger(__name__)
|
| 20 |
|
| 21 |
|
| 22 |
-
class DadosGovAPIError(
|
| 23 |
"""Custom exception for Dados.gov.br API errors"""
|
| 24 |
pass
|
| 25 |
|
|
|
|
| 14 |
from pydantic import BaseModel, Field
|
| 15 |
|
| 16 |
from src.core.config import settings
|
| 17 |
+
from src.core.exceptions import ExternalServiceError
|
| 18 |
|
| 19 |
logger = logging.getLogger(__name__)
|
| 20 |
|
| 21 |
|
| 22 |
+
class DadosGovAPIError(ExternalServiceError):
|
| 23 |
"""Custom exception for Dados.gov.br API errors"""
|
| 24 |
pass
|
| 25 |
|
|
@@ -8,35 +8,42 @@ Open Data Portal (dados.gov.br) to enhance their investigations.
|
|
| 8 |
import json
|
| 9 |
import logging
|
| 10 |
from typing import Any, Dict, List, Optional, Union
|
|
|
|
| 11 |
|
| 12 |
from src.services.dados_gov_service import DadosGovService
|
| 13 |
-
from src.tools.base import BaseTool, ToolResult
|
| 14 |
from src.tools.dados_gov_api import DadosGovAPIError
|
| 15 |
|
| 16 |
logger = logging.getLogger(__name__)
|
| 17 |
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
"""
|
| 21 |
Tool for accessing Brazilian Open Data Portal (dados.gov.br).
|
| 22 |
-
|
| 23 |
This tool enables agents to search for government datasets,
|
| 24 |
analyze data availability, and find specific types of public data.
|
| 25 |
"""
|
| 26 |
-
|
| 27 |
name = "dados_gov_search"
|
| 28 |
description = (
|
| 29 |
"Search and analyze Brazilian government open data from dados.gov.br. "
|
| 30 |
"Use this to find datasets about government spending, contracts, "
|
| 31 |
"education, health, and other public data."
|
| 32 |
)
|
| 33 |
-
|
| 34 |
def __init__(self):
|
| 35 |
"""Initialize the dados.gov.br tool"""
|
| 36 |
-
super().__init__()
|
| 37 |
self.service = DadosGovService()
|
| 38 |
-
|
| 39 |
-
async def
|
| 40 |
self,
|
| 41 |
query: Optional[str] = None,
|
| 42 |
action: str = "search",
|
|
|
|
| 8 |
import json
|
| 9 |
import logging
|
| 10 |
from typing import Any, Dict, List, Optional, Union
|
| 11 |
+
from dataclasses import dataclass
|
| 12 |
|
| 13 |
from src.services.dados_gov_service import DadosGovService
|
|
|
|
| 14 |
from src.tools.dados_gov_api import DadosGovAPIError
|
| 15 |
|
| 16 |
logger = logging.getLogger(__name__)
|
| 17 |
|
| 18 |
|
| 19 |
+
@dataclass
|
| 20 |
+
class ToolResult:
|
| 21 |
+
"""Result from tool execution"""
|
| 22 |
+
success: bool
|
| 23 |
+
data: Any
|
| 24 |
+
error: Optional[str] = None
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class DadosGovTool:
|
| 28 |
"""
|
| 29 |
Tool for accessing Brazilian Open Data Portal (dados.gov.br).
|
| 30 |
+
|
| 31 |
This tool enables agents to search for government datasets,
|
| 32 |
analyze data availability, and find specific types of public data.
|
| 33 |
"""
|
| 34 |
+
|
| 35 |
name = "dados_gov_search"
|
| 36 |
description = (
|
| 37 |
"Search and analyze Brazilian government open data from dados.gov.br. "
|
| 38 |
"Use this to find datasets about government spending, contracts, "
|
| 39 |
"education, health, and other public data."
|
| 40 |
)
|
| 41 |
+
|
| 42 |
def __init__(self):
|
| 43 |
"""Initialize the dados.gov.br tool"""
|
|
|
|
| 44 |
self.service = DadosGovService()
|
| 45 |
+
|
| 46 |
+
async def execute(
|
| 47 |
self,
|
| 48 |
query: Optional[str] = None,
|
| 49 |
action: str = "search",
|