Multi-step task with an LLM tool-use loop

0
Sign in

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."""
AnthropicPractical codingMediumLast asked Sep 2026

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.