Skip to main content
⚑
← Coursesβ€ΊAI Engineering with PythonModule 6 Β· Frontier AI Engineeringβ€ΊπŸ† Capstone: end-to-end multi-modal agentmission101 / 101
πŸ’¬ DiscussπŸ§ͺ Playground+250 XP
Task
πŸ“ **Task:** Implement `route_turn(turn: dict) -> str` that returns one of `'haiku'`, `'sonnet'`, `'opus'` based on these rules (in priority order): 1. If `turn['escalate']` is truthy β†’ `'opus'` 2. Else if `turn['tool_count']` β‰₯ 1 β†’ `'sonnet'` 3. Else if `len(turn['text'])` < 80 chars AND no images β†’ `'haiku'` 4. Else β†’ `'sonnet'` (default) Then implement `estimate_cost(model: str, input_tokens: int, output_tokens: int) -> float`. Use these per-1M-token prices: Haiku 1/5, Sonnet 3/15, Opus 5/25 (input/output USD). Finally, exercise the router with 4 sample turns + print results. Expected output (4 lines): ``` haiku sonnet opus 0.051 ``` πŸ“‹ Implement the function above. Tests run automatically. πŸ’‘ **Hint:** Re-read the theory if stuck.

Keep going

✏️ Write your code here
🐍
Loading Python...
First visit only β€” ~5-10s. Stays cached afterward.
πŸ“Š Result
Press Run to see result...
πŸ“£ Help someone learn PythonShare this lesson with a friend β€” the first 15 are free, no signup.Tweet

πŸ’¬ Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…