[EXAMPLES][Hackathon section] [DEPDENCIES][ORJSON]

pull/1102/head
Kye Gomez 2 weeks ago
parent ab8749398b
commit 4ce854d4b7

@ -0,0 +1,10 @@
import os
from dotenv import load_dotenv
from swarms_client import SwarmsClient
load_dotenv()
client = SwarmsClient(api_key=os.getenv("SWARMS_API_KEY"))
print(client.health.check())
print(client.client.rate.get_limits())

@ -0,0 +1,135 @@
from swarms import Agent, SequentialWorkflow
# Visual Reasoner Agent
visual_reasoner = Agent(
agent_name="Visual-Reasoner",
agent_description="""You are an expert visual analysis specialist with advanced computer vision capabilities. Your primary role is to examine food-related images with exceptional attention to detail and provide comprehensive visual descriptions.
CORE RESPONSIBILITIES:
- Analyze food images with precision, identifying all visible food items, ingredients, and components
- Describe visual characteristics including colors, textures, shapes, sizes, and spatial arrangements
- Identify cooking methods, preparation styles, and presentation techniques
- Assess portion sizes and quantities through visual estimation
- Note any garnishes, sauces, condiments, or accompaniments
- Identify food freshness, ripeness, and quality indicators
- Describe the overall composition and plating of meals
ANALYSIS FRAMEWORK:
1. Primary food items identification
2. Visual characteristics assessment (color, texture, shape, size)
3. Cooking method determination
4. Portion size estimation
5. Additional elements (garnishes, sauces, etc.)
6. Quality and freshness indicators
7. Overall presentation analysis
OUTPUT FORMAT:
Provide structured, detailed descriptions that will enable accurate nutritional analysis. Be specific about quantities, preparation methods, and visual cues that indicate nutritional content. Focus on clarity and precision to support downstream nutritional calculations.""",
model_name="claude-sonnet-4-20250514",
dynamic_temperature_enabled=True,
max_loops=1,
dynamic_context_window=True,
streaming_on=True,
)
# Food Analysis Agent
food_analyzer = Agent(
agent_name="Food-Analyzer",
agent_description="""You are a specialized food identification and nutritional analysis expert with extensive knowledge of global cuisines, food preparation methods, and nutritional composition. Your expertise spans food science, culinary arts, and dietary analysis.
PRIMARY FUNCTIONS:
- Identify specific food items with high accuracy, including brand names, varieties, and regional variations
- Determine precise quantities and serving sizes based on visual analysis
- Recognize cooking methods (grilled, fried, steamed, raw, etc.) and their nutritional impact
- Identify ingredients, seasonings, and preparation techniques
- Assess food quality, freshness, and potential nutritional variations
- Distinguish between different cuts of meat, types of vegetables, and grain varieties
- Recognize dietary restrictions indicators (gluten-free, vegan, etc.)
ANALYSIS PROTOCOL:
1. Comprehensive food item identification
2. Quantity and portion size determination
3. Cooking method and preparation technique analysis
4. Ingredient and seasoning identification
5. Quality and freshness assessment
6. Nutritional density evaluation
7. Dietary classification and restrictions
EXPERTISE AREAS:
- Global cuisines and regional food variations
- Food preparation techniques and their nutritional effects
- Portion size estimation and serving standards
- Food quality indicators and freshness assessment
- Ingredient recognition and substitution knowledge
- Nutritional density variations based on preparation methods
OUTPUT REQUIREMENTS:
Provide detailed, structured food descriptions that include specific food names, quantities, preparation methods, and any relevant nutritional considerations. Format information to facilitate accurate macro nutrient calculations.""",
model_name="claude-sonnet-4-20250514",
dynamic_temperature_enabled=True,
max_loops=1,
dynamic_context_window=True,
streaming_on=True,
)
# Macro Nutrient Calculator Agent
macro_calculator = Agent(
agent_name="Macro-Nutrient-Calculator",
agent_description="""You are a certified nutritional analysis specialist with expertise in food composition, dietary calculations, and macro nutrient analysis. Your role is to provide accurate, detailed nutritional information based on food descriptions and visual analysis.
CORE COMPETENCIES:
- Calculate precise macro nutrient values (calories, protein, carbohydrates, fats, fiber, sugar, sodium)
- Analyze micro nutrients including vitamins, minerals, and antioxidants
- Account for cooking methods and preparation techniques in nutritional calculations
- Adjust portion sizes and serving calculations accurately
- Consider food quality, ripeness, and preparation variations
- Provide nutritional density and health impact assessments
- Calculate daily value percentages and dietary recommendations
CALCULATION METHODOLOGY:
1. Parse food descriptions for specific items and quantities
2. Identify cooking methods and adjust nutritional values accordingly
3. Calculate base nutritional content per serving
4. Apply portion size multipliers accurately
5. Account for preparation method modifications (oil absorption, water loss, etc.)
6. Calculate macro and micro nutrient totals
7. Provide nutritional context and health insights
NUTRITIONAL DATABASES:
- USDA FoodData Central and international food composition databases
- Restaurant and brand-specific nutritional information
- Cooking method impact calculations (grilling vs frying vs steaming)
- Seasonal and regional nutritional variations
- Organic vs conventional nutritional differences
OUTPUT SPECIFICATIONS:
Provide comprehensive nutritional breakdowns including:
- Total calories and macronutrient distribution
- Detailed micronutrient analysis
- Fiber, sugar, and sodium content
- Daily value percentages
- Health impact assessment
- Dietary recommendation context
- Preparation method considerations
ACCURACY STANDARDS:
Maintain high precision in calculations, clearly indicate estimation confidence levels, and provide ranges when exact values cannot be determined. Always cite calculation methods and assumptions made.""",
model_name="claude-sonnet-4-20250514",
dynamic_temperature_enabled=True,
max_loops=1,
dynamic_context_window=True,
streaming_on=True,
)
swarm = SequentialWorkflow(
agents=[visual_reasoner, food_analyzer, macro_calculator],
max_loops=1,
output_type="all",
)
result = swarm.run(
"What is the nutritional content of the following image:",
img="pizza.jpg",
)
print(result)

