-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathsmol_blogwriter.py
107 lines (89 loc) · 3.32 KB
/
smol_blogwriter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from smolagents import (
CodeAgent,
ToolCallingAgent,
LiteLLMModel,
ManagedAgent,
DuckDuckGoSearchTool,
)
from smoltools.jinaai import scrape_page_with_jina_ai, search_facts_with_jina_ai
from dotenv import load_dotenv
import os
load_dotenv()
# Initialize the model
model = LiteLLMModel(model_id="gpt-4o-mini")
# Research Agent
research_agent = ToolCallingAgent(
tools=[scrape_page_with_jina_ai, search_facts_with_jina_ai, DuckDuckGoSearchTool()],
model=model,
max_steps=10,
)
managed_research_agent = ManagedAgent(
agent=research_agent,
name="super_researcher",
description="Researches topics thoroughly using web searches and content scraping. Provide the research topic as input.",
)
# Research Checker Agent
research_checker_agent = ToolCallingAgent(
tools=[],
model=model
)
managed_research_checker_agent = ManagedAgent(
agent=research_checker_agent,
name="research_checker",
description="Checks the research for relevance to the original task request. If the research is not relevant, it will ask for more research.",
)
# Writer Agent
writer_agent = ToolCallingAgent(
tools=[],
model=model
)
managed_writer_agent = ManagedAgent(
agent=writer_agent,
name="writer",
description="Writes blog posts based on the checkedresearch. Provide the research findings and desired tone/style.",
)
# Copy Editor Agent
copy_editor_agent = ToolCallingAgent(
tools=[],
model=model
)
managed_copy_editor = ManagedAgent(
agent=copy_editor_agent,
name="editor",
description="Reviews and polishes the blog post based on the research and original task request. Order the final blog post and any lists in a way that is most engaging to someone working in AI. Provides the final, edited version in markdown.",
)
# Main Blog Writer Manager
blog_manager = CodeAgent(
tools=[],
model=model,
managed_agents=[managed_research_agent, managed_research_checker_agent, managed_writer_agent, managed_copy_editor],
additional_authorized_imports=["re"],
# system_prompt="""You are a blog post creation manager. Coordinate between research, writing, and editing teams.
# Follow these steps:
# 1. Use research_agent to gather information
# 2. Pass research to research_checker_agent to check for relevance
# 3. Pass research to writer_agent to create the initial draft
# 4. Send draft to editor for final polish
# 4. Save the final markdown file
# """
)
def write_blog_post(topic, output_file="blog_post.md"):
"""
Creates a blog post on the given topic using multiple agents
Args:
topic (str): The blog post topic or title
output_file (str): The filename to save the markdown post
"""
result = blog_manager.run(f"""Create a blog post about: {topic}
1. First, research the topic thoroughly, focus on specific products and sources
2. Then, write an engaging blog post not just a list
3. Finally, edit and polish the content
""")
with open(output_file, 'w', encoding='utf-8') as f:
f.write(result)
print(f"Blog post has been saved to {output_file}")
return result
# print(blog_manager.system_prompt_template)
topic = "Create a blog post about the top 5 products released at CES 2025 so far. Please include specific product names and sources"
print(topic)
write_blog_post(topic)