Book 4: Workflows and Playbooks
Strategic Guides for AI Agents
Part of the UnifyWeaver Education Series
Welcome to the comprehensive guide for designing workflows and playbooks that enable AI agents to work effectively with UnifyWeaver!
Prerequisites: Complete Books 1-3 for core concepts. This book helps you plan before exploring more targets.
What This Book Covers
This book teaches you how to create strategic guides for AI agents that go beyond simple scripts:
- Workflows: High-level operating principles and strategic frameworks
- Playbooks: Specific, actionable plans for concrete tasks
- Example Libraries: Reusable patterns and code snippets
- Tool Integration: How to leverage UnifyWeaver’s capabilities
- Economic Decision-Making: Cost, speed, and quality trade-offs
The Paradigm Shift
From Scripts to Strategies
Traditional programming: Write scripts that execute fixed sequences of commands.
Workflow-based AI: Provide agents with:
- Multiple strategies to achieve goals
- Economic data to make intelligent trade-offs
- Tool libraries for execution
- Heuristic guidance for decision-making
The AI agent becomes an economic strategist, not just a script executor.
Chapters
From scripts to strategies. Learn the distinction between workflows (strategic guides) and playbooks (specific execution plans), and how AI agents use them.
The standardized format for creating playbooks. Covers frontmatter, callout types ([!output], [!example-record]), and best practices.
Design multi-stage pipelines that chain compilation targets. AWK → Python → Go and other cross-language workflows.
How AI agents choose strategies based on cost, speed, and quality trade-offs. Heuristics and decision frameworks.
Create, organize, and use reusable code patterns. Naming conventions, cross-references, and maintenance.
Additional Resources
Example Libraries
examples_library/
Reusable code patterns and examples:
Sample Playbooks
playbooks/
Complete playbook examples:
Quick Start
5-Minute Introduction
- Read Chapter 1: Introduction (5 min)
- Skim Chapter 2: Playbook Format (2 min)
- Look at Factorial Playbook (3 min)
Complete Guide
Work through all chapters (1-2 hours).
Key Concepts
Workflows
Definition: The overarching strategic guide for an AI agent.
Contains:
- High-level goals
- General operating principles
- Types of tools available
- Economic decision criteria
- Heuristic guidance
Characteristics:
- Highly reusable
- Defines agent behavior broadly
- Context for many tasks
Example: “When compiling Prolog to Bash, analyze the recursion pattern first, then choose between linear recursion, transitive closure, or general recursive compilation based on pattern detection results.”
Playbooks
Definition: Specific, detailed project plans for accomplishing particular tasks.
Contains:
- Concrete steps
- Specific tools to use
- Conditional logic
- Expected outputs
- Verification steps
Characteristics:
- Task-specific
- Detailed and actionable
- Operates within workflow framework
Example: “To compile factorial: 1) Create /tmp/factorial.pl with this code, 2) Run compiler_driver with factorial/2, 3) Verify output script exists, 4) Test with inputs 0, 5, 10.”
Example Libraries
Purpose: Provide concrete instances of patterns, tools, and solutions.
Structure:
- Organized by topic (recursion, compilation, testing)
- Tagged with IDs and metadata
- Cross-referenced between libraries
- Extractable by tools
Usage: Playbooks reference examples rather than embedding large code blocks.
Design Principles
1. Separation of Concerns
Workflows: Strategic thinking and decision-making
Playbooks: Concrete execution plans
Examples: Reusable implementation patterns
Don’t mix these! Keep strategies separate from tactics.
2. Economic Awareness
Every strategy should have:
- Cost: Resource usage (time, memory, complexity)
- Speed: Execution time
- Quality: Correctness, robustness, maintainability
AI agents use this data to make trade-offs.
3. Heuristic Guidance
Provide rules of thumb:
- “For lists <100 items, use simple iteration”
- “For recursive depth >10, consider memoization”
- “For production deployments, prefer compiled binaries”
4. Composability
Design playbooks and examples to work together:
- Reference examples from libraries
- Chain playbooks for complex workflows
- Build on existing patterns
5. Verifiability
Every playbook should include:
- Expected outputs
- Verification steps
- Success criteria
- Error handling
Callout Reference
[!output] - Expected Output
Specifies what the agent should generate.
> [!output]
> language: prolog
> purpose: Define factorial predicate
> format: executable
>
> ```prolog
> factorial(0, 1).
> factorial(N, F) :- N > 0, N1 is N-1, factorial(N1, F1), F is N * F1.
> ```
Guidelines:
- Keep <10% of playbook content
- Use as template/placeholder
- Include metadata (language, purpose, format)
[!example-record] - Example Reference
Tags reusable examples in libraries.
> [!example-record]
> id: 20251108-factorial-compile
> name: unifyweaver.compilation.factorial
> pattern: linear_recursion
> child_examples: [unifyweaver.testing.factorial_runner]
Metadata:
id: Unique identifier (timestamp-based)
name: Namespaced example name
pattern: Classification tag
child_examples: Related examples
parent_example: Parent in hierarchy
Common Patterns
Pattern 1: Compile-and-Test Workflow
- Define Prolog predicate
- Save to file
- Compile with compiler_driver
- Generate test runner
- Execute tests
- Verify results
Example: Factorial Complete Workflow
Pattern 2: Data Source Integration
- Declare data source (
:- source(...))
- Define domain predicate
- Compile with dynamic source
- Generate target scripts
- Verify pipeline
Example: Data Source Playbooks
Pattern 3: Multi-Target Generation
- Define predicate once
- Compile to Bash
- Compile to C#
- Test both targets
- Compare results
Pattern 4: Recursive Pattern Optimization
- Analyze recursion type
- Choose optimizer (linear, transitive, general)
- Compile with appropriate strategy
- Verify optimization applied
Example: Ancestor Compilation
UnifyWeaver Compiler Driver
What: Main compilation orchestrator
When: Always use for Prolog→Bash/C# compilation
How: compile(Predicate/Arity, Options, Scripts)
Options:
output_dir(Dir): Where to write scripts
target(bash|csharp): Target language
optimize(Level): Optimization level
Test Runner Inference
What: Automatically generate test suites
When: After compilation, for verification
How: generate_test_runner_inferred(Output, Options)
Options:
mode(explicit|inferred): Test generation mode
output_dir(Dir): Test script location
What: Perl script to extract examples from libraries
When: Building playbooks dynamically
How: extract_example.pl --id <example-id>
Creating New Content
Adding a New Playbook
- Start with playbook format template
- Define goal clearly
- Provide strategies (if multiple approaches exist)
- Reference relevant examples from libraries
- Include expected outputs
- Add verification steps
Adding to Example Libraries
- Choose appropriate library file
- Use
[!example-record] callout
- Assign unique ID (timestamp-based)
- Use namespaced naming (e.g.,
unifyweaver.pattern.name)
- Tag with pattern classification
- Cross-reference related examples
Expanding Workflows
- Identify strategic decision points
- Document alternative approaches
- Provide economic data (cost/speed/quality)
- Add heuristics for selection
- Reference playbooks for each strategy
Current Status
Complete ✅
- Chapter 1: Thinking in Workflows
- Playbook format specification
- Core example libraries:
- Compilation examples (factorial, ancestor)
- Recursion examples (ancestor)
- Data source principles
In Progress 🚧
- Additional playbook examples
- More compilation patterns
- Multi-target workflows
- Partitioning playbooks
Planned 📝
- Chapter 2: Designing Workflows
- Chapter 3: Economic Decision-Making
- Chapter 4: Tool Orchestration
- Chapter 5: Testing and Verification
- Complete factorial playbook (standalone)
- CSV data source playbook (detailed)
- Parallel execution playbooks
- Firewall policy playbooks
Best Practices
For Workflow Designers
- Think economically: Always include cost/speed/quality data
- Provide options: Multiple strategies > single approach
- Use heuristics: Guide decisions with rules of thumb
- Stay abstract: Workflows define principles, not details
For Playbook Creators
- Be specific: Concrete steps, specific tools
- Reference examples: Don’t embed large code blocks
- Include verification: How to know it worked
- Handle errors: What to do when things fail
- Keep outputs minimal: <10% of content in
[!output] blocks
For Example Library Maintainers
- Tag consistently: Use pattern classifications
- Cross-reference: Link related examples
- Keep examples small: Focus on one pattern
- Provide context: Explain what and why
- Update metadata: IDs, names, relationships
Getting Help
- Concepts: Read Chapter 1
- Format: See playbook_format.md
- Examples: Browse examples_library/
- Issues: File on GitHub
- Questions: Community discussions
Contributing
Want to contribute?
- New playbooks: Follow format spec, reference examples
- Example patterns: Add to appropriate library file
- Documentation: Improve existing content
- Workflows: Submit strategic guides
All contributions welcome!
This is part of the UnifyWeaver Educational Series:
- Book 1: Foundations - Architecture, Prolog basics
- Book 2: Bash Target - Stream compilation
- Book 3: C# Target - Fixed-point approaches
- Book 4: Workflows (This Book)
Continue to Book 5 or 6 to explore more targets:
Version: 0.2.0
Last Updated: 2025-12-07
Focus: Strategic AI agent guidance