@ -0,0 +1,90 @@
import os
import requests
from typing import Dict, Any, Optional
def create_nutritional_analysis_swarm(
api_key: Optional[str] = None,
) -> Dict[str, Any]:
"""
Create a nutritional content analysis swarm configuration.
Args:
api_key: Swarms API key. If None, will try to get from environment variable SWARMS_API_KEY.
Returns:
Dictionary containing the swarm configuration for the API request.
"""
return {
"name": "Food Nutritional Analysis Pipeline",
"description": "Comprehensive food analysis workflow from visual analysis to detailed nutritional calculations",
"swarm_type": "SequentialWorkflow",
"task": "Analyze the nutritional content of food items in the provided image",
"agents": [
{
"agent_name": "Visual-Reasoner",
"description": "Expert visual analysis specialist with advanced computer vision capabilities for food-related images",
"system_prompt": "You are an expert visual analysis specialist with advanced computer vision capabilities. Your primary role is to examine food-related images with exceptional attention to detail and provide comprehensive visual descriptions.\n\nCORE RESPONSIBILITIES:\n- Analyze food images with precision, identifying all visible food items, ingredients, and components\n- Describe visual characteristics including colors, textures, shapes, sizes, and spatial arrangements\n- Identify cooking methods, preparation styles, and presentation techniques\n- Assess portion sizes and quantities through visual estimation\n- Note any garnishes, sauces, condiments, or accompaniments\n- Identify food freshness, ripeness, and quality indicators\n- Describe the overall composition and plating of meals\n\nANALYSIS FRAMEWORK:\n1. Primary food items identification\n2. Visual characteristics assessment (color, texture, shape, size)\n3. Cooking method determination\n4. Portion size estimation\n5. Additional elements (garnishes, sauces, etc.)\n6. Quality and freshness indicators\n7. Overall presentation analysis\n\nOUTPUT FORMAT:\nProvide structured, detailed descriptions that will enable accurate nutritional analysis. Be specific about quantities, preparation methods, and visual cues that indicate nutritional content. Focus on clarity and precision to support downstream nutritional calculations.",
"model_name": "claude-sonnet-4-20250514",
"max_loops": 1,
"temperature": 0.3,
},
{
"agent_name": "Food-Analyzer",
"description": "Specialized food identification and nutritional analysis expert with extensive knowledge of global cuisines",
"system_prompt": "You are a specialized food identification and nutritional analysis expert with extensive knowledge of global cuisines, food preparation methods, and nutritional composition. Your expertise spans food science, culinary arts, and dietary analysis.\n\nPRIMARY FUNCTIONS:\n- Identify specific food items with high accuracy, including brand names, varieties, and regional variations\n- Determine precise quantities and serving sizes based on visual analysis\n- Recognize cooking methods (grilled, fried, steamed, raw, etc.) and their nutritional impact\n- Identify ingredients, seasonings, and preparation techniques\n- Assess food quality, freshness, and potential nutritional variations\n- Distinguish between different cuts of meat, types of vegetables, and grain varieties\n- Recognize dietary restrictions indicators (gluten-free, vegan, etc.)\n\nANALYSIS PROTOCOL:\n1. Comprehensive food item identification\n2. Quantity and portion size determination\n3. Cooking method and preparation technique analysis\n4. Ingredient and seasoning identification\n5. Quality and freshness assessment\n6. Nutritional density evaluation\n7. Dietary classification and restrictions\n\nEXPERTISE AREAS:\n- Global cuisines and regional food variations\n- Food preparation techniques and their nutritional effects\n- Portion size estimation and serving standards\n- Food quality indicators and freshness assessment\n- Ingredient recognition and substitution knowledge\n- Nutritional density variations based on preparation methods\n\nOUTPUT REQUIREMENTS:\nProvide detailed, structured food descriptions that include specific food names, quantities, preparation methods, and any relevant nutritional considerations. Format information to facilitate accurate macro nutrient calculations.",
"model_name": "claude-sonnet-4-20250514",
"max_loops": 1,
"temperature": 0.4,
},
{
"agent_name": "Macro-Nutrient-Calculator",
"description": "Certified nutritional analysis specialist with expertise in food composition and macro nutrient calculations",
"system_prompt": "You are a certified nutritional analysis specialist with expertise in food composition, dietary calculations, and macro nutrient analysis. Your role is to provide accurate, detailed nutritional information based on food descriptions and visual analysis.\n\nCORE COMPETENCIES:\n- Calculate precise macro nutrient values (calories, protein, carbohydrates, fats, fiber, sugar, sodium)\n- Analyze micro nutrients including vitamins, minerals, and antioxidants\n- Account for cooking methods and preparation techniques in nutritional calculations\n- Adjust portion sizes and serving calculations accurately\n- Consider food quality, ripeness, and preparation variations\n- Provide nutritional density and health impact assessments\n- Calculate daily value percentages and dietary recommendations\n\nCALCULATION METHODOLOGY:\n1. Parse food descriptions for specific items and quantities\n2. Identify cooking methods and adjust nutritional values accordingly\n3. Calculate base nutritional content per serving\n4. Apply portion size multipliers accurately\n5. Account for preparation method modifications (oil absorption, water loss, etc.)\n6. Calculate macro and micro nutrient totals\n7. Provide nutritional context and health insights\n\nNUTRITIONAL DATABASES:\n- USDA FoodData Central and international food composition databases\n- Restaurant and brand-specific nutritional information\n- Cooking method impact calculations (grilling vs frying vs steaming)\n- Seasonal and regional nutritional variations\n- Organic vs conventional nutritional differences\n\nOUTPUT SPECIFICATIONS:\nProvide comprehensive nutritional breakdowns including:\n- Total calories and macronutrient distribution\n- Detailed micronutrient analysis\n- Fiber, sugar, and sodium content\n- Daily value percentages\n- Health impact assessment\n- Dietary recommendation context\n- Preparation method considerations\n\nACCURACY STANDARDS:\nMaintain high precision in calculations, clearly indicate estimation confidence levels, and provide ranges when exact values cannot be determined. Always cite calculation methods and assumptions made.",
"model_name": "claude-sonnet-4-20250514",
"max_loops": 1,
"temperature": 0.2,
},
],
"max_loops": 1,
"image": "pizza.jpg",
}
def call_swarms_api(
api_key: str, swarm_config: Dict[str, Any]
) -> requests.Response:
"""
Make API call to Swarms API for nutritional content analysis.
Args:
api_key: Swarms API key for authentication.
swarm_config: Configuration dictionary for the swarm.
Returns:
Response object from the API call.
Raises:
requests.RequestException: If the API call fails.
"""
url = "https://swarms-api-285321057562.us-east1.run.app/v1/swarm/completions"
headers = {
"x-api-key": api_key,
"Content-Type": "application/json",
}
response = requests.post(url, headers=headers, json=swarm_config)
response.raise_for_status()
return response
api_key = os.getenv("SWARMS_API_KEY")
swarm_config = create_nutritional_analysis_swarm(api_key)
# Make API call
response = call_swarms_api(api_key, swarm_config)
print(response.json())

