見出し画像

AutoGen が出たので触ってみる

メモしながら https://microsoft.github.io/autogen/docs/Getting-Started/ の Tutorial を進めてみる。

AutoGen は AIAgent ではあるが、複数の LLM や ツール、人間との対話をしながら問題を解決する agent である。 最近話題に上がる、 LLM 毎の得手不得手を理解して、使い分けてくれるというらしい。

早速動かす。以下でインストール。

pip install pyautogen 


Tutorial にあるコードをそのまま動かしてみる

from autogen import AssistantAgent, UserProxyAgent, config_list_from_json

# Load LLM inference endpoints from an env variable or a file
# See https://microsoft.github.io/autogen/docs/FAQ#set-your-api-endpoints
# and OAI_CONFIG_LIST_sample.json
config_list = config_list_from_json(env_or_file="OAI_CONFIG_LIST")
assistant = AssistantAgent("assistant", llm_config={"config_list": config_list})
user_proxy = UserProxyAgent("user_proxy", code_execution_config={"work_dir": "coding"})
user_proxy.initiate_chat(assistant, message="Plot a chart of NVDA and TESLA stock price change YTD.")
# This initiates an automated chat between the two agents to solve the task

 実行ログ

Plot a chart of NVDA and TESLA stock price change YTD.

--------------------------------------------------------------------------------
assistant (to user_proxy):

Firstly, let's ensure that all the necessary libraries are installed. Run the following commands to install them if you haven't already:

```python
!pip install yfinance matplotlib pandas
```

After installing needed libraries, execute the Python code below to plot a chart of NVDA and TESLA stock price change Year-To-Date (YTD):

```python
# Python code

import yfinance as yf
import matplotlib.pyplot as plt

# Fetch data
nvda = yf.Ticker("NVDA")
tesla = yf.Ticker("TSLA")

# Get historical market data YTD
nvda_hist = nvda.history(period="YTD")
tesla_hist = tesla.history(period="YTD")

# Plot NVDA close price
plt.figure(figsize=(14,7))
plt.plot(nvda_hist.index, nvda_hist['Close'], label='NVDA')

# Plot TESLA close price
plt.plot(tesla_hist.index, tesla_hist['Close'], label='TESLA')

plt.title('NVDA vs TESLA YTD Close Prices')
plt.xlabel('Date')
plt.ylabel('Close Price (USD)')
plt.legend()
plt.grid()
plt.show()
```

This script uses the `yfinance` library to fetch the year-to-date (YTD) stock prices for NVDA and TESLA. Then, it plots them on a line chart using `matplotlib.pyplot`. The prices represented in the chart are the closing prices for each trading day. The x-axis represents the date, and the y-axis represents the closing price in USD.

--------------------------------------------------------------------------------
Provide feedback to assistant. Press enter to skip and use auto-reply, or type 'exit' to end the conversation:

Feedback を求められる。 試しに enter を押して skip

--------------------------------------------------------------------------------
Provide feedback to assistant. Press enter to skip and use auto-reply, or type 'exit' to end the conversation:

>>>>>>>> NO HUMAN INPUT RECEIVED.

>>>>>>>> USING AUTO REPLY...

>>>>>>>> EXECUTING CODE BLOCK 0 (inferred language is python)...
user_proxy (to assistant):

exitcode: 1 (execution failed)
Code output:
  File "", line 1
    !pip install yfinance matplotlib pandas
    ^
SyntaxError: invalid syntax


--------------------------------------------------------------------------------

feedback が無いと「feedback なし」で進む。この辺 OpenInterpreter だと止まる。「勝手にやっといて。できる範囲で」は人への指示としては当然存在するのでより直感的に AGI に近づいてる感じが。

進まないので、 前に進むよう feedback をすると、下記を求められる。

This script will download the Year-To-Date (YTD) historical data for TESLA and NVDA, and then plot it. Please input the correct start and end dates in the code.

ので 20200101 ~ 今までのを取ってもらうように feedback

(Script がある)
---
To run the script, navigate the terminal to the directory where you saved 'stock_plot.py' and use the following command:

Python 2.x : `python stock_plot.py`

Python 3.x : `python3 stock_plot.py`

The chart will be displayed in a pop-up window. Python must be installed and available in your terminal path to be used directly from the command line.

Make sure matplotlib, yfinance and pandas are installed in your Python environment. If not, you can use pip to locally install these libraries using the following commands:

Python 2.x : `pip install matplotlib pandas yfinance`

Python 3.x : `pip3 install matplotlib pandas yfinance`

Provide feedback to assistant. Press enter to skip and use auto-reply, or type 'exit' to end the conversation: go ahead

あれ、コードを書くことと指示はしてくれるけど、実行はしてくれないんだ。完璧アシスタントって感じだ。

頼むから実行してくれと伝える

Apologies for any confusion but as an AI, I'm not capable of executing commands or scripts locally on your computer. You can follow the instructions provided to execute the code on your own machine.

You need a Python environment installed and set up on your computer to execute Python code. The Python environment should have necessary libraries such as matplotlib, yfinance and pandas installed.

If you're having trouble running the code or if you encounter any errors, feel free to share them and I'd be happy to help troubleshoot.

駄目らしい。まぁ Microsoft が相対する顧客基準って感じなので、残念だが概ね期待通り。

ここまでの対話のクオリティとかはとても高いと感じた。無理らしい。

ただ、この辺(https://github.com/microsoft/autogen/blob/main/notebook/agentchat_MathChat.ipynb)を見ると、依頼に対してはかなり忠実にやるべきことをやってくれそうではある。

次回は autogen の notebook を順に動かしてみよう。


お酒と映画と読書が大好きで夜も眠れません。たくさん働きます。 プロダクトマネージャー ← 受託開発会社代表(コーディング/セールス/PM)。 fintech / プロダクト / 映画の呟きが多め。 ストーリーあるものが好き。