← Questions

Multi-step task with an LLM tool-use loop

0
AnthropicCodingLast asked Sep 2026

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."""
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding