Skip to content

Python Executor Tool

Python Executor Tool lets an agent work out calculations and data operations by itself, by writing a small program and running it. You don’t write anything: when the agent needs to, for example, add up a column, calculate dates or reorder a list, it writes the program, runs it and uses the result in its answer.

Connect its Tool output to the agent’s Tools input.

When to use it

  • The agent has to do exact calculations, such as totals, averages, percentages or interest.
  • You need to count working days between two dates or work out due dates.
  • The agent receives data and has to sort, group or reformat it.
  • You want reliable numerical answers instead of the model’s approximate calculations.

Configuration

FieldWhat it does
Tool Name (required)The name the agent sees for the tool. Default: python_executor.

Advanced options

FieldWhat it does
Debug ModeWhen on and the program fails, the error message the agent gets also includes the program that was run. Useful for reviewing failures in the trace. Off by default.

Output

Tool: the tool ready for the agent. Connect it to the agent’s Tools input. The agent gets back whatever the program shows when it finishes or, if it fails, the error message, so it can fix it and try again.

Example

An accounting firm wants an assistant that calculates late-payment interest.

  1. Add Python Executor Tool and connect it to the agent’s Tools input.
  2. In the agent’s instructions, say it must do every calculation with this tool.
  3. When someone asks for the interest on a 12,500 euro invoice paid 47 days late at 8% a year, the agent writes the calculation, runs it and replies with the exact amount.
  • Python Code: if you want to write the program yourself as a fixed step in the flow.
  • Calculator: simple arithmetic.