Multi-step task with an LLM tool-use loop
In a notebook with docs open, solve a multi-step problem by writing code that calls a language model as a building block: design the prompts and the loop that invokes tools and folds results back in. Starter API code is given; judgment about decomposition matters more than syntax.
class Tool:
def __init__(self, name, description, input_schema, fn): ...
def run_agent(client, model, system, user_message, tools, max_turns=8, max_tokens=1024):
"""Messages-API tool loop. Returns (final_text, messages)."""
def map_prompts(client, model, system, inputs, render, parse, workers=8, retries=1):
"""One validated call per input, in parallel."""
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
