Agent recipe · 03

Multi-model routing agent

Use one model to classify the task and another to execute it. This pattern makes the hand-off explicit without hiding model choice in application code.

Intermediate20 minutesEnglishVerified 2026-09-25
This example uses live catalog IDs glm-4.5 for planning and deepseek-v4-flash for execution. Confirm both IDs on Models before running.

1. The 60-second version

from openai import OpenAI
import os, json
client = OpenAI(base_url="https://aiwave.live/v1", api_key=os.environ["AIWAVE_API_KEY"])
task = "Write a two-line status update about a delayed deployment."
plan = client.chat.completions.create(model="glm-4.5", messages=[{"role":"system","content":"Return JSON with keys action and constraints."},{"role":"user","content":task}], response_format={"type":"json_object"})
plan_json = json.loads(plan.choices[0].message.content)
execution = client.chat.completions.create(model="deepseek-v4-flash", messages=[{"role":"system","content":"Follow the planner JSON and answer only the user's task."},{"role":"user","content":task},{"role":"assistant","content":json.dumps(plan_json)}])
print(execution.choices[0].message.content)

Run with python router.py. If your selected model does not accept JSON mode, remove response_format and validate the returned text before parsing.

2. Per-run cost model

AssumptionEstimate
Planner: 800 input + 150 output; executor: 1,200 input + 300 outputabout $0.0027 per run using the listed 2026-08-27 rates
SourcesPricing: glm-4.5 ($0.6975/$2.17) and deepseek-v4-flash ($0.638/$1.914), checked 2026-09-25

3. Extend it safely

Next steps