ChatGPTが現れた当初、自立型エージェントとしてBabyAGIはインパクトがありました。シンプルな自己構築型エージェントとして「BabyAGI 2o - the simplest self-building autonomous agent.」が公開されていました。簡単なコードで実現されていて勉強にもなります。
ollama(qwen2.5-code)と組み合わせ
BabyAGI的な機能を完全には達成できませんでしたが、折角なのでローカルLLMと組み合わせてColab上で遊んでみました。シンプルなプログラムなので、ollamaで動作できるように直接書き換えました。ローカルLLMはコンパクトでコード生成タスクに特化したqwen2.5-codeを使いました。tool作成に失敗やエラーでループに突入することもあります。しかしながら、コード生成はそこそこやれているようです。
複雑なプロンプトのため、ダメもとでのトライでした。しかし、小型のLLMの場合はタスク立案とコード生成のLLMを分けるといった機能分離すれば、行けるかも・・・と可能性を感じる結果でした。
ちなみに、単に入れ替えただけでは、Gemini_Flashでは成功しませんでした。LiteLLM側の問題なのか、そうでないかは未検証です。実装されちゃうのも時間の問題しれません。機会があったら挑戦してみたいと思います。
円周率を10桁計算して表示
Registered tool: create_or_update_tool
Registered tool: install_package
Registered tool: task_completed
Describe the task you want to complete: 円周率の計算をして10桁を表示する。
Iteration 1 running...
Calling tool: create_or_update_tool with args: {'name': 'calculate_pi', 'code': 'import math
def calculate_pi(digits):
return str(math.pi)[:digits + 2]
', 'description': 'Calculates the value of pi to a specified number of digits.', 'parameters': {'digits': {'type': 'integer', 'description': 'The number of digits after the decimal point to calculate for pi.'}}}
Registered tool: calculate_pi
Result of create_or_update_tool: Tool 'calculate_pi' created/updated successfully.
Iteration 2 running...
Calling tool: calculate_pi with args: {'digits': 10}
Result of calculate_pi: 3.1415926535
Iteration 3 running...
Calling tool: task_completed with args: {}
Result of task_completed: Task marked as completed.
Task completed.
Max iterations reached or task completed.
太字の部分が生成したものです。そりゃ・・・一番簡単な解決法です。ごめんなさい。
お天気を調べてLINEに通知するというタスクを作成してもらいました。コードに相当する部分は見やすくするため改行を入れています。
Iteration 1 running...
Calling tool: create_or_update_tool with args: {'name': 'get_weather_data', 'code':"import requests
import json
def get_weather_data(location):
api_key = 'YOUR_OPENWEATHERMAP_API_KEY'
url = f'http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}'
response = requests.get(url)
data = json.loads(response.text)
return data
", 'description': 'Fetches weather data for a specified location using OpenWeatherMap API.', 'parameters': {'location': {'type': 'string', 'description': 'The city name for which to fetch the weather.'}}}
Registered tool: get_weather_data
Result of create_or_update_tool: Tool 'get_weather_data' created/updated successfully.
Iteration 2 running...
Calling tool: create_or_update_tool with args: {'name': 'send_line_notification', 'code': "import requests
def send_line_notification(message):
line_token = 'YOUR_LINE_TOKEN_HERE'
headers = {
'Authorization': f'Bearer {line_token}',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'\n }
payload = {'message': message}
response = requests.post('https://api.line.me/v2/bot/message/push', headers=headers, data=payload)
if response.status_code == 200:
return 'Notification sent successfully.'
else:
return 'Failed to send notification.
'", 'description': 'Sends a message to a LINE user using the provided token.', 'parameters': {'type': 'object', 'properties': {'message': {'type': 'string', 'description': 'The message to send.'}}}}
Registered tool: send_line_notification
Result of create_or_update_tool: Tool 'send_line_notification' created/updated successfully.
Iteration 3 running...
Calling tool: task_completed with args: {}
Result of task_completed: Task marked as completed.
Task completed.
Max iterations reached or task completed.
元祖BabyAGIしたのは一年前。それからLLMの進歩は半端ないですね。
今回使ったColabノートブックです。