How JAZ works
How it works
What happens inside invoke
You call it with a task and the Python you have in hand. The model writes the body of that call as Python code, JAZ runs it in a sandboxed interpreter, and the result comes back as a real Python value of the type you asked for. There is no graph to wire, no tool schema to write and nothing to parse: the model's reply is the program. Scroll to watch one call run, as described in the paper.
You writedef web_search(query: str) -> list[str]: """Search the web; return result summaries.""" return parse_hits(SESSION.get(search_url(query))) plots = jaz.def invoke(LLM sees task="Make plots comparing penguin species.", Make plots comparing penguin species. df=pd.read_csv("penguins.csv"), species island ... body_mass_g sex 0 Adelie Torgersen ... 3750.0 MALE 1 Adelie Torgersen ... 3800.0 FEMALE [344 rows x 7 columns] web_search=web_search, `web_search(query: str) -> list[str]`: Search the web; return result summaries.): LLM writesprint(web_search(task))LLM sees['Palmer penguins in seaborn: Compare species ...', ...] LLM writesplots = [] for col in ["island", "body_mass_g", ...]: plot = invoke( subtask=f"Plot {col} by species", df=df, instructions=__history__[0].repl_output, ) plots.append(plot) return plotsplotsMinimalist interface
Every input — a prompt, your data, a tool — is the same thing: a keyword argument with a name of your choosing.
Maximal expressivity
All inputs are available as variables.
Recursive subagents are available by default.
The REPL history itself is available as a variable in the REPL.
Return any Python object created in the REPL.
Make it yours
Small core. Your kind of agent.
The result type, the budget, and the tools the agent can use are all explicit in your code. Tick a feature: the lines it costs appear, and the output under the program changes with them. Copy it and run it — no new agent class required. New to agents that write code? Start here.
imports and configuration, and search_wikipedia's helpersincluded when you copy
from jaz import configure, invokefrom jaz.llm import LiteLLMimport pandas as pdimport requestsfrom urllib.parse import urlencodefrom dataclasses import dataclassfrom jaz.hooks import ReturnTypefrom jaz.hooks import BudgetPoolfrom jaz.hooks import IterationLimit, RecursionLimitfrom jaz.hooks import FileLogger # reads OPENAI_API_KEYconfigure(llm=LiteLLM(model="openai/gpt-5.4"))# Wikipedia refuses requests' default User-Agent (HTTP 403).
SESSION = requests.Session()
SESSION.headers["User-Agent"] = (
"jaz-example (https://jaz-lang.ai)")
def search_url(query: str) -> str:
"""The search, with each hit's title and lead."""
params = urlencode({
"action": "query", "format": "json",
"formatversion": 2, "generator": "search",
"gsrsearch": query, "prop": "extracts",
"exintro": 1, "exsentences": 3,
"exlimit": "max", "explaintext": 1,
})
return f"https://en.wikipedia.org/w/api.php?{params}"
def parse_hits(response: requests.Response) -> list[str]:
"""One "Title: lead" string per hit, in rank order."""
response.raise_for_status()
data = response.json()
if "error" in data:
raise RuntimeError(data["error"]["info"])
pages = data.get("query", {}).get("pages", [])
pages.sort(key=lambda p: p["index"])
return [f"{p['title']}: {p.get('extract', '')}"
for p in pages]# seaborn's Palmer Penguins: 344 birds, 3 speciesPENGUINS = ( "https://raw.githubusercontent.com" "/mwaskom/seaborn-data/master/penguins.csv") # a tool: any function; the agent reads its docstringdef search_wikipedia(query: str) -> list[str]: """Search Wikipedia; return article summaries.""" return parse_hits(SESSION.get(search_url(query))) # the shape of the answer: a class, checked on return@dataclassclass SpeciesReport: best_features: list[str] summary: str # hooks see every event; the caps can stop the runwith ( # $0.50 or 100 LLM calls, across nested agents BudgetPool(cost_budget=0.50, calls_budget=100), # 10 turns per agent, at most 2 levels of agents IterationLimit(max_iterations=10), RecursionLimit(max_depth=2), # every event, from every nested agent, to a file FileLogger("agent.log"),): # the agent writes and runs Python until it returns report = invoke( ReturnType(SpeciesReport), # or it retries task="How to tell apart different penguin species?", df=pd.read_csv(PENGUINS), # a live DataFrame search_wikipedia=search_wikipedia, # agent may call )print(report)Outputwhat print(report) shows — an example; yours will differ
Look at the head. Adélie penguins have a white ring around each eye, chinstraps a thin black line under the chin, and gentoos a white patch above each eye and an orange bill. Gentoos are also the largest of the three.In this data, size separates Gentoo first: flippers average 217 mm and body mass 5076 g, against 190–196 mm and about 3700 g for Adelie and Chinstrap. Bill length then splits those two: 48.8 mm for Chinstrap, 38.8 mm for Adelie. Island is a shortcut, too: every Gentoo is on Biscoe and every Chinstrap on Dream.Wikipedia: the chinstrap is named for the narrow black band under its head, which makes it look as if it is wearing a black helmet; the gentoo, its closest relative, is known for a loud trumpeting call made with the head thrown back; the Adélie is the most widespread penguin in the Antarctic, found along the entire coast.Size first: in this data Gentoo average 217 mm flippers and 5076 g, against 190–196 mm and about 3700 g for Adelie and Chinstrap, and bill length then splits Chinstrap (48.8 mm) from Adelie (38.8 mm). In the field, Wikipedia gives the chinstrap's narrow black band under the head, and the Adélie's range along the entire Antarctic coast.SpeciesReport(best_features=['eye ring', 'chin band', 'bill colour'], summary='Adélie have a white ring around each eye, chinstraps a thin black line under the chin, gentoos a white patch above each eye and an orange bill.')SpeciesReport(best_features=['flipper_length_mm', 'body_mass_g', 'bill_length_mm'], summary='Flipper length and body mass separate Gentoo (217 mm, 5076 g) from Adelie and Chinstrap (190–196 mm, about 3700 g); bill length then splits Chinstrap (48.8 mm) from Adelie (38.8 mm).')SpeciesReport(best_features=['head band', 'call', 'range'], summary='Wikipedia: the chinstrap has a narrow black band under its head; the gentoo a loud trumpeting call; the Adélie the widest range, along the entire Antarctic coast.')SpeciesReport(best_features=['flipper_length_mm', 'body_mass_g', 'bill_length_mm'], summary='In the data, flipper length and body mass separate Gentoo (217 mm, 5076 g) from the other two, and bill length splits Chinstrap (48.8 mm) from Adelie (38.8 mm); in the field, Wikipedia gives the chinstrap its black band under the head.')agent.loga new file, one line per event, nested agents included
2026-10-12 09:12:04 [Agent] invoke enter: inputs={'task': 'How to tell apart…'}, depth=1, hooks=[…]
2026-10-12 09:12:04 [LLM] query enter: model=openai/gpt-5.4, messages=2 messages
2026-10-12 09:12:07 [LLM] query exit: model=openai/gpt-5.4, cost=$0.0138
2026-10-12 09:12:07 [Agent] repl exec 0 input: code='…', depth=1Same output. The run stayed under $0.50 and 100 calls, so the cap never acted. Past either, invoke raises BudgetPoolExhaustedError instead of returning — and nested agents draw on the same pool.
Same output. The agent returned within 10 turns and never went two agents deep. Past either, invoke raises IterationLimitExhaustedError or RecursionLimitError.
no line for the steps: the agent works out what the task needs and writes the control flow itself, as code
Less wiring, more Python
Same task. See the difference.
Choose a use case and a framework. See how JAZ keeps your objects, tools, and return types in one ordinary Python call.
Turn the same signups dict into a saved matplotlib bar chart.
Shared input — included when you copy either example
from matplotlib.figure import Figure
signups = {"Jan": 120, "Feb": 150, "Mar": 90}- In
signups, the dict- Out
- a
Figure, checked byReturnType
from jaz import configure, invoke
from jaz.hooks import ReturnType
from jaz.llm import LiteLLM
configure(llm=LiteLLM(model="openai/gpt-5-mini"))
fig = invoke(
ReturnType(Figure),
task="Plot signups per month as a bar chart titled 'Signups'.",
signups=signups,
)
fig.savefig("signups.png")Outputan example run; yours will differ
>>> fig
<Figure size 640x480 with 1 Axes>signups.png written to disk
The result is the Figure itself, checked to be one. The agent wrote the plotting code against your data, so a different chart tomorrow needs no new tool.
pip install jaz-lang matplotlib
- In
signups.json, written to disk first- Out
- the last message's text; a PNG the script wrote
import json
from langchain.agents import create_agent
from langchain.agents.middleware import ShellToolMiddleware
with open("signups.json", "w") as file:
json.dump(signups, file)
agent = create_agent(
model="openai:gpt-5-mini",
middleware=[ShellToolMiddleware(workspace_root=".")],
)
result = agent.invoke({
"messages": [{
"role": "user",
"content": "Plot signups per month as a bar chart titled 'Signups'. The data is in"
" signups.json; save it as signups.png.",
}],
})
print(result["messages"][-1].content)Outputan example run; yours will differ
Saved the bar chart 'Signups' to signups.png.signups.png written to disk
In the shell, the agent writes and runs its own matplotlib script. The data goes in as a JSON file and the chart comes out as a PNG on disk, not a Figure.
- In
- the dict, pasted into the prompt, and
plot, a tool - Out
- the last message's text; a PNG
plotwrote
from langchain.agents import create_agent
def plot(kind: str, labels: list[str], values: list[float],
title: str, path: str) -> str:
"""Save a "bar" or "line" chart of values by label to path."""
fig = Figure()
ax = fig.subplots()
draw = {"bar": ax.bar, "line": ax.plot}[kind]
draw(labels, values)
ax.set_title(title)
fig.savefig(path)
return path
agent = create_agent(
model="openai:gpt-5-mini",
tools=[plot],
)
result = agent.invoke({
"messages": [{
"role": "user",
"content": f"Plot signups per month as a bar chart titled 'Signups'.\n{signups}",
}],
})
print(result["messages"][-1].content)Outputan example run; yours will differ
Saved the bar chart 'Signups' to signups.png.A general chart tool: the agent picks the kind and the title and reads the values out of the data. What it can draw is what the tool draws.
pip install langchain langchain-openai matplotlib
- In
- the dict, pasted into the prompt
- Out
- a PNG in OpenAI's container, downloaded by its citation
from agents import Agent, CodeInterpreterTool, Runner
from openai import OpenAI
agent = Agent(
name="Chart assistant",
model="gpt-5-mini",
tools=[CodeInterpreterTool(tool_config={
"type": "code_interpreter",
"container": {"type": "auto"},
})],
)
result = Runner.run_sync(
agent,
f"Plot signups per month as a bar chart titled 'Signups'.\n{signups}",
)
message = result.raw_responses[-1].output[-1]
for note in message.content[0].annotations:
if note.type == "container_file_citation":
png = OpenAI().containers.files.content.retrieve(
note.file_id, container_id=note.container_id)
png.write_to_file("signups.png")Outputan example run; yours will differ
signups.png written to disk
The hosted Code Interpreter writes its own plotting code, but the chart is a PNG in OpenAI’s container: you find it among the response’s file citations and download it.
- In
- the dict, pasted into the prompt, and
plot, a function tool - Out
final_output, text; a PNGplotwrote
from agents import Agent, Runner, function_tool
def plot(kind: str, labels: list[str], values: list[float],
title: str, path: str) -> str:
"""Save a "bar" or "line" chart of values by label to path."""
fig = Figure()
ax = fig.subplots()
draw = {"bar": ax.bar, "line": ax.plot}[kind]
draw(labels, values)
ax.set_title(title)
fig.savefig(path)
return path
agent = Agent(
name="Chart assistant",
model="gpt-5-mini",
tools=[function_tool(plot)],
)
result = Runner.run_sync(
agent,
f"Plot signups per month as a bar chart titled 'Signups'.\n{signups}",
)
print(result.final_output)Outputan example run; yours will differ
Saved the bar chart 'Signups' to signups.png.Wrap a general chart function with function_tool; the agent picks the kind and the title and fills in the values. What it can draw is what the tool draws.
pip install openai-agents matplotlib
- In
signupsandFigure, in yourrun_pythontool's namespace- Out
namespace["fig"], checked by your validator
import contextlib
import io
from pydantic_ai import Agent, ModelRetry
namespace = {"signups": signups, "Figure": Figure}
def run_python(code: str) -> str:
"""Run Python with `signups` and `Figure` in scope.
Returns what the code printed."""
out = io.StringIO()
try:
with contextlib.redirect_stdout(out):
exec(code, namespace)
except Exception as error:
return f"{out.getvalue()}{error!r}"
return out.getvalue()
agent = Agent(
"openai:gpt-5-mini",
tools=[run_python],
)
@agent.output_validator
def check_fig(output: str) -> str:
if not isinstance(namespace.get("fig"), Figure):
raise ModelRetry("Set fig to a Figure.")
return output
agent.run_sync(
"Plot signups per month as a bar chart titled 'Signups'. Leave the Figure in a variable named fig.",
)
namespace["fig"].savefig("signups.png")Outputan example run; yours will differ
>>> namespace["fig"]
<Figure size 640x480 with 1 Axes>signups.png written to disk
Code Mode’s sandbox cannot import matplotlib, so again the closest is your own exec tool. It reaches the real Figure class; you fetch the result out of the namespace by the name you told the agent to use, and the Figure check is an output validator you write.
- In
- the dict, pasted into the prompt, and
plot, a tool - Out
result.output, text; a PNGplotwrote
from pydantic_ai import Agent
def plot(kind: str, labels: list[str], values: list[float],
title: str, path: str) -> str:
"""Save a "bar" or "line" chart of values by label to path."""
fig = Figure()
ax = fig.subplots()
draw = {"bar": ax.bar, "line": ax.plot}[kind]
draw(labels, values)
ax.set_title(title)
fig.savefig(path)
return path
agent = Agent(
"openai:gpt-5-mini",
tools=[plot],
)
result = agent.run_sync(
f"Plot signups per month as a bar chart titled 'Signups'.\n{signups}",
)
print(result.output)Outputan example run; yours will differ
Saved the bar chart 'Signups' to signups.png.Register a general chart function as a tool; the agent picks the kind and the title and fills in the values. What it can draw is what the tool draws.
pip install pydantic-ai matplotlib
- In
signupsandFigure, viaadditional_args- Out
- a
Figure, checked by youris_figure
from smolagents import CodeAgent, OpenAIModel
def is_figure(answer, memory, agent):
return isinstance(answer, Figure)
agent = CodeAgent(
tools=[],
model=OpenAIModel(model_id="gpt-5-mini"),
final_answer_checks=[is_figure],
)
fig = agent.run(
"Plot signups per month as a bar chart titled 'Signups'.",
additional_args={"signups": signups, "Figure": Figure},
)
fig.savefig("signups.png")Outputan example run; yours will differ
>>> fig
<Figure size 640x480 with 1 Axes>signups.png written to disk
Pass the data and the class, and the agent writes the plot, as with JAZ, whose ReturnType adds the class itself. Checking that the result is a Figure is again a final_answer_checks function you write.
- In
- the dict, pasted into the prompt, and
plot, a tool - Out
- the answer, text; a PNG
plotwrote
from smolagents import OpenAIModel, ToolCallingAgent, tool
@tool
def plot(kind: str, labels: list[str], values: list[float],
title: str, path: str) -> str:
"""Save a bar or line chart of values by label to a file.
Args:
kind: "bar" or "line".
labels: One label per value.
values: The values to plot.
title: The chart's title.
path: Where to save the image.
"""
fig = Figure()
ax = fig.subplots()
draw = {"bar": ax.bar, "line": ax.plot}[kind]
draw(labels, values)
ax.set_title(title)
fig.savefig(path)
return path
agent = ToolCallingAgent(
tools=[plot],
model=OpenAIModel(model_id="gpt-5-mini"),
)
result = agent.run(f"Plot signups per month as a bar chart titled 'Signups'.\n{signups}")
print(result)Outputan example run; yours will differ
Saved the bar chart 'Signups' to signups.png.ToolCallingAgent takes the same general chart tool, decorated with @tool and an Args section. What it can draw is what the tool draws.
pip install 'smolagents[openai]' matplotlib
- In
signups, as JSON- Out
result.path, astr; a PNG the REPL wrote
import dspy
dspy.configure(lm=dspy.LM("openai/gpt-5-mini"))
rlm = dspy.RLM(
"signups: dict, task: str -> path: str",
interpreter_factory=dspy.LocalInterpreter,
)
result = rlm(
signups=signups,
task="Plot signups per month as a bar chart titled 'Signups'. Save it as signups.png.",
)
print(result.path)Outputan example run; yours will differ
signups.pngsignups.png written to disk
In RLM the agent writes its own matplotlib. Only JSON leaves the REPL, so the chart comes back as a PNG it saved (a local subprocess can write files), not as a Figure.
- In
signups, as JSON, andplot, a tool- Out
result.path, astr; a PNGplotwrote
import dspy
dspy.configure(lm=dspy.LM("openai/gpt-5-mini"))
def plot(kind: str, labels: list[str], values: list[float],
title: str, path: str) -> str:
"""Save a "bar" or "line" chart of values by label to path."""
fig = Figure()
ax = fig.subplots()
draw = {"bar": ax.bar, "line": ax.plot}[kind]
draw(labels, values)
ax.set_title(title)
fig.savefig(path)
return path
react = dspy.ReAct(
"signups: dict, task: str -> path: str",
tools=[plot],
)
result = react(signups=signups, task="Plot signups per month as a bar chart titled 'Signups'.")
print(result.path)Outputan example run; yours will differ
signups.pngReAct with the general chart function as a tool; the agent picks the kind and the title and fills in the values. What it can draw is what the tool draws.
pip install dspy matplotlib
- In
signupsandFigure, in yourrun_pythontool's namespace- Out
namespace["fig"], checked by your guardrail
import contextlib
import io
from crewai import Agent
from crewai.tools import tool
namespace = {"signups": signups, "Figure": Figure}
@tool
def run_python(code: str) -> str:
"""Run Python with `signups` and `Figure` in scope.
Returns what the code printed."""
out = io.StringIO()
try:
with contextlib.redirect_stdout(out):
exec(code, namespace)
except Exception as error:
return f"{out.getvalue()}{error!r}"
return out.getvalue()
def check_fig(output):
if isinstance(namespace.get("fig"), Figure):
return True, output
return False, "Set fig to a Figure."
agent = Agent(
role="Chart assistant",
goal="Do the task you are given, accurately.",
backstory="You are careful and concise.",
llm="openai/gpt-5-mini",
tools=[run_python],
guardrail=check_fig,
)
agent.kickoff(
"Plot signups per month as a bar chart titled 'Signups'. Leave the Figure in a variable named fig.",
)
namespace["fig"].savefig("signups.png")Outputan example run; yours will differ
>>> namespace["fig"]
<Figure size 640x480 with 1 Axes>signups.png written to disk
With no code interpreter left in CrewAI, again the closest is your own exec tool. It reaches the real Figure class; you fetch the result out of the namespace by the name you told the agent to use, and the Figure check is a guardrail you write.
- In
- the dict, pasted into the prompt, and
plot, a tool - Out
result.raw, text; a PNGplotwrote
from crewai import Agent
from crewai.tools import tool
@tool
def plot(kind: str, labels: list[str], values: list[float],
title: str, path: str) -> str:
"""Save a "bar" or "line" chart of values by label to path."""
fig = Figure()
ax = fig.subplots()
draw = {"bar": ax.bar, "line": ax.plot}[kind]
draw(labels, values)
ax.set_title(title)
fig.savefig(path)
return path
agent = Agent(
role="Chart assistant",
goal="Do the task you are given, accurately.",
backstory="You are careful and concise.",
llm="openai/gpt-5-mini",
tools=[plot],
)
result = agent.kickoff(f"Plot signups per month as a bar chart titled 'Signups'.\n{signups}")
print(result.raw)Outputan example run; yours will differ
Saved the bar chart 'Signups' to signups.png.The general chart function under @tool; the agent picks the kind and the title and fills in the values. What it can draw is what the tool draws.
pip install crewai matplotlib
Find the region with the highest total revenue in the same pandas DataFrame.
Shared input — included when you copy either example
import pandas as pd
sales = pd.DataFrame({
"region": ["North", "South", "North"],
"revenue": [120.0, 90.0, 80.0],
})- In
sales, the live DataFrame- Out
- a
str, checked byReturnType
from jaz import configure, invoke
from jaz.hooks import ReturnType
from jaz.llm import LiteLLM
configure(llm=LiteLLM(model="openai/gpt-5-mini"))
result = invoke(
ReturnType(str),
task="Which region has the most revenue? Return only its name.",
sales=sales,
)
print(result)Outputan example run; yours will differ
NorthPass the live DataFrame. The agent writes the analysis against the object you already have, and the answer is checked to be a str.
pip install jaz-lang pandas
- In
sales.csv, written to disk first- Out
- the last message's text
from langchain.agents import create_agent
from langchain.agents.middleware import ShellToolMiddleware
sales.to_csv("sales.csv", index=False)
agent = create_agent(
model="openai:gpt-5-mini",
middleware=[ShellToolMiddleware(workspace_root=".")],
)
result = agent.invoke({
"messages": [{
"role": "user",
"content": "Which region has the most revenue? Return only its name. The data is in sales.csv.",
}],
})
print(result["messages"][-1].content)Outputan example run; yours will differ
NorthShellToolMiddleware gives the agent a shell, where it writes its own pandas, but in a separate process: the frame is written to a CSV first, and the answer comes back as text. It runs on your machine unless you pass a Docker or Codex execution policy.
- In
previewandaggregate, tools over the frame- Out
- the last message's text
from langchain.agents import create_agent
def preview() -> str:
"""Show the first rows of the sales DataFrame."""
return sales.head().to_string()
def aggregate(by: str, column: str, how: str) -> dict:
"""Group the sales DataFrame by `by`, then aggregate `column`
with `how`: "sum", "mean", "min", "max" or "count"."""
return sales.groupby(by)[column].agg(how).to_dict()
agent = create_agent(
model="openai:gpt-5-mini",
tools=[preview, aggregate],
)
result = agent.invoke({
"messages": [{
"role": "user",
"content": "Which region has the most revenue? Return only its name.",
}],
})
print(result["messages"][-1].content)Outputan example run; yours will differ
NorthWrap general operations on the frame as tools; the agent chains calls to them. It can only do what the tools offer, so a question they do not cover means a new tool.
pip install langchain langchain-openai pandas
- In
sales.csv, uploaded to OpenAI- Out
final_output, text
from agents import Agent, CodeInterpreterTool, Runner
from openai import OpenAI
sales.to_csv("sales.csv", index=False)
upload = OpenAI().files.create(
file=open("sales.csv", "rb"), purpose="user_data")
agent = Agent(
name="Sales analyst",
model="gpt-5-mini",
tools=[CodeInterpreterTool(tool_config={
"type": "code_interpreter",
"container": {"type": "auto", "file_ids": [upload.id]},
})],
)
result = Runner.run_sync(
agent,
"Which region has the most revenue? Return only its name. The data is in sales.csv.",
)
print(result.final_output)Outputan example run; yours will differ
NorthThe hosted Code Interpreter writes its own pandas in OpenAI’s container, so the frame is uploaded as a file first, and the answer comes back as text.
- In
previewandaggregate, function tools over the frame- Out
final_output, text
from agents import Agent, Runner, function_tool
def preview() -> str:
"""Show the first rows of the sales DataFrame."""
return sales.head().to_string()
def aggregate(by: str, column: str, how: str) -> dict:
"""Group the sales DataFrame by `by`, then aggregate `column`
with `how`: "sum", "mean", "min", "max" or "count"."""
return sales.groupby(by)[column].agg(how).to_dict()
agent = Agent(
name="Sales analyst",
model="gpt-5-mini",
tools=[function_tool(preview), function_tool(aggregate)],
)
result = Runner.run_sync(
agent,
"Which region has the most revenue? Return only its name.",
)
print(result.final_output)Outputan example run; yours will differ
NorthWrap general operations on the frame as function tools; the agent chains calls to them. It can only do what the tools offer.
pip install openai-agents pandas
- In
sales, in yourrun_pythontool's namespace- Out
result.output, text
import contextlib
import io
from pydantic_ai import Agent
namespace = {"sales": sales}
def run_python(code: str) -> str:
"""Run Python with `sales`, a pandas DataFrame, in scope.
Returns what the code printed."""
out = io.StringIO()
try:
with contextlib.redirect_stdout(out):
exec(code, namespace)
except Exception as error:
return f"{out.getvalue()}{error!r}"
return out.getvalue()
agent = Agent(
"openai:gpt-5-mini",
tools=[run_python],
)
result = agent.run_sync(
"Which region has the most revenue? Return only its name.",
)
print(result.output)Outputan example run; yours will differ
NorthPydanticAI’s Code Mode runs in Monty, a sandboxed Python subset that cannot import pandas or see your frame. The closest that can is an exec tool you write: it reaches the live frame, with no sandbox, and only printed text comes back.
- In
previewandaggregate, tools over the frame- Out
result.output, text
from pydantic_ai import Agent
def preview() -> str:
"""Show the first rows of the sales DataFrame."""
return sales.head().to_string()
def aggregate(by: str, column: str, how: str) -> dict:
"""Group the sales DataFrame by `by`, then aggregate `column`
with `how`: "sum", "mean", "min", "max" or "count"."""
return sales.groupby(by)[column].agg(how).to_dict()
agent = Agent(
"openai:gpt-5-mini",
tools=[preview, aggregate],
)
result = agent.run_sync(
"Which region has the most revenue? Return only its name.",
)
print(result.output)Outputan example run; yours will differ
NorthRegister general operations on the frame as tools; plain functions work. The agent can only do what the tools offer.
pip install pydantic-ai pandas
- In
sales, the live DataFrame, viaadditional_args- Out
- the answer, checked by your
is_str
from smolagents import CodeAgent, OpenAIModel
def is_str(answer, memory, agent):
return isinstance(answer, str)
agent = CodeAgent(
tools=[],
model=OpenAIModel(model_id="gpt-5-mini"),
final_answer_checks=[is_str],
)
result = agent.run(
"Which region has the most revenue? Return only its name.",
additional_args={"sales": sales},
)
print(result)Outputan example run; yours will differ
NorthThe closest to JAZ: additional_args puts the live frame in the agent’s namespace, and it writes the pandas itself. ReturnType(str)’s check is a final_answer_checks function you write; a failed check is fed back and the agent tries again.
- In
previewandaggregate, tools over the frame- Out
- the answer, checked by your
is_str
from smolagents import OpenAIModel, ToolCallingAgent, tool
@tool
def preview() -> str:
"""Show the first rows of the sales DataFrame."""
return sales.head().to_string()
@tool
def aggregate(by: str, column: str, how: str) -> dict:
"""Group the sales DataFrame by `by`, then aggregate `column`.
Args:
by: The column to group by.
column: The column to aggregate.
how: "sum", "mean", "min", "max" or "count".
"""
return sales.groupby(by)[column].agg(how).to_dict()
def is_str(answer, memory, agent):
return isinstance(answer, str)
agent = ToolCallingAgent(
tools=[preview, aggregate],
model=OpenAIModel(model_id="gpt-5-mini"),
final_answer_checks=[is_str],
)
result = agent.run("Which region has the most revenue? Return only its name.")
print(result)Outputan example run; yours will differ
NorthToolCallingAgent takes the same general tools, each decorated with @tool and given an Args section in its docstring, and the same str check.
pip install 'smolagents[openai]' pandas
- In
sales.to_dict("list"), as JSON- Out
result.region, astrby the signature
import dspy
dspy.configure(lm=dspy.LM("openai/gpt-5-mini"))
rlm = dspy.RLM(
"sales: dict, task: str -> region: str",
interpreter_factory=dspy.LocalInterpreter,
)
result = rlm(
sales=sales.to_dict("list"),
task="Which region has the most revenue? Return only its name.",
)
print(result.region)Outputan example run; yours will differ
NorthRLM, DSPy’s code mode (marked experimental; CodeAct and ProgramOfThought are deprecated for it), has the agent write its own pandas in a REPL, and the typed signature checks the answer. The REPL is a separate process (a WASM sandbox by default, a local subprocess here so pandas imports), so inputs must be JSON: the frame goes in as a dict.
- In
previewandaggregate, tools over the frame- Out
result.region, astrby the signature
import dspy
dspy.configure(lm=dspy.LM("openai/gpt-5-mini"))
def preview() -> str:
"""Show the first rows of the sales DataFrame."""
return sales.head().to_string()
def aggregate(by: str, column: str, how: str) -> dict:
"""Group the sales DataFrame by `by`, then aggregate `column`
with `how`: "sum", "mean", "min", "max" or "count"."""
return sales.groupby(by)[column].agg(how).to_dict()
react = dspy.ReAct(
"task: str -> region: str",
tools=[preview, aggregate],
)
result = react(task="Which region has the most revenue? Return only its name.")
print(result.region)Outputan example run; yours will differ
NorthReAct takes plain functions as tools and chains calls to them; the signature types the answer. It can only do what the tools offer.
pip install dspy pandas
- In
sales, in yourrun_pythontool's namespace- Out
result.raw, text
import contextlib
import io
from crewai import Agent
from crewai.tools import tool
namespace = {"sales": sales}
@tool
def run_python(code: str) -> str:
"""Run Python with `sales`, a pandas DataFrame, in scope.
Returns what the code printed."""
out = io.StringIO()
try:
with contextlib.redirect_stdout(out):
exec(code, namespace)
except Exception as error:
return f"{out.getvalue()}{error!r}"
return out.getvalue()
agent = Agent(
role="Sales analyst",
goal="Do the task you are given, accurately.",
backstory="You are careful and concise.",
llm="openai/gpt-5-mini",
tools=[run_python],
)
result = agent.kickoff("Which region has the most revenue? Return only its name.")
print(result.raw)Outputan example run; yours will differ
NorthCrewAI removed its code interpreter (allow_code_execution is deprecated in favour of an outside sandbox service), so the closest is an exec tool you write: it reaches the live frame, with no sandbox, and only printed text comes back. Every agent also needs a role, a goal and a backstory.
- In
previewandaggregate, tools over the frame- Out
result.raw, text
from crewai import Agent
from crewai.tools import tool
@tool
def preview() -> str:
"""Show the first rows of the sales DataFrame."""
return sales.head().to_string()
@tool
def aggregate(by: str, column: str, how: str) -> dict:
"""Group the sales DataFrame by `by`, then aggregate `column`
with `how`: "sum", "mean", "min", "max" or "count"."""
return sales.groupby(by)[column].agg(how).to_dict()
agent = Agent(
role="Sales analyst",
goal="Do the task you are given, accurately.",
backstory="You are careful and concise.",
llm="openai/gpt-5-mini",
tools=[preview, aggregate],
)
result = agent.kickoff("Which region has the most revenue? Return only its name.")
print(result.raw)Outputan example run; yours will differ
NorthThe same general operations under CrewAI’s @tool decorator; the agent chains calls to them. It can only do what the tools offer, and every agent needs a role, a goal and a backstory.
pip install crewai pandas
Parse the same log into a list of Order dataclass instances.
Shared input — included when you copy either example
from dataclasses import dataclass
@dataclass
class Order:
order_id: str
total_usd: float
log = """2026-03-01 order A-1041 total=$42.50 ok
2026-03-01 order A-1042 total=$8.99 ok
2026-03-02 order A-1043 FAILED timeout
""" # in practice: thousands of lines- In
log, the string- Out
- a
list[Order], checked byReturnType
from jaz import configure, invoke
from jaz.hooks import ReturnType
from jaz.llm import LiteLLM
configure(llm=LiteLLM(model="openai/gpt-5-mini"))
result = invoke(
ReturnType(list[Order]),
task="Return an Order for every line marked ok, in order.",
log=log,
)
print(result)Outputan example run; yours will differ
[Order(order_id='A-1041', total_usd=42.5), Order(order_id='A-1042', total_usd=8.99)]Your dataclass is the schema. The agent writes a parser and runs it over the whole string, so ten thousand lines take the same few turns as three.
pip install jaz-lang
- In
orders.log, written to disk first- Out
structured_response.orders, each record typed out by the model
from langchain.agents import create_agent
from langchain.agents.middleware import ShellToolMiddleware
from pydantic import BaseModel
class Orders(BaseModel):
orders: list[Order]
with open("orders.log", "w") as file:
file.write(log)
agent = create_agent(
model="openai:gpt-5-mini",
middleware=[ShellToolMiddleware(workspace_root=".")],
response_format=Orders,
)
result = agent.invoke({
"messages": [{
"role": "user",
"content": "Return an Order for every line marked ok, in order. The log is in orders.log.",
}],
})
print(result["structured_response"].orders)Outputan example run; yours will differ
[Order(order_id='A-1041', total_usd=42.5), Order(order_id='A-1042', total_usd=8.99)]In the shell the agent can write a parser and run it over the file, but the shell is a separate process: what it parses comes back as text, and the response format then has the model type every record out again as JSON. The schema must be an object, so the list needs a wrapper model.
- In
- the log, pasted into the prompt
- Out
structured_response.orders, each record typed out by the model
from langchain.agents import create_agent
from pydantic import BaseModel
class Orders(BaseModel):
orders: list[Order]
agent = create_agent(
model="openai:gpt-5-mini",
response_format=Orders,
)
result = agent.invoke({
"messages": [{
"role": "user",
"content": f"Return an Order for every line marked ok, in order.\n{log}",
}],
})
print(result["structured_response"].orders)Outputan example run; yours will differ
[Order(order_id='A-1041', total_usd=42.5), Order(order_id='A-1042', total_usd=8.99)]No tool needed: structured output. The schema must be an object, so the list needs a wrapper model, and the log rides in the prompt while the model types every record back out as JSON.
pip install langchain langchain-openai
- In
orders.log, uploaded to OpenAI- Out
final_output, each record typed out by the model
from agents import Agent, CodeInterpreterTool, Runner
from openai import OpenAI
with open("orders.log", "w") as file:
file.write(log)
upload = OpenAI().files.create(
file=open("orders.log", "rb"), purpose="user_data")
agent = Agent(
name="Order parser",
model="gpt-5-mini",
tools=[CodeInterpreterTool(tool_config={
"type": "code_interpreter",
"container": {"type": "auto", "file_ids": [upload.id]},
})],
output_type=list[Order],
)
result = Runner.run_sync(
agent,
"Return an Order for every line marked ok, in order. The log is in orders.log.",
)
print(result.final_output)Outputan example run; yours will differ
[Order(order_id='A-1041', total_usd=42.5), Order(order_id='A-1042', total_usd=8.99)]The hosted Code Interpreter can write a parser and run it over the uploaded log, but the records it parses stay in OpenAI’s container: output_type then has the model type every one out again.
- In
- the log, pasted into the prompt
- Out
final_output, each record typed out by the model
from agents import Agent, Runner
agent = Agent(
name="Order parser",
model="gpt-5-mini",
output_type=list[Order],
)
result = Runner.run_sync(
agent,
f"Return an Order for every line marked ok, in order.\n{log}",
)
print(result.final_output)Outputan example run; yours will differ
[Order(order_id='A-1041', total_usd=42.5), Order(order_id='A-1042', total_usd=8.99)]No tool needed: output_type accepts a list of dataclasses. The log still rides in the prompt, and every record comes back as model output.
pip install openai-agents
- In
logandOrder, in yourrun_pythontool's namespace- Out
namespace["orders"], checked by your validator
import contextlib
import io
from pydantic_ai import Agent, ModelRetry
namespace = {"log": log, "Order": Order}
def run_python(code: str) -> str:
"""Run Python with `log`, a str, and `Order`, a dataclass, in scope.
Returns what the code printed."""
out = io.StringIO()
try:
with contextlib.redirect_stdout(out):
exec(code, namespace)
except Exception as error:
return f"{out.getvalue()}{error!r}"
return out.getvalue()
agent = Agent(
"openai:gpt-5-mini",
tools=[run_python],
)
@agent.output_validator
def check_orders(output: str) -> str:
orders = namespace.get("orders")
if not (isinstance(orders, list) and all(
isinstance(order, Order) for order in orders)):
raise ModelRetry("Set orders to a list of Order.")
return output
agent.run_sync(
"Return an Order for every line marked ok, in order. Leave the list in a variable named orders.",
)
print(namespace["orders"])Outputan example run; yours will differ
[Order(order_id='A-1041', total_usd=42.5), Order(order_id='A-1042', total_usd=8.99)]With your own exec tool the agent writes the parser against the real string and builds real Orders. You fetch them out of the namespace by the name you told it to use, and the type check is an output validator you write, which sends a failure back to the agent.
- In
- the log, pasted into the prompt
- Out
result.output, each record typed out by the model
from pydantic_ai import Agent
agent = Agent(
"openai:gpt-5-mini",
output_type=list[Order],
)
result = agent.run_sync(
f"Return an Order for every line marked ok, in order.\n{log}",
)
print(result.output)Outputan example run; yours will differ
[Order(order_id='A-1041', total_usd=42.5), Order(order_id='A-1042', total_usd=8.99)]No tool needed, and just as short. The difference is where the work happens: the model emits each record as tokens, instead of writing one parser.
pip install pydantic-ai
- In
logandOrder, viaadditional_args- Out
- the list, checked by your
is_orders
from smolagents import CodeAgent, OpenAIModel
def is_orders(answer, memory, agent):
return isinstance(answer, list) and all(
isinstance(order, Order) for order in answer)
agent = CodeAgent(
tools=[],
model=OpenAIModel(model_id="gpt-5-mini"),
final_answer_checks=[is_orders],
)
result = agent.run(
"Return an Order for every line marked ok, in order.",
additional_args={"log": log, "Order": Order},
)
print(result)Outputan example run; yours will differ
[Order(order_id='A-1041', total_usd=42.5), Order(order_id='A-1042', total_usd=8.99)]Your objects go in the same way, and the agent writes the parser. The type check is yours to write, as a final_answer_checks function, where JAZ takes ReturnType(list[Order]).
- In
- the log, pasted into the prompt
- Out
final_answer's JSON, validated intoOrders
from pydantic import TypeAdapter
from smolagents import OpenAIModel, ToolCallingAgent
orders = TypeAdapter(list[Order])
def is_orders(answer, memory, agent):
orders.validate_python(answer)
return True
agent = ToolCallingAgent(
tools=[],
model=OpenAIModel(model_id="gpt-5-mini"),
final_answer_checks=[is_orders],
)
result = agent.run(f"Return an Order for every line marked ok, in order.\n{log}")
print(orders.validate_python(result))Outputan example run; yours will differ
[Order(order_id='A-1041', total_usd=42.5), Order(order_id='A-1042', total_usd=8.99)]ToolCallingAgent needs no tool but its final_answer, whose argument is JSON, so the log rides in the prompt and the model types every record out. The check validates that JSON against Order with Pydantic, and a mismatch is fed back.
pip install 'smolagents[openai]'
- In
log, as JSON- Out
result.orders, submitted dicts validated intoOrders
import dspy
dspy.configure(lm=dspy.LM("openai/gpt-5-mini"))
class ParseOrders(dspy.Signature):
"""Return an Order for every line marked ok, in order."""
log: str = dspy.InputField()
orders: list[Order] = dspy.OutputField()
rlm = dspy.RLM(
ParseOrders,
interpreter_factory=dspy.LocalInterpreter,
)
result = rlm(log=log)
print(result.orders)Outputan example run; yours will differ
[Order(order_id='A-1041', total_usd=42.5), Order(order_id='A-1042', total_usd=8.99)]The signature is the schema. In RLM the agent writes the parser and submits plain dicts, which DSPy validates into your Orders, sending a mismatch back to the agent to fix. The Order class itself cannot go into the REPL; only JSON can.
- In
log, in the prompt- Out
result.orders, each record typed out by the model
import dspy
dspy.configure(lm=dspy.LM("openai/gpt-5-mini"))
class ParseOrders(dspy.Signature):
"""Return an Order for every line marked ok, in order."""
log: str = dspy.InputField()
orders: list[Order] = dspy.OutputField()
parse = dspy.Predict(ParseOrders)
result = parse(log=log)
print(result.orders)Outputan example run; yours will differ
[Order(order_id='A-1041', total_usd=42.5), Order(order_id='A-1042', total_usd=8.99)]No tool needed: Predict with the same signature. The log rides in the prompt, and the model types every record back out, which DSPy parses into Orders.
pip install dspy
- In
logandOrder, in yourrun_pythontool's namespace- Out
namespace["orders"], checked by your guardrail
import contextlib
import io
from crewai import Agent
from crewai.tools import tool
namespace = {"log": log, "Order": Order}
@tool
def run_python(code: str) -> str:
"""Run Python with `log`, a str, and `Order`, a dataclass, in scope.
Returns what the code printed."""
out = io.StringIO()
try:
with contextlib.redirect_stdout(out):
exec(code, namespace)
except Exception as error:
return f"{out.getvalue()}{error!r}"
return out.getvalue()
def check_orders(output):
orders = namespace.get("orders")
if isinstance(orders, list) and all(
isinstance(order, Order) for order in orders):
return True, output
return False, "Set orders to a list of Order."
agent = Agent(
role="Order parser",
goal="Do the task you are given, accurately.",
backstory="You are careful and concise.",
llm="openai/gpt-5-mini",
tools=[run_python],
guardrail=check_orders,
)
agent.kickoff(
"Return an Order for every line marked ok, in order. Leave the list in a variable named orders.",
)
print(namespace["orders"])Outputan example run; yours will differ
[Order(order_id='A-1041', total_usd=42.5), Order(order_id='A-1042', total_usd=8.99)]With your own exec tool the agent writes the parser against the real string and builds real Orders. You fetch them out of the namespace by the name you told it to use, and the type check is a guardrail you write, which sends a failure back to the agent.
- In
- the log, pasted into the prompt
- Out
result.pydantic.orders, each record typed out by the model
from crewai import Agent
from pydantic import BaseModel
class Orders(BaseModel):
orders: list[Order]
agent = Agent(
role="Order parser",
goal="Do the task you are given, accurately.",
backstory="You are careful and concise.",
llm="openai/gpt-5-mini",
)
result = agent.kickoff(
f"Return an Order for every line marked ok, in order.\n{log}",
response_format=Orders,
)
print(result.pydantic.orders)Outputan example run; yours will differ
[Order(order_id='A-1041', total_usd=42.5), Order(order_id='A-1042', total_usd=8.99)]No tool needed: response_format takes a Pydantic model, so the list needs a wrapper, and the log rides in the prompt while the model types every record back out.
pip install crewai
Label a list of reviews, stopping the whole run at five US cents of model spend.
Shared input — included when you copy either example
reviews = [
"Arrived fast and works perfectly.",
"Broke after two days.",
"Fine for the price.",
] # in practice: thousands- In
reviews, the list- Out
- a
list[str], checked byReturnType;BudgetPoolExhaustedErrorpast five cents
from jaz import configure, invoke
from jaz.hooks import BudgetPool, ReturnType
from jaz.llm import LiteLLM
configure(llm=LiteLLM(model="openai/gpt-5-mini"))
with BudgetPool(cost_budget=0.05):
labels = invoke(
ReturnType(list[str]),
task="Label each review positive, negative or neutral, in order.",
reviews=reviews,
)
print(labels)Outputan example run; yours will differ
['positive', 'negative', 'neutral']A hook in a with block. The cap is in dollars, priced by JAZ, and it covers every sub-agent the call starts, with nothing to thread through.
pip install jaz-lang
- In
- the reviews, pasted into the prompt
- Out
structured_response.labels; yourRuntimeErrorpast five cents
from langchain.agents import create_agent
from langchain.agents.middleware import after_model
from pydantic import BaseModel
PRICE_IN, PRICE_OUT = 0.25e-6, 2e-6 # gpt-5-mini, USD per token
class Labels(BaseModel):
labels: list[str]
@after_model
def cap_spend(state, runtime):
spent = sum(
m.usage_metadata["input_tokens"] * PRICE_IN
+ m.usage_metadata["output_tokens"] * PRICE_OUT
for m in state["messages"]
if getattr(m, "usage_metadata", None))
if spent >= 0.05:
raise RuntimeError("Spent five cents; stopping.")
agent = create_agent(
model="openai:gpt-5-mini",
middleware=[cap_spend],
response_format=Labels,
)
result = agent.invoke({
"messages": [{
"role": "user",
"content": f"Label each review positive, negative or neutral, in order.\n{reviews}",
}],
})
print(result["structured_response"].labels)Outputan example run; yours will differ
['positive', 'negative', 'neutral']No dollar cap built in (ModelCallLimitMiddleware counts calls), so it is middleware you write: price each response’s tokens yourself and raise. It is the same middleware on a code-mode agent, and a sub-agent is a separate agent, which needs it too.
pip install langchain langchain-openai
- In
- the reviews, pasted into the prompt
- Out
final_output, alist[str]; yourRuntimeErrorpast five cents
from agents import Agent, RunHooks, Runner
PRICE_IN, PRICE_OUT = 0.25e-6, 2e-6 # gpt-5-mini, USD per token
class CapSpend(RunHooks):
async def on_llm_end(self, context, agent, response):
usage = context.usage
spent = (usage.input_tokens * PRICE_IN
+ usage.output_tokens * PRICE_OUT)
if spent >= 0.05:
raise RuntimeError("Spent five cents; stopping.")
agent = Agent(
name="Review labeller",
model="gpt-5-mini",
output_type=list[str],
)
result = Runner.run_sync(
agent,
f"Label each review positive, negative or neutral, in order.\n{reviews}",
hooks=CapSpend(),
)
print(result.final_output)Outputan example run; yours will differ
['positive', 'negative', 'neutral']No dollar cap built in (max_turns counts turns), so it is a run hook you write: price the run’s tokens yourself and raise. It is the same hook with Code Interpreter, and an agent used as a tool runs separately and needs it too.
pip install openai-agents
- In
- the reviews, pasted into the prompt
- Out
result.output, alist[str];UsageLimitExceededpast five cents
from decimal import Decimal
from pydantic_ai import Agent
from pydantic_ai.usage import UsageLimits
agent = Agent(
"openai:gpt-5-mini",
output_type=list[str],
)
result = agent.run_sync(
f"Label each review positive, negative or neutral, in order.\n{reviews}",
usage_limits=UsageLimits(cost_limit=Decimal("0.05")),
)
print(result.output)Outputan example run; yours will differ
['positive', 'negative', 'neutral']A dollar cap built in, as a usage limit on the run, the same with an exec tool. A delegate agent counts against it only if you pass usage=ctx.usage into its run yourself.
pip install pydantic-ai
- In
reviews, viaadditional_args- Out
- the list, checked by your
is_labels; an interrupted run past five cents
from smolagents import CodeAgent, OpenAIModel
PRICE_IN, PRICE_OUT = 0.25e-6, 2e-6 # gpt-5-mini, USD per token
spent = 0.0
def cap_spend(step, agent):
global spent
used = step.token_usage
spent += (used.input_tokens * PRICE_IN
+ used.output_tokens * PRICE_OUT)
if spent >= 0.05:
agent.interrupt()
def is_labels(answer, memory, agent):
return isinstance(answer, list) and all(
isinstance(label, str) for label in answer)
agent = CodeAgent(
tools=[],
model=OpenAIModel(model_id="gpt-5-mini"),
step_callbacks=[cap_spend],
final_answer_checks=[is_labels],
)
result = agent.run(
"Label each review positive, negative or neutral, in order.",
additional_args={"reviews": reviews},
)
print(result)Outputan example run; yours will differ
['positive', 'negative', 'neutral']No cost cap built in (max_steps counts steps), so it is a step callback you write: price the tokens yourself and interrupt the agent. Each managed sub-agent needs the callback too.
pip install 'smolagents[openai]'
- In
reviews, in the prompt- Out
result.labels, alist[str]; yourRuntimeErrorpast five cents
import dspy
class CappedLM(dspy.LM):
def __call__(self, *args, **kwargs):
spent = sum(entry["cost"] or 0 for entry in self.history)
if spent >= 0.05:
raise RuntimeError("Spent five cents; stopping.")
return super().__call__(*args, **kwargs)
dspy.configure(lm=CappedLM("openai/gpt-5-mini"))
label = dspy.Predict("reviews: list[str], task: str -> labels: list[str]")
result = label(reviews=reviews, task="Label each review positive, negative or neutral, in order.")
print(result.labels)Outputan example run; yours will differ
['positive', 'negative', 'neutral']No spend cap built in, but DSPy prices every call, so the cap is a subclass of its LM that stops once the recorded cost reaches five cents. No tool is needed, so the module is Predict; every module calls the configured LM, so the same cap covers ReAct and RLM, including RLM’s llm_query sub-calls.
pip install dspy
- In
- the reviews, pasted into the prompt
- Out
result.pydantic.labels;LLMCallBlockedErrorpast five cents
from crewai import Agent
from crewai.hooks import before_llm_call
from pydantic import BaseModel
PRICE_IN, PRICE_OUT = 0.25e-6, 2e-6 # gpt-5-mini, USD per token
class Labels(BaseModel):
labels: list[str]
@before_llm_call
def cap_spend(context):
used = context.llm.get_token_usage_summary()
spent = (used.prompt_tokens * PRICE_IN
+ used.completion_tokens * PRICE_OUT)
if spent >= 0.05:
return False
agent = Agent(
role="Review labeller",
goal="Do the task you are given, accurately.",
backstory="You are careful and concise.",
llm="openai/gpt-5-mini",
)
result = agent.kickoff(
f"Label each review positive, negative or neutral, in order.\n{reviews}",
response_format=Labels,
)
print(result.pydantic.labels)Outputan example run; yours will differ
['positive', 'negative', 'neutral']No dollar cap built in (max_iter and max_rpm count steps and requests), so it is a before_llm_call hook you write: price the tokens yourself and block the next call, which raises. It is the same hook with an exec tool; hooks are global, but each agent’s LLM counts only its own tokens.
pip install crewai