from fibonacci import Workflow, LLMNode, CriticNode
workflow = Workflow(name="blog-writer")
# Generate blog post
writer = LLMNode(
id="writer",
model="claude-sonnet-4-5-20250929",
prompt="""Write a blog post about {{input.topic}}.
Target audience: {{input.audience}}
Desired length: {{input.length}} words
Tone: {{input.tone}}
"""
)
# Quality assurance
critic = CriticNode(
id="quality_assurance",
model="claude-opus-4-5-20251101", # Use best model for evaluation
target_node="writer",
criteria=[
"Content is engaging from the first paragraph",
"Information is accurate and well-researched",
"Writing style matches the target audience",
"Post is close to the requested length",
"Tone is consistent throughout",
"Includes actionable takeaways",
"Has a compelling conclusion"
],
min_score=8,
max_iterations=3,
improvement_prompt="""
Improve this blog post based on the editorial feedback:
**Editorial Feedback:**
{{feedback}}
**Scores by Criterion:**
{{criteria_scores}}
**Current Draft:**
{{writer}}
**Requirements:**
- Topic: {{input.topic}}
- Audience: {{input.audience}}
- Length: {{input.length}} words
- Tone: {{input.tone}}
Revise the post to address the feedback while maintaining the requirements.
"""
)
workflow.add_node(writer)
workflow.add_node(critic)
# Execute
result = workflow.execute(inputs={
"topic": "Introduction to Machine Learning",
"audience": "business professionals",
"length": 800,
"tone": "informative yet approachable"
})
# Output
if result["quality_assurance"]["passed"]:
print("Final blog post:")
print(result["quality_assurance"]["final_output"])
else:
print("Could not achieve quality threshold")
print(f"Best score: {result['quality_assurance']['overall_score']}")