#!/usr/bin/env python3
# security_vulnerability_summary.py
# Demonstrates the first use case: AI Security Vulnerability Summary

import os
from tbh_secure_agents import Expert, Operation, Squad

# --- !!! SECURITY WARNING !!! ---
# Using a hardcoded API key for testing ONLY. Replace with environment variables for production.
TESTING_API_KEY = "" # Key provided by user
# --- !!! /SECURITY WARNING !!! ---

print("--- Initializing Experts (AI Security Vulnerability) ---")
# Define Experts for the use case
try:
    security_researcher = Expert(
        specialty='Security Researcher',
        objective='Find the latest information on AI security vulnerabilities',
        background='An expert in cybersecurity with a focus on AI systems.',
        llm_model_name='gemini-2.0-flash-lite',
        security_profile='research_standard',
        api_key=TESTING_API_KEY
    )

    technical_writer = Expert(
        specialty='Technical Writer',
        objective='Summarize complex security information into concise reports',
        background='Skilled in communicating technical details clearly.',
        llm_model_name='gemini-2.0-flash-lite',
        security_profile='reporting_standard',
        api_key=TESTING_API_KEY
    )
except Exception as e:
    print(f"\nError initializing experts: {e}")
    exit()

print("\n--- Defining Operations (AI Security Vulnerability) ---")
# Define Operations for the use case
research_operation = Operation(
    instructions='Research and identify the top 3 AI security vulnerabilities reported in the last month.',
    output_format='A list of the top 3 vulnerabilities with brief descriptions.',
    expert=security_researcher
)

summary_operation = Operation(
    instructions='Based on the research findings, write a concise 2-paragraph summary for a non-technical audience.',
    output_format='A short summary explaining the vulnerabilities simply.',
    expert=technical_writer
    # Context will be passed automatically by the Squad in sequential mode
)

print("\n--- Creating Squad (AI Security Vulnerability) ---")
# Create Squad
security_squad = Squad(
    experts=[security_researcher, technical_writer],
    operations=[research_operation, summary_operation],
    process='sequential'
)

print("\n--- Deploying Squad (AI Security Vulnerability) ---")
# Deploy the Squad
try:
    final_summary = security_squad.deploy()

    print("\n--- Squad Execution Finished (AI Security Vulnerability) ---")

    research_findings = research_operation.result # Get the research from the first operation

    print("\nResearch Findings:")
    print("------------------")
    print(research_findings if research_findings else "# Error generating research findings.")
    print("------------------")

    print("\nFinal Summary:")
    print("-------------")
    print(final_summary if final_summary else "# Error generating summary.")
    print("-------------")

except Exception as e:
    print(f"\nAn error occurred during squad execution: {e}")

print("\n--- Example Script Finished ---")
