# Start with a clear problem statement# What task does this recipe automate?# Who is the target user?# What are the expected inputs and outputs?# Example: Support Reply Drafter# Problem: Support agents spend too much time drafting replies# User: Support team members# Input: Ticket ID, customer message# Output: Draft reply text
# recipe.pyfrom praisonaiagents import Agent, Task, PraisonAIAgentsdef run(input_data: dict, config: dict = None) -> dict: """ Generate a support reply draft. Args: input_data: Contains ticket_id, message, and optional tone config: Optional configuration overrides Returns: Dict with reply and confidence score """ ticket_id = input_data.get("ticket_id") message = input_data.get("message") tone = input_data.get("tone", "professional") # Create support agent support_agent = Agent( name="Support Specialist", role="Customer Support Expert", goal=f"Draft a {tone} reply to customer inquiries", instructions=""" You are an expert customer support specialist. - Be helpful and empathetic - Address the customer's concern directly - Provide clear next steps if applicable - Keep responses concise but complete """, ) # Create task task = Task( name="draft_reply", description=f""" Draft a {tone} reply to this customer message: Ticket: {ticket_id} Message: {message} Provide a professional, helpful response. """, expected_output="A well-crafted support reply", agent=support_agent, ) # Execute agents = PraisonAIAgents( agents=[support_agent], tasks=[task], ) result = agents.start() return { "reply": result.get("task_output", ""), "confidence": 0.85, # Could be calculated from model response }
4
Write Tests
Copy
# test_recipe.pyimport pytestfrom recipe import rundef test_basic_reply(): """Test basic reply generation.""" result = run({ "ticket_id": "T-123", "message": "I can't log into my account", }) assert "reply" in result assert len(result["reply"]) > 50 assert result["confidence"] > 0.5def test_tone_professional(): """Test professional tone.""" result = run({ "ticket_id": "T-124", "message": "Your product is broken!", "tone": "professional", }) assert "reply" in result # Should not contain informal language assert "hey" not in result["reply"].lower()def test_tone_friendly(): """Test friendly tone.""" result = run({ "ticket_id": "T-125", "message": "How do I reset my password?", "tone": "friendly", }) assert "reply" in resultdef test_missing_required_field(): """Test error handling for missing fields.""" with pytest.raises(ValueError): run({"ticket_id": "T-126"}) # Missing message@pytest.mark.integrationdef test_end_to_end(): """Full integration test.""" from praisonai import recipe result = recipe.run( "support-reply-drafter", input={ "ticket_id": "T-127", "message": "I need a refund", } ) assert result.ok assert result.output.get("reply")
5
Document the Recipe
Create a README.md with:
Title and description - What the recipe does
Quick start - Minimal example to get started
Inputs table - All parameters with types and descriptions
Outputs table - What the recipe returns
Examples - Multiple usage scenarios
Requirements - Dependencies and environment variables
Troubleshooting - Common issues and solutions
Example README structure:
Copy
# Recipe NameDescription of what the recipe does.## Quick Startpraisonai recipe run my-recipe --input '{"key": "value"}'## Inputs| Field | Type | Required | Description ||-------|------|----------|-------------|| field1 | string | Yes | Description |## Outputs| Field | Type | Description ||-------|------|-------------|| output1 | string | Description |## Examples[Code examples for different use cases]## Requirements- OPENAI_API_KEY environment variable- praisonaiagents package## TroubleshootingCommon issues and solutions
# Unit tests - fast, isolateddef test_input_validation(): with pytest.raises(ValueError): run({})# Integration tests - with real APIs@pytest.mark.integrationdef test_with_real_api(): result = run({"query": "test"}) assert result["ok"]# Snapshot tests - for output consistencydef test_output_format(snapshot): result = run({"query": "hello"}) assert result == snapshot
This section is designed to be copied wholesale and given to an AI assistant. It contains everything needed to build a complete, valid PraisonAI recipe from scratch.
# test_recipe.pyimport pytestfrom recipe import run# Unit test - fast, no API callsdef test_input_validation(): """Test that missing required fields raise errors.""" with pytest.raises(ValueError): run({})def test_output_structure(): """Test output has required fields.""" result = run({"input": "test"}) assert "ok" in result assert "output" in result# Integration test - with real APIs@pytest.mark.integrationdef test_with_real_api(): """Test with actual API calls.""" result = run({"input": "real data"}) assert result["ok"] is True# Mark slow tests@pytest.mark.slowdef test_large_file_processing(): """Test with large files.""" pass# Run tests# pytest test_recipe.py # Unit tests only# pytest test_recipe.py -m integration # Integration tests# pytest test_recipe.py -m "not slow" # Skip slow tests
Use this prompt to instruct an AI to create a valid recipe:
Copy
You are creating a PraisonAI recipe. Follow these rules exactly:1. Create a directory with the recipe name (kebab-case)2. Create TEMPLATE.yaml with ALL required fields: - name, version, description, author, license - tags (at least one) - requires (env, packages, tools as needed) - inputs (with type, description, required for each) - outputs (with type, description for each) - cli (command and examples) - safety (dry_run_default, requires_consent, overwrites_files)3. Create recipe.py with: - def run(input_data: dict, config: dict = None) -> dict - Validate all required inputs - Return dict with 'ok', 'output', 'artifacts', 'warnings', 'error' - Handle errors gracefully4. Create README.md with: - Title and description - Quick start example - Inputs table - Outputs table - Requirements - Troubleshooting5. Create test_recipe.py with: - Unit tests for input validation - Integration tests marked with @pytest.mark.integration6. Use praisonaiagents for Agent, Task, PraisonAIAgents7. Use praisonai_tools.recipe_tools for LLMTool, VisionTool, etc.8. Always check dependencies before using tools9. Use semantic versioning for version field10. Include proper error handling and logging