from strands import Agent, tool
class InvestigationAgent:
self.agent: Optional[Agent] = None
self._config_version: Optional[str] = Nonedef _ensure_agent(self):
current_version = self._get_config_version()
if self.agent is None or self._config_version != current_version:
model = create_model_from_config()
system_prompt=self._get_system_prompt(self._lang),
self.list_ec2_instances,
self.describe_ec2_instance,
self.list_rds_instances,
self._config_version = current_version
@tooldef list_ec2_instances(self, state: str = "all") -> str:
state: 实例状态过滤 (running/stopped/all)
ec2 = boto3.client("ec2", region_name=self._region)
response = ec2.describe_instances(...)
result = f"找到 {len(instances)} 个 EC2 实例:\n"for inst in instances:
result += f" - {inst['id']} ({inst['name']}): {inst['type']}, {inst['state']}\n"return result