|
| 1 | +""" |
| 2 | +Example of running a Flo AI workflow with snake_case agent names |
| 3 | +Generated from Flo AI Studio |
| 4 | +""" |
| 5 | + |
| 6 | +import asyncio |
| 7 | +from flo_ai.arium import AriumBuilder |
| 8 | +from flo_ai.tool.base_tool import Tool |
| 9 | + |
| 10 | +# Set your OpenAI API key |
| 11 | +# os.environ["OPENAI_API_KEY"] = "your-api-key-here" |
| 12 | + |
| 13 | + |
| 14 | +# Create a simple web search tool |
| 15 | +async def web_search_function(query: str) -> str: |
| 16 | + """Simple web search simulation - replace with actual search API""" |
| 17 | + return f"Web search results for '{query}': Found relevant articles about the topic including latest developments, applications, and ethical considerations. [This is a mock search - integrate with real search API like Google, Bing, or DuckDuckGo]" |
| 18 | + |
| 19 | + |
| 20 | +# Create the tool instance |
| 21 | +web_search_tool = Tool( |
| 22 | + name='web_search', |
| 23 | + description='Search the web for information on a given topic', |
| 24 | + function=web_search_function, |
| 25 | + parameters={ |
| 26 | + 'query': { |
| 27 | + 'type': 'string', |
| 28 | + 'description': 'The search query to look up information about', |
| 29 | + } |
| 30 | + }, |
| 31 | +) |
| 32 | + |
| 33 | +# YAML workflow definition (exported from Flo AI Studio) |
| 34 | +workflow_yaml = """ |
| 35 | +metadata: |
| 36 | + name: New Workflow |
| 37 | + version: 1.0.0 |
| 38 | + description: Generated with Flo AI Studio |
| 39 | + tags: |
| 40 | + - flo-ai |
| 41 | + - studio-generated |
| 42 | +arium: |
| 43 | + agents: |
| 44 | + - name: content_analyzer |
| 45 | + role: Content Analyst |
| 46 | + job: Analyze content and extract key insights, themes, and important information. |
| 47 | + model: |
| 48 | + provider: openai |
| 49 | + name: gpt-4o-mini |
| 50 | + settings: |
| 51 | + temperature: 0.7 |
| 52 | + max_retries: 3 |
| 53 | + reasoning_pattern: DIRECT |
| 54 | + - name: researcher |
| 55 | + role: Research Specialist |
| 56 | + job: Research topics and gather comprehensive information using available tools. |
| 57 | + model: |
| 58 | + provider: openai |
| 59 | + name: gpt-4o |
| 60 | + tools: |
| 61 | + - web_search |
| 62 | + - name: summarizer |
| 63 | + role: Summary Generator |
| 64 | + job: Create concise, actionable summaries from analysis and content. |
| 65 | + model: |
| 66 | + provider: openai |
| 67 | + name: gpt-4o-mini |
| 68 | + routers: |
| 69 | + - name: smart_router |
| 70 | + type: smart |
| 71 | + routing_options: |
| 72 | + researcher: If there is not enough information & deep research needs to be done |
| 73 | + summarizer: If we have enough information and its time to summarize |
| 74 | + model: |
| 75 | + provider: openai |
| 76 | + name: gpt-4o-mini |
| 77 | + settings: |
| 78 | + temperature: 0.3 |
| 79 | + fallback_strategy: first |
| 80 | + workflow: |
| 81 | + start: content_analyzer |
| 82 | + edges: |
| 83 | + - from: content_analyzer |
| 84 | + to: [researcher, summarizer] |
| 85 | + router: smart_router |
| 86 | + - from: researcher |
| 87 | + to: [summarizer] |
| 88 | + end: |
| 89 | + - summarizer |
| 90 | +""" |
| 91 | + |
| 92 | + |
| 93 | +async def main(): |
| 94 | + """Run the workflow""" |
| 95 | + print('🚀 Starting Flo AI Workflow...') |
| 96 | + print('📋 Workflow: Content Analysis with Smart Routing') |
| 97 | + print('-' * 50) |
| 98 | + |
| 99 | + try: |
| 100 | + # Create tools dictionary (required format for AriumBuilder) |
| 101 | + tools = {'web_search': web_search_tool} |
| 102 | + |
| 103 | + # Create Arium builder from YAML |
| 104 | + builder = AriumBuilder.from_yaml(yaml_str=workflow_yaml, tools=tools) |
| 105 | + |
| 106 | + # Example input for the workflow |
| 107 | + user_input = [ |
| 108 | + """I need to understand the current trends in artificial intelligence and machine learning. |
| 109 | + Specifically, I'm interested in: |
| 110 | + 1. Latest developments in large language models |
| 111 | + 2. Applications in healthcare and finance |
| 112 | + 3. Ethical considerations and regulations |
| 113 | + |
| 114 | + Please provide a comprehensive analysis and summary.""" |
| 115 | + ] |
| 116 | + |
| 117 | + print('📝 Input:') |
| 118 | + print(user_input[0]) |
| 119 | + print('\n' + '=' * 50) |
| 120 | + print('🔄 Processing workflow...') |
| 121 | + print('=' * 50 + '\n') |
| 122 | + |
| 123 | + # Build and run the workflow |
| 124 | + result = await builder.build_and_run(user_input) |
| 125 | + |
| 126 | + print('✅ Workflow Result:') |
| 127 | + print('-' * 30) |
| 128 | + if isinstance(result, list): |
| 129 | + for i, message in enumerate(result): |
| 130 | + print(f'{i+1}. {message}') |
| 131 | + else: |
| 132 | + print(result) |
| 133 | + |
| 134 | + except Exception as e: |
| 135 | + print(f'❌ Error running workflow: {str(e)}') |
| 136 | + print('\n💡 Make sure you have:') |
| 137 | + print('1. Set your OPENAI_API_KEY environment variable') |
| 138 | + print('2. Installed flo-ai: pip install flo-ai') |
| 139 | + print('3. All required dependencies') |
| 140 | + |
| 141 | + |
| 142 | +if __name__ == '__main__': |
| 143 | + asyncio.run(main()) |
0 commit comments