from afk.agents import Agent, FailSafeConfig
from afk.core import Runner
# Start cheap, escalate if quality is insufficient
simple_agent = Agent(
name="classifier",
model="gpt-5.2-nano", # Start with cheapest
instructions="""
Classify the support ticket. Output exactly one label:
billing, technical, account, other.
""",
fail_safe=FailSafeConfig(
fallback_model_chain=["gpt-5.2-mini", "gpt-5.2"],
max_total_cost_usd=0.05,
),
)
# Complex tasks get the big model with fallbacks
analysis_agent = Agent(
name="analyst",
model="gpt-5.2", # Start with most capable
instructions="""
Provide detailed technical analysis with code examples.
Be thorough and precise.
""",
fail_safe=FailSafeConfig(
fallback_model_chain=["gpt-5.2-mini"],
llm_failure_policy="retry_then_degrade",
max_total_cost_usd=2.00,
),
)
runner = Runner()
# Simple task → cheap model handles it
r1 = runner.run_sync(simple_agent, user_message="I can't log in")
print(f"Classification: {r1.final_text} (${r1.usage.estimated_cost_usd:.4f})")
# Complex task → powerful model with safety net
r2 = runner.run_sync(analysis_agent, user_message="Analyze Python's asyncio event loop")
print(f"Analysis: {r2.final_text[:100]}... (${r2.usage.estimated_cost_usd:.4f})")