You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Routing logic - this could be enhanced with more sophisticated rules
36
+
instructions="""You are a cost-optimization router. For simple tasks like basic questions,
37
+
definitions, or simple calculations, use the cheapest model. For moderate complexity tasks
38
+
like writing, analysis, or research, use the balanced model. For complex tasks requiring
39
+
deep reasoning, creativity, or specialized knowledge, use the premium model.""",
40
+
41
+
tools=[duckduckgo],
42
+
verbose=True
43
+
)
44
+
45
+
# Example tasks of varying complexity levels
46
+
47
+
# Simple task - should route to cheap model
48
+
print("="*60)
49
+
print("TESTING SIMPLE TASK (should use cheap model)")
50
+
print("="*60)
51
+
simple_result=router.start("What is the capital of France?")
52
+
print(f"Simple task result: {simple_result}")
53
+
54
+
# Moderate complexity task - should route to balanced model
55
+
print("\n"+"="*60)
56
+
print("TESTING MODERATE TASK (should use balanced model)")
57
+
print("="*60)
58
+
moderate_result=router.start("Write a brief analysis of renewable energy trends in 2024")
59
+
print(f"Moderate task result: {moderate_result}")
60
+
61
+
# Complex task - should route to premium model
62
+
print("\n"+"="*60)
63
+
print("TESTING COMPLEX TASK (should use premium model)")
64
+
print("="*60)
65
+
complex_result=router.start("Conduct a comprehensive strategic analysis of the impact of quantum computing on cybersecurity, including potential vulnerabilities and mitigation strategies")
66
+
print(f"Complex task result: {complex_result}")
67
+
68
+
# Research task with tool usage - should route appropriately
69
+
print("\n"+"="*60)
70
+
print("TESTING RESEARCH TASK WITH TOOLS")
71
+
print("="*60)
72
+
research_result=router.start("Research and analyze the latest developments in artificial intelligence regulation globally")
backstory="You are a research analyst who backs all claims with evidence and citations.",
117
+
instructions="Support all statements with references to research, studies, or credible data sources."
118
+
)
119
+
120
+
# Create tasks with specific guardrails
121
+
122
+
# Task with email format guardrail
123
+
email_task=Task(
124
+
name="email_communication",
125
+
description="Write a business proposal for a new software project, including contact information",
126
+
expected_output="Professional business proposal with contact email addresses",
127
+
agent=email_agent,
128
+
guardrail=email_format_guardrail,
129
+
max_retries=3
130
+
)
131
+
132
+
# Task with word count guardrail
133
+
content_task=Task(
134
+
name="detailed_analysis",
135
+
description="Write an analysis of cloud computing benefits for small businesses",
136
+
expected_output="Comprehensive analysis of cloud computing benefits (minimum 50 words)",
137
+
agent=content_agent,
138
+
guardrail=word_count_guardrail,
139
+
max_retries=3
140
+
)
141
+
142
+
# Task with professional tone guardrail
143
+
business_task=Task(
144
+
name="professional_advice",
145
+
description="Provide advice on handling difficult client relationships",
146
+
expected_output="Professional advice maintaining appropriate business tone",
147
+
agent=business_agent,
148
+
guardrail=professional_tone_guardrail,
149
+
max_retries=3
150
+
)
151
+
152
+
# Task with factual accuracy guardrail
153
+
research_task=Task(
154
+
name="research_report",
155
+
description="Analyze the impact of artificial intelligence on job markets",
156
+
expected_output="Research-backed analysis with citations and evidence",
157
+
agent=research_agent,
158
+
guardrail=factual_accuracy_guardrail,
159
+
max_retries=3
160
+
)
161
+
162
+
# LLM-based guardrail example
163
+
llm_guardrail_agent=Agent(
164
+
name="LLMGuardrailAgent",
165
+
role="Content Quality Validator",
166
+
goal="Validate content quality using LLM-based assessment",
167
+
backstory="You are a quality assurance specialist who uses AI to validate content quality.",
168
+
instructions="Create marketing content that is engaging, accurate, and compliant with advertising standards."
169
+
)
170
+
171
+
# Task with LLM-based guardrail
172
+
llm_guardrail_task=Task(
173
+
name="marketing_content",
174
+
description="Create a marketing email for a new fitness app targeting busy professionals",
175
+
expected_output="Engaging marketing email that is accurate and compliant",
176
+
agent=llm_guardrail_agent,
177
+
178
+
# LLM-based guardrail using natural language validation
179
+
guardrail="Validate that this marketing content is: 1) Factually accurate with no false claims, 2) Compliant with advertising standards (no misleading statements), 3) Engaging and professional in tone, 4) Includes a clear call-to-action. If any criteria are not met, explain what needs to be improved.",
0 commit comments