# Install dependencies:
# pip install crewai
# Set provider credentials, e.g. export OPENAI_API_KEY="your-key"
#
# Manager-style CrewAI workflow: manager coordinates research and writing.
# Hierarchical process delegates task execution to the manager.

from crewai import Agent, Task, Crew, Process

topic = "Agentic AI"


def main():
    research_agent = Agent(
        role="Research Agent",
        goal="Collect important information about the topic.",
        backstory="You are responsible for research and fact collection.",
        verbose=True,
    )
    writer_agent = Agent(
        role="Writer Agent",
        goal="Prepare a clear final report using the research.",
        backstory="You convert research into a structured report.",
        verbose=True,
    )
    manager_agent = Agent(
        role="Manager Agent",
        goal="Manage a team of AI agents and ensure the final task is completed.",
        backstory="You coordinate agents, assign tasks, and review their results.",
        allow_delegation=True,
        verbose=True,
    )

    research_task = Task(
        description=f"Research {topic} and collect important points.",
        expected_output="A concise research summary.",
        agent=research_agent,
    )
    writing_task = Task(
        description=f"Prepare a short report on {topic} using the research.",
        expected_output="A structured final report.",
        agent=writer_agent,
        context=[research_task],
    )
    manager_task = Task(
        description=(
            "Review and coordinate the research and writing work on "
            f"{topic}. Ensure the final response is clear and complete."
        ),
        expected_output="A reviewed and finalized report.",
        agent=manager_agent,
        context=[research_task, writing_task],
    )

    crew = Crew(
        agents=[manager_agent, research_agent, writer_agent],
        tasks=[research_task, writing_task, manager_task],
        process=Process.sequential,
        verbose=True,
    )
    result = crew.kickoff()
    print("\nMANAGER AGENT OUTPUT")
    print(result)


if __name__ == "__main__":
    main()
