gnosis / prediction-market-agent

GNU Lesser General Public License v3.0
26 stars 5 forks source link

Allow the general agent to install and use libraries #270

Open kongzii opened 3 months ago

kongzii commented 3 months ago

We were talking about making the agent code its own functions to use. However

  1. Without access to libraries to use, it won't code much
  2. It's super hard to code something from scratch, and there are already open-source projects for that anyway (eg OpenDevin)
  3. Why code something if there is a library to do it? (which is often the case in Python)

A more low-hanging fruit but still cool is:

  1. Allow the agent to search on PyPi and Google
  2. Allow the agent to install arbitrary library at runtime (not sure how, but usually anything is possible in Python if one is willing to be hacky enough 😄 )
  3. Allow the agent to scrap library's documentation
  4. And use it in the end

But not sure what would be a goal to achieve with this. Would be nice to come up with a goal that the agent should do in the end, without us creating a specific Function for it. Perhaps removing the BuyTokens function and making him figure out the PMAT library?

gabrielfior commented 3 months ago

This sounds a lot like what AutoGen already does within its CodeExecutors https://microsoft.github.io/autogen/docs/tutorial/code-executors/ - maybe we can use that somehow instead of coding from scratch?

evangriffiths commented 3 months ago

Perhaps removing the BuyTokens function and making him figure out the PMAT library?

I like this idea. It would require adding docstrings to the AgentMarket class. An alternative would be to take a different project like CowSwap (https://docs.cow.fi/cow-protocol/reference/apis/orderbook) or uniswap (https://uniswap-python.com/) which is already well documented.

kongzii commented 3 months ago

I like the idea of using already documented projects! 😄 Perhaps making him swap for some token with yield? That would also come with a bunch of interesting Learn* functions.

gabrielfior commented 3 months ago

Some additional thoughts: -> AutoGen has the LocalCommandLineCodeExecutor and allows for the agent to be executed within a venv. Hence the agent could install packages using a Tool that creates a venv with the new package programatically. -> So theoretically, the agent could simply run pip install MY_PACKAGE and use it afterwards, since it will be available in the venv. -> Another step is allowing the agent to search PyPI and other sources (I expect langchain/crewai/autogen to have something for this already)

evangriffiths commented 3 months ago

Came across this library which looks handy for adding the code interpreter feature https://github.com/e2b-dev/code-interpreter

With it you can do:

from e2b_code_interpreter import CodeInterpreter

with CodeInterpreter() as sandbox:
    sandbox.notebook.exec_cell("x = 1")

    execution = sandbox.notebook.exec_cell("x+=1; x")
    print(execution.text)  # outputs 2
kongzii commented 2 months ago

https://github.com/e2b-dev/code-interpreter looks cool, but the code runs inside of their cloud environment, which is great, because all worries about running unsafe, API keys stealing or in some other way malicious code is on them, on the other hand, it's yet another web2 provider that we need to pay for.

Autogen's DockerCommandLineCodeExecutor should probably be safe enough, but I'm not sure we will be able to use docker inside of Kubernetes.

I'll try to make it work with LocalCommandLineCodeExecutor, and we can swap it later.

kongzii commented 2 months ago

Implementing LocalCommandLineCodeExecutor was easier than expected, but keeping this open as we will need to switch to either DockerCommandLineCodeExecutor or e2b_code_interpreter if we would offer this functionality to the world.