workflow_output_modes.py
1 """ 2 Workflow Output Modes Example 3 4 Demonstrates how to use different output modes with Workflow. 5 Workflows use the same output presets as Agent for consistency (DRY approach). 6 7 Available presets: 8 - silent: No output (default, fastest) 9 - status: Tool calls + final output inline 10 - trace: Timestamped execution trace 11 - verbose: Full Rich panels 12 - debug: Trace + metrics 13 - json: JSONL output for piping 14 """ 15 16 from praisonaiagents import Agent, Workflow 17 18 19 def main(): 20 # Create a simple agent 21 researcher = Agent( 22 name="Researcher", 23 role="Research Analyst", 24 goal="Research and provide information", 25 instructions="You are a research analyst. Provide concise, factual information." 26 ) 27 28 # Example 1: Status output (recommended for CLI) 29 print("=" * 50) 30 print("Example 1: Status Output (output='status')") 31 print("=" * 50) 32 33 workflow_status = AgentFlow( 34 name="Status Example", 35 steps=[researcher], 36 output="status" # Shows: ▸ tool → result ✓ 37 ) 38 # result = workflow_status.start("What is Python?") 39 print("Workflow created with output='status'") 40 print(f" actions_trace: {getattr(workflow_status._output_config, 'actions_trace', False)}") 41 print() 42 43 # Example 2: Trace output (with timestamps) 44 print("=" * 50) 45 print("Example 2: Trace Output (output='trace')") 46 print("=" * 50) 47 48 workflow_trace = AgentFlow( 49 name="Trace Example", 50 steps=[researcher], 51 output="trace" # Shows: [HH:MM:SS] ▸ tool → result [0.2s] ✓ 52 ) 53 print("Workflow created with output='trace'") 54 print(f" status_trace: {getattr(workflow_trace._output_config, 'status_trace', False)}") 55 print() 56 57 # Example 3: Verbose output (Rich panels) 58 print("=" * 50) 59 print("Example 3: Verbose Output (output='verbose')") 60 print("=" * 50) 61 62 workflow_verbose = AgentFlow( 63 name="Verbose Example", 64 steps=[researcher], 65 output="verbose" # Full interactive display 66 ) 67 print("Workflow created with output='verbose'") 68 print(f" verbose: {getattr(workflow_verbose._output_config, 'verbose', False)}") 69 print() 70 71 # Example 4: Silent output (default, fastest) 72 print("=" * 50) 73 print("Example 4: Silent Output (output='silent' or default)") 74 print("=" * 50) 75 76 workflow_silent = AgentFlow( 77 name="Silent Example", 78 steps=[researcher], 79 output="silent" # No output - zero overhead 80 ) 81 print("Workflow created with output='silent'") 82 print(f" verbose: {getattr(workflow_silent._output_config, 'verbose', False)}") 83 print(f" actions_trace: {getattr(workflow_silent._output_config, 'actions_trace', False)}") 84 print() 85 86 # Example 5: JSON output (for piping) 87 print("=" * 50) 88 print("Example 5: JSON Output (output='json')") 89 print("=" * 50) 90 91 workflow_json = AgentFlow( 92 name="JSON Example", 93 steps=[researcher], 94 output="json" # JSONL output for scripting 95 ) 96 print("Workflow created with output='json'") 97 print(f" json_output: {getattr(workflow_json._output_config, 'json_output', False)}") 98 print() 99 100 print("=" * 50) 101 print("All examples completed successfully!") 102 print("=" * 50) 103 104 105 if __name__ == "__main__": 106 main()