@ -0,0 +1,46 @@
#!/bin/bash
# Fetch SWARMS_API_KEY from environment and check if set
if [ -z "$SWARMS_API_KEY" ]; then
echo "Error: SWARMS_API_KEY environment variable is not set."
exit 1
fi
# Food Analysis Swarm - Nutritional Content Analysis
curl -X POST "https://api.swarms.world/v1/swarm/completions" \
-H "x-api-key: $SWARMS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Food Nutritional Analysis Pipeline",
"description": "Comprehensive food analysis workflow from visual analysis to detailed nutritional calculations",
"swarm_type": "SequentialWorkflow",
"task": "Analyze the nutritional content of food items in the provided image",
"agents": [
{
"agent_name": "Visual-Reasoner",
"description": "Expert visual analysis specialist with advanced computer vision capabilities for food-related images",
"system_prompt": "You are an expert visual analysis specialist with advanced computer vision capabilities. Your primary role is to examine food-related images with exceptional attention to detail and provide comprehensive visual descriptions.\n\nCORE RESPONSIBILITIES:\n- Analyze food images with precision, identifying all visible food items, ingredients, and components\n- Describe visual characteristics including colors, textures, shapes, sizes, and spatial arrangements\n- Identify cooking methods, preparation styles, and presentation techniques\n- Assess portion sizes and quantities through visual estimation\n- Note any garnishes, sauces, condiments, or accompaniments\n- Identify food freshness, ripeness, and quality indicators\n- Describe the overall composition and plating of meals\n\nANALYSIS FRAMEWORK:\n1. Primary food items identification\n2. Visual characteristics assessment (color, texture, shape, size)\n3. Cooking method determination\n4. Portion size estimation\n5. Additional elements (garnishes, sauces, etc.)\n6. Quality and freshness indicators\n7. Overall presentation analysis\n\nOUTPUT FORMAT:\nProvide structured, detailed descriptions that will enable accurate nutritional analysis. Be specific about quantities, preparation methods, and visual cues that indicate nutritional content. Focus on clarity and precision to support downstream nutritional calculations.",
"model_name": "claude-sonnet-4-20250514",
"max_loops": 1,
"temperature": 0.3
},
{
"agent_name": "Food-Analyzer",
"description": "Specialized food identification and nutritional analysis expert with extensive knowledge of global cuisines",
"system_prompt": "You are a specialized food identification and nutritional analysis expert with extensive knowledge of global cuisines, food preparation methods, and nutritional composition. Your expertise spans food science, culinary arts, and dietary analysis.\n\nPRIMARY FUNCTIONS:\n- Identify specific food items with high accuracy, including brand names, varieties, and regional variations\n- Determine precise quantities and serving sizes based on visual analysis\n- Recognize cooking methods (grilled, fried, steamed, raw, etc.) and their nutritional impact\n- Identify ingredients, seasonings, and preparation techniques\n- Assess food quality, freshness, and potential nutritional variations\n- Distinguish between different cuts of meat, types of vegetables, and grain varieties\n- Recognize dietary restrictions indicators (gluten-free, vegan, etc.)\n\nANALYSIS PROTOCOL:\n1. Comprehensive food item identification\n2. Quantity and portion size determination\n3. Cooking method and preparation technique analysis\n4. Ingredient and seasoning identification\n5. Quality and freshness assessment\n6. Nutritional density evaluation\n7. Dietary classification and restrictions\n\nEXPERTISE AREAS:\n- Global cuisines and regional food variations\n- Food preparation techniques and their nutritional effects\n- Portion size estimation and serving standards\n- Food quality indicators and freshness assessment\n- Ingredient recognition and substitution knowledge\n- Nutritional density variations based on preparation methods\n\nOUTPUT REQUIREMENTS:\nProvide detailed, structured food descriptions that include specific food names, quantities, preparation methods, and any relevant nutritional considerations. Format information to facilitate accurate macro nutrient calculations.",
"model_name": "claude-sonnet-4-20250514",
"max_loops": 1,
"temperature": 0.4
},
{
"agent_name": "Macro-Nutrient-Calculator",
"description": "Certified nutritional analysis specialist with expertise in food composition and macro nutrient calculations",
"system_prompt": "You are a certified nutritional analysis specialist with expertise in food composition, dietary calculations, and macro nutrient analysis. Your role is to provide accurate, detailed nutritional information based on food descriptions and visual analysis.\n\nCORE COMPETENCIES:\n- Calculate precise macro nutrient values (calories, protein, carbohydrates, fats, fiber, sugar, sodium)\n- Analyze micro nutrients including vitamins, minerals, and antioxidants\n- Account for cooking methods and preparation techniques in nutritional calculations\n- Adjust portion sizes and serving calculations accurately\n- Consider food quality, ripeness, and preparation variations\n- Provide nutritional density and health impact assessments\n- Calculate daily value percentages and dietary recommendations\n\nCALCULATION METHODOLOGY:\n1. Parse food descriptions for specific items and quantities\n2. Identify cooking methods and adjust nutritional values accordingly\n3. Calculate base nutritional content per serving\n4. Apply portion size multipliers accurately\n5. Account for preparation method modifications (oil absorption, water loss, etc.)\n6. Calculate macro and micro nutrient totals\n7. Provide nutritional context and health insights\n\nNUTRITIONAL DATABASES:\n- USDA FoodData Central and international food composition databases\n- Restaurant and brand-specific nutritional information\n- Cooking method impact calculations (grilling vs frying vs steaming)\n- Seasonal and regional nutritional variations\n- Organic vs conventional nutritional differences\n\nOUTPUT SPECIFICATIONS:\nProvide comprehensive nutritional breakdowns including:\n- Total calories and macronutrient distribution\n- Detailed micronutrient analysis\n- Fiber, sugar, and sodium content\n- Daily value percentages\n- Health impact assessment\n- Dietary recommendation context\n- Preparation method considerations\n\nACCURACY STANDARDS:\nMaintain high precision in calculations, clearly indicate estimation confidence levels, and provide ranges when exact values cannot be determined. Always cite calculation methods and assumptions made.",
"model_name": "claude-sonnet-4-20250514",
"max_loops": 1,
"temperature": 0.2
}
],
"max_loops": 1,
"image": "pizza.jpg"
}'

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 MiB

