from fibonacci import Workflow, LLMNodeworkflow = Workflow(name="content-pipeline")# Step 1: Generate outlineoutliner = LLMNode( id="create_outline", model="claude-sonnet-5", prompt="Create an outline for: {{input.topic}}")# Step 2: Write draftwriter = LLMNode( id="write_draft", model="claude-sonnet-5", prompt="Write content following this outline: {{create_outline}}", dependencies=["create_outline"])# Step 3: Edit and polisheditor = LLMNode( id="edit_content", model="claude-sonnet-5", prompt="Edit for clarity and style: {{write_draft}}", dependencies=["write_draft"])# Step 4: Final reviewreviewer = LLMNode( id="final_review", model="claude-opus-5", # Premium model for final check prompt="Final quality review: {{edit_content}}", dependencies=["edit_content"])
Parallel Processing
Maximize throughput with parallel execution:
workflow = Workflow(name="multi-analysis")# These run in parallel (no dependencies)sentiment = LLMNode( id="sentiment", model="claude-haiku-4-5-20251001", prompt="Sentiment: {{input.text}}")entities = LLMNode( id="entities", model="claude-haiku-4-5-20251001", prompt="Extract entities: {{input.text}}")summary = LLMNode( id="summary", model="claude-haiku-4-5-20251001", prompt="Summarize: {{input.text}}")# Combine resultscombine = LLMNode( id="combine", model="claude-sonnet-5", prompt=""" Combine these analyses: Sentiment: {{sentiment}} Entities: {{entities}} Summary: {{summary}} """, dependencies=["sentiment", "entities", "summary"])
Critic Pattern for Quality
Use CriticNode for iterative improvement:
from fibonacci import LLMNode, CriticNodewriter = LLMNode( id="writer", model="claude-sonnet-5", prompt="Write a professional email: {{input.request}}")critic = CriticNode( id="quality_critic", model="claude-sonnet-5", target_node="writer", criteria=[ "Professional tone throughout", "Clear and concise language", "Proper grammar and spelling", "Appropriate length (not too long)", "Clear call to action" ], min_score=8, max_iterations=3, improvement_prompt=""" Improve the email based on this feedback: {{feedback}} Original email: {{writer}} """)
Prompt Engineering
Use Clear Structure
analyzer = LLMNode( id="analyzer", model="claude-sonnet-5", prompt="""You are analyzing customer feedback for a software company.<context>Product: {{input.product_name}}Customer tier: {{input.customer_tier}}</context><feedback>{{input.feedback_text}}</feedback><instructions>1. Identify the main issue or request2. Assess the urgency (low/medium/high/critical)3. Categorize: bug, feature_request, question, complaint, praise4. Suggest an appropriate response approach</instructions><output_format>Return JSON:{ "main_issue": "...", "urgency": "...", "category": "...", "response_approach": "..."}</output_format>""")
Include Examples (Few-Shot)
classifier = LLMNode( id="intent_classifier", model="claude-sonnet-5", prompt="""Classify the customer intent.<examples>Input: "I can't log into my account"Output: {"intent": "technical_support", "urgency": "high"}Input: "Do you offer annual billing?"Output: {"intent": "billing_question", "urgency": "low"}Input: "This is unacceptable, I want a refund!"Output: {"intent": "complaint", "urgency": "high"}Input: "Love the new feature!"Output: {"intent": "feedback_positive", "urgency": "low"}</examples><input>{{input.message}}</input>Classify this input following the same format as the examples.""")
# Use Haiku for simple, high-volume tasksclassifier = LLMNode( id="quick_classify", model="claude-haiku-4-5-20251001", # Fast and cost-effective prompt="Classify as spam/not_spam: {{input.text}}")# Use Opus for complex analysisdeep_analyzer = LLMNode( id="deep_analysis", model="claude-opus-5", # Most capable prompt="Provide comprehensive analysis: {{input.text}}")
Optimize Token Usage
# Be concise in prompts# ❌ Verboseverbose = LLMNode( id="verbose", prompt="""I would like you to please analyze the following text and provide me with a detailed sentiment analysis. The text is provided below for your analysis...""")# ✅ Conciseconcise = LLMNode( id="concise", prompt="Analyze sentiment: {{input.text}}\nReturn: positive/negative/neutral")
Cache Expensive Operations
from fibonacci import Workflowfrom fibonacci.patterns import cachedworkflow = Workflow(name="cached-workflow")@cached(ttl=3600) # Cache for 1 hourdef expensive_analysis(text: str): return workflow.execute(inputs={"text": text})# Or use memory-based cachingdef get_or_compute(workflow, key: str, compute_fn): cached = workflow.memory.get(f"cache:{key}", scope="organization") if cached: return cached result = compute_fn() workflow.memory.set( f"cache:{key}", result, scope="organization", ttl=3600 ) return result
Testing
Unit Test Nodes
import pytestfrom fibonacci import LLMNodefrom fibonacci.testing import MockLLMdef test_sentiment_classifier(): # Mock the LLM response mock = MockLLM(responses={ "positive": '{"sentiment": "positive", "confidence": 0.95}' }) node = LLMNode( id="sentiment", model=mock, prompt="Classify: {{input.text}}" ) result = node.execute({"text": "I love this product!"}) assert result["sentiment"] == "positive" assert result["confidence"] > 0.9
Integration Test Workflows
def test_support_workflow(): workflow = Workflow.from_yaml("workflows/support.yaml") # Test happy path result = workflow.execute( inputs={ "message": "How do I reset my password?", "customer_id": "test-123" } ) assert result["category"] == "technical_support" assert "password" in result["response"].lower()def test_error_handling(): workflow = Workflow.from_yaml("workflows/support.yaml") # Test with invalid input with pytest.raises(ValidationError): workflow.execute(inputs={"message": ""})
Use Test Fixtures
import pytestfrom fibonacci import Workflow@pytest.fixturedef sample_workflow(): return Workflow.from_yaml("test_fixtures/sample.yaml")@pytest.fixturedef test_inputs(): return { "text": "Sample text for testing", "user_id": "test-user" }def test_workflow_execution(sample_workflow, test_inputs): result = sample_workflow.execute(inputs=test_inputs) assert "output" in result
Deployment
Environment Separation
# fibonacci.yamlenvironments: development: model_default: claude-haiku-4-5-20251001 # Cheaper for dev timeout_default: 30 log_level: debug staging: model_default: claude-sonnet-5 timeout_default: 60 log_level: info production: model_default: claude-sonnet-5 timeout_default: 120 log_level: warning retry_default: 3