Example 6: Workflow execution with streaming
()
| 155 | |
| 156 | |
| 157 | def streaming_example(): |
| 158 | """Example 6: Workflow execution with streaming""" |
| 159 | client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) |
| 160 | |
| 161 | try: |
| 162 | result = client.execute_workflow( |
| 163 | "your-workflow-id", |
| 164 | input_data={"message": "Count to five"}, |
| 165 | stream=True, |
| 166 | selected_outputs=["agent1.content"], # Use blockName.attribute format |
| 167 | timeout=60.0 |
| 168 | ) |
| 169 | |
| 170 | if result.success: |
| 171 | print("✅ Workflow executed successfully!") |
| 172 | print(f"Output: {result.output}") |
| 173 | if result.metadata: |
| 174 | print(f"Duration: {result.metadata.get('duration')} ms") |
| 175 | else: |
| 176 | print(f"❌ Workflow failed: {result.error}") |
| 177 | |
| 178 | except SimStudioError as error: |
| 179 | print(f"SDK Error: {error} (Code: {error.code})") |
| 180 | except Exception as error: |
| 181 | print(f"Unexpected error: {error}") |
| 182 | |
| 183 | |
| 184 | def error_handling_example(): |
no test coverage detected