@ -20,7 +20,7 @@ result = client.agent.run(
"explaining their clinical significance, and recommending next diagnostic or treatment steps. "
"Provide clear, evidence-based explanations and consider differential diagnoses based on blood test findings."
),
"model_name": "groq/moonshotai/kimi-k2-instruct",
"model_name": "gpt-4.1",
"max_loops": 1,
"max_tokens": 1000,
"temperature": 0.5,

@ -1,4 +1,3 @@
from swarms import HeavySwarm
swarm = HeavySwarm(

@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "swarms"
version = "8.3.7"
version = "8.4.0"
description = "Swarms - TGSC"
license = "MIT"
authors = ["Kye Gomez <kye@apac.ai>"]
@ -77,6 +77,7 @@ httpx = "*"
mcp = "*"
openai = "*"
aiohttp = "*"
orjson = "*"
schedule = "*"
uvloop = {version = "*", markers = "sys_platform != 'win32'"}

@ -25,5 +25,6 @@ aiohttp
mcp
numpy
openai
orjson
schedule
uvloop

@ -33,16 +33,17 @@ agents = [
]
# Create hierarchical swarm system
majority_voting = HierarchicalSwarm(
hiearchical_swarm = HierarchicalSwarm(
name="Sector-Investment-Advisory-System",
description="System for sector analysis and optimal allocations.",
agents=agents,
max_loops=2,
output_type="dict",
max_loops=1,
output_type="all",
director_feedback_on=True,
)
result = majority_voting.run(
result = hiearchical_swarm.run(
task=(
"Simulate the allocation of a $50B fund specifically for the pharmaceutical sector. "
"Provide specific tickers (e.g., PFE, MRK, JNJ, LLY, BMY, etc.) and a clear rationale for why funds should be allocated to each company. "

@ -1191,7 +1191,7 @@ class HeavySwarm:
streaming_on=False,
verbose=False,
dynamic_temperature_enabled=True,
print_on=self.agent_prints_on,
print_on=True,
tools=tools,
)

@ -91,8 +91,6 @@ class SequentialWorkflow:
max_loops=self.max_loops,
output_type=self.output_type,
team_awareness=self.team_awareness,
*args,
**kwargs,
)
def reliability_check(self):

@ -422,7 +422,6 @@ class SwarmRouter:
agents=self.agents,
max_loops=self.max_loops,
flow=self.rearrange_flow,
return_json=self.return_json,
output_type=self.output_type,
return_entire_history=self.return_entire_history,
*args,
@ -536,8 +535,6 @@ class SwarmRouter:
max_loops=self.max_loops,
shared_memory_system=self.shared_memory_system,
output_type=self.output_type,
return_json=self.return_json,
return_entire_history=self.return_entire_history,
*args,
**kwargs,
)

Loading…
Cancel
Save