-
Notifications
You must be signed in to change notification settings - Fork 0
Python Interpreter Tool
David-Andrew Samson edited this page Jun 22, 2023
·
9 revisions
Archytas provides a (currently a work in progress) python tool that allows the LLM to write/run scripts in a persistent environment.
bare-bones python tool with nothing extra added
from archytas.tools import PythonTool
agent = ReActAgent(tools=[PythonTool], verbose=True)
# query agent
response = agent.query('write me a script that prints out the first 100 prime numbers')
print(response)
#etc...
In the future, you'll be able to include pre-initialized custom local variables (including @tools
and @toolsets
) in the python environment, as well as provide prelude code to run on initialization
from archytas.demo_tools import fib_n, jackpot, ModelSimulation
python = PythonTool(
prelude='import numpy as np\nfrom matplotlib import pyplot as plt',
locals={'fib_n': fib_n, 'jackpot': jackpot, 'ModelSimulation': ModelSimulation},
)
tools = [python]
agent = ReActAgent(tools=tools, verbose=True)
# do your queries ...
The user input in the demo follows the following script:
- write a python script to download the csv from this link: https://covid.ourworldindata.org/data/owid-covid-data.csv
- now load the csv into a dataframe and print out the columns and head
- that's a lot of data, can you filter for just new US cases?
- can you plot this
- in the plot, there are too many dates on the x-axis, so they all just overlap into one big black blob. Can you fix that?
- there seem to be some cyclicalities and artifacts in the raw data. Can you plot a 7-day moving average?
- looks good. Can you tell me what day had the most new cases?
- What was the mean and median number of new cases? use the 7-day moving average
- Can you plot a histogram of the new daily cases (from the 7-day average) and mark the mean and median
The only special libraries that are in the environment are pandas
, and matplotlib
. At each step the agent is able to write a script to run in the python tool that solves the current prompt, making use of persistent variables in the tool during successive calls.
- passing in python modules, classes, functions, variables, etc.
- having the python tool run a default prelude script (e.g. for imports, etc)
- having a way for the LLM to lookup a provided local variable's usage docs (esp. if it's an @tool that the LLM wouldn't be familiar with)
- oneshot version of the tool with no persistence