Skip to content

Agent Turns

Use turn when a prompt can call tools and the runtime should continue the conversation until the model returns a final answer.

turn prepares the prompt, calls the model, dispatches requested tool calls, formats tool results, and repeats until completion or a loop limit is reached.

def get_weather(location: str) -> str:
return f"Sunny in {location}"
result = prompty.turn(
"agent.prompty",
inputs={"question": "Weather in Seattle?"},
tools={"get_weather": get_weather},
max_iterations=10,
)
ParameterDescription
promptPath to a .prompty file or loaded Prompty object
inputsTemplate input dictionary
toolsTool implementations keyed by tool name
max_iterationsLoop limit; implementations should fail rather than loop forever
rawReturn raw provider responses when supported

Tools are matched by name. Tool arguments are decoded from provider tool-call payloads, merged with any Prompty tool bindings, and passed to the registered function.

Tool bindings are not sent to the model as model-controllable parameters. They are injected by the runtime when the tool is executed.

For the registry APIs, kind handlers, and dispatch precedence, see Tool Calling.

ConditionExpected behavior
Bad JSON tool argumentsSurface the error to the model so it can retry
Tool throwsReturn an error-shaped tool result to the model
Missing tool implementationReturn an error-shaped tool result or raise according to runtime policy
Loop limit exceededRaise an error
Cancellation requestedStop the loop and return or raise according to the runtime cancellation API

See Agentic Concepts for the behavioral model behind agent loops, cancellation, compaction, guardrails, and steering.