anderson-ufrj
commited on
Commit
·
d5b36b2
1
Parent(s):
f2c26ae
refactor(agents): migrate Tiradentes agent to new BaseAgent pattern
Browse files- Update constructor to use BaseAgent parameters (name, description, capabilities)
- Replace execute() method with process() returning AgentResponse
- Add initialize() and shutdown() methods as required by BaseAgent
- Update all agent_id references to use self.name
- Fix message parsing to use action/payload instead of message_type/content
- Update error handling and return types to match new pattern
This aligns Tiradentes agent with the modern agent architecture defined in deodoro.py
- src/agents/tiradentes.py +54 -29
src/agents/tiradentes.py
CHANGED
|
@@ -15,8 +15,8 @@ from enum import Enum
|
|
| 15 |
|
| 16 |
from pydantic import BaseModel, Field as PydanticField
|
| 17 |
|
| 18 |
-
from src.agents.deodoro import BaseAgent, AgentContext, AgentMessage
|
| 19 |
-
from src.core import get_logger
|
| 20 |
from src.core.exceptions import AgentExecutionError
|
| 21 |
|
| 22 |
|
|
@@ -83,7 +83,6 @@ class ReporterAgent(BaseAgent):
|
|
| 83 |
|
| 84 |
def __init__(
|
| 85 |
self,
|
| 86 |
-
agent_id: str = "reporter",
|
| 87 |
default_language: str = "pt",
|
| 88 |
max_report_length: int = 10000, # words
|
| 89 |
):
|
|
@@ -91,14 +90,27 @@ class ReporterAgent(BaseAgent):
|
|
| 91 |
Initialize the Reporter Agent.
|
| 92 |
|
| 93 |
Args:
|
| 94 |
-
agent_id: Unique identifier for this agent
|
| 95 |
default_language: Default language for reports
|
| 96 |
max_report_length: Maximum report length in words
|
| 97 |
"""
|
| 98 |
-
super().__init__(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
self.default_language = default_language
|
| 100 |
self.max_length = max_report_length
|
| 101 |
-
self.logger = get_logger(__name__)
|
| 102 |
|
| 103 |
# Report generators registry
|
| 104 |
self.report_generators = {
|
|
@@ -120,48 +132,58 @@ class ReporterAgent(BaseAgent):
|
|
| 120 |
|
| 121 |
self.logger.info(
|
| 122 |
"tiradentes_initialized",
|
| 123 |
-
|
| 124 |
default_language=default_language,
|
| 125 |
max_length=max_report_length,
|
| 126 |
)
|
| 127 |
|
| 128 |
-
async def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
self,
|
| 130 |
message: AgentMessage,
|
| 131 |
context: AgentContext
|
| 132 |
-
) ->
|
| 133 |
"""
|
| 134 |
-
|
| 135 |
|
| 136 |
Args:
|
| 137 |
message: Report request message
|
| 138 |
context: Agent execution context
|
| 139 |
|
| 140 |
Returns:
|
| 141 |
-
|
| 142 |
"""
|
| 143 |
try:
|
| 144 |
self.logger.info(
|
| 145 |
"report_generation_started",
|
| 146 |
investigation_id=context.investigation_id,
|
| 147 |
-
|
| 148 |
-
|
| 149 |
)
|
| 150 |
|
| 151 |
# Parse report request
|
| 152 |
-
if message.
|
| 153 |
-
request = ReportRequest(**message.
|
| 154 |
else:
|
| 155 |
raise AgentExecutionError(
|
| 156 |
-
f"Unsupported
|
| 157 |
-
agent_id=self.
|
| 158 |
)
|
| 159 |
|
| 160 |
# Validate input data
|
| 161 |
if not request.investigation_results and not request.analysis_results:
|
| 162 |
-
return
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
| 165 |
"status": "error",
|
| 166 |
"error": "No data provided for report generation",
|
| 167 |
"investigation_id": context.investigation_id,
|
|
@@ -184,7 +206,7 @@ class ReporterAgent(BaseAgent):
|
|
| 184 |
"metadata": {
|
| 185 |
"investigation_id": context.investigation_id,
|
| 186 |
"timestamp": datetime.utcnow().isoformat(),
|
| 187 |
-
"
|
| 188 |
"target_audience": request.target_audience,
|
| 189 |
"language": request.language,
|
| 190 |
"sections_count": len(report_sections),
|
|
@@ -200,9 +222,10 @@ class ReporterAgent(BaseAgent):
|
|
| 200 |
sections_count=len(report_sections),
|
| 201 |
)
|
| 202 |
|
| 203 |
-
return
|
| 204 |
-
|
| 205 |
-
|
|
|
|
| 206 |
metadata={"investigation_id": context.investigation_id}
|
| 207 |
)
|
| 208 |
|
|
@@ -211,12 +234,14 @@ class ReporterAgent(BaseAgent):
|
|
| 211 |
"report_generation_failed",
|
| 212 |
investigation_id=context.investigation_id,
|
| 213 |
error=str(e),
|
| 214 |
-
|
| 215 |
)
|
| 216 |
|
| 217 |
-
return
|
| 218 |
-
|
| 219 |
-
|
|
|
|
|
|
|
| 220 |
"status": "error",
|
| 221 |
"error": str(e),
|
| 222 |
"investigation_id": context.investigation_id,
|
|
@@ -245,7 +270,7 @@ class ReporterAgent(BaseAgent):
|
|
| 245 |
else:
|
| 246 |
raise AgentExecutionError(
|
| 247 |
f"Unsupported report type: {request.report_type}",
|
| 248 |
-
agent_id=self.
|
| 249 |
)
|
| 250 |
|
| 251 |
async def _generate_investigation_report(
|
|
|
|
| 15 |
|
| 16 |
from pydantic import BaseModel, Field as PydanticField
|
| 17 |
|
| 18 |
+
from src.agents.deodoro import BaseAgent, AgentContext, AgentMessage, AgentResponse
|
| 19 |
+
from src.core import get_logger, AgentStatus
|
| 20 |
from src.core.exceptions import AgentExecutionError
|
| 21 |
|
| 22 |
|
|
|
|
| 83 |
|
| 84 |
def __init__(
|
| 85 |
self,
|
|
|
|
| 86 |
default_language: str = "pt",
|
| 87 |
max_report_length: int = 10000, # words
|
| 88 |
):
|
|
|
|
| 90 |
Initialize the Reporter Agent.
|
| 91 |
|
| 92 |
Args:
|
|
|
|
| 93 |
default_language: Default language for reports
|
| 94 |
max_report_length: Maximum report length in words
|
| 95 |
"""
|
| 96 |
+
super().__init__(
|
| 97 |
+
name="Tiradentes",
|
| 98 |
+
description="Tiradentes - Agent specialized in generating natural language reports",
|
| 99 |
+
capabilities=[
|
| 100 |
+
"investigation_report_generation",
|
| 101 |
+
"pattern_analysis_reporting",
|
| 102 |
+
"executive_summary_creation",
|
| 103 |
+
"multi_format_rendering",
|
| 104 |
+
"audience_adaptation",
|
| 105 |
+
"data_visualization",
|
| 106 |
+
"recommendation_generation",
|
| 107 |
+
"transparency_reporting"
|
| 108 |
+
],
|
| 109 |
+
max_retries=3,
|
| 110 |
+
timeout=60
|
| 111 |
+
)
|
| 112 |
self.default_language = default_language
|
| 113 |
self.max_length = max_report_length
|
|
|
|
| 114 |
|
| 115 |
# Report generators registry
|
| 116 |
self.report_generators = {
|
|
|
|
| 132 |
|
| 133 |
self.logger.info(
|
| 134 |
"tiradentes_initialized",
|
| 135 |
+
agent_name=self.name,
|
| 136 |
default_language=default_language,
|
| 137 |
max_length=max_report_length,
|
| 138 |
)
|
| 139 |
|
| 140 |
+
async def initialize(self) -> None:
|
| 141 |
+
"""Initialize agent resources."""
|
| 142 |
+
self.logger.info(f"{self.name} agent initialized")
|
| 143 |
+
|
| 144 |
+
async def shutdown(self) -> None:
|
| 145 |
+
"""Cleanup agent resources."""
|
| 146 |
+
self.logger.info(f"{self.name} agent shutting down")
|
| 147 |
+
|
| 148 |
+
async def process(
|
| 149 |
self,
|
| 150 |
message: AgentMessage,
|
| 151 |
context: AgentContext
|
| 152 |
+
) -> AgentResponse:
|
| 153 |
"""
|
| 154 |
+
Process report generation request and return formatted report.
|
| 155 |
|
| 156 |
Args:
|
| 157 |
message: Report request message
|
| 158 |
context: Agent execution context
|
| 159 |
|
| 160 |
Returns:
|
| 161 |
+
AgentResponse with generated report
|
| 162 |
"""
|
| 163 |
try:
|
| 164 |
self.logger.info(
|
| 165 |
"report_generation_started",
|
| 166 |
investigation_id=context.investigation_id,
|
| 167 |
+
agent_name=self.name,
|
| 168 |
+
action=message.action,
|
| 169 |
)
|
| 170 |
|
| 171 |
# Parse report request
|
| 172 |
+
if message.action == "generate_report":
|
| 173 |
+
request = ReportRequest(**message.payload)
|
| 174 |
else:
|
| 175 |
raise AgentExecutionError(
|
| 176 |
+
f"Unsupported action: {message.action}",
|
| 177 |
+
agent_id=self.name
|
| 178 |
)
|
| 179 |
|
| 180 |
# Validate input data
|
| 181 |
if not request.investigation_results and not request.analysis_results:
|
| 182 |
+
return AgentResponse(
|
| 183 |
+
agent_name=self.name,
|
| 184 |
+
status=AgentStatus.ERROR,
|
| 185 |
+
error="No data provided for report generation",
|
| 186 |
+
result={
|
| 187 |
"status": "error",
|
| 188 |
"error": "No data provided for report generation",
|
| 189 |
"investigation_id": context.investigation_id,
|
|
|
|
| 206 |
"metadata": {
|
| 207 |
"investigation_id": context.investigation_id,
|
| 208 |
"timestamp": datetime.utcnow().isoformat(),
|
| 209 |
+
"agent_name": self.name,
|
| 210 |
"target_audience": request.target_audience,
|
| 211 |
"language": request.language,
|
| 212 |
"sections_count": len(report_sections),
|
|
|
|
| 222 |
sections_count=len(report_sections),
|
| 223 |
)
|
| 224 |
|
| 225 |
+
return AgentResponse(
|
| 226 |
+
agent_name=self.name,
|
| 227 |
+
status=AgentStatus.COMPLETED,
|
| 228 |
+
result=result,
|
| 229 |
metadata={"investigation_id": context.investigation_id}
|
| 230 |
)
|
| 231 |
|
|
|
|
| 234 |
"report_generation_failed",
|
| 235 |
investigation_id=context.investigation_id,
|
| 236 |
error=str(e),
|
| 237 |
+
agent_name=self.name,
|
| 238 |
)
|
| 239 |
|
| 240 |
+
return AgentResponse(
|
| 241 |
+
agent_name=self.name,
|
| 242 |
+
status=AgentStatus.ERROR,
|
| 243 |
+
error=str(e),
|
| 244 |
+
result={
|
| 245 |
"status": "error",
|
| 246 |
"error": str(e),
|
| 247 |
"investigation_id": context.investigation_id,
|
|
|
|
| 270 |
else:
|
| 271 |
raise AgentExecutionError(
|
| 272 |
f"Unsupported report type: {request.report_type}",
|
| 273 |
+
agent_id=self.name
|
| 274 |
)
|
| 275 |
|
| 276 |
async def _generate_investigation_report(
|