from crewai import LLM, Agent, Task, Crew

# Instantiate the local LLaMA‑3 model via Ollama
llm_local = LLM(
    model="ollama/llama3",  # Make sure this matches your Ollama model name
    base_url="http://localhost:11434",
    api_key=""  # Not needed for Ollama but required by interface
)

# Define Agents
researcher = Agent(
    role="Researcher",
    goal="Collect recent news about Artificial Intelligence developments",
    backstory="An expert tech journalist",
    verbose=True,
    allow_delegation=False,
    llm=llm_local
)

writer = Agent(
    role="Writer",
    goal="Write a concise and informative blog post based on research",
    backstory="A skilled content writer",
    verbose=True,
    allow_delegation=False,
    llm=llm_local
)

# Define Tasks
research_task = Task(
    description="Find and summarize the top 3 recent AI developments as of this week.",
    expected_output="A list of 3 bullet points with summaries and source URLs.",
    agent=researcher
)

writing_task = Task(
    description="Using the research summary, write a blog post titled 'Top 3 AI Breakthroughs This Week'.",
    expected_output="A 300‑500 word well‑structured blog post.",
    agent=writer,
    context=[research_task]
)

# Create the Crew and run
crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, writing_task],
    verbose=True
)

result = crew.kickoff()
print("\n📝 Final Blog Post:\n", result)
