bstraehle commited on
Commit
0d55b74
·
verified ·
1 Parent(s): bee3b29

Delete multi-agent-ai.ipynb

Browse files
Files changed (1) hide show
  1. multi-agent-ai.ipynb +0 -194
multi-agent-ai.ipynb DELETED
@@ -1,194 +0,0 @@
1
- {
2
- "nbformat": 4,
3
- "nbformat_minor": 0,
4
- "metadata": {
5
- "colab": {
6
- "provenance": []
7
- },
8
- "kernelspec": {
9
- "name": "python3",
10
- "display_name": "Python 3"
11
- },
12
- "language_info": {
13
- "name": "python"
14
- }
15
- },
16
- "cells": [
17
- {
18
- "cell_type": "code",
19
- "execution_count": null,
20
- "metadata": {
21
- "id": "ERCO7TceMBRu"
22
- },
23
- "outputs": [],
24
- "source": [
25
- "!pip install chess==1.10.0 ipython==8.24.0 pyautogen==0.2.25"
26
- ]
27
- },
28
- {
29
- "cell_type": "code",
30
- "source": [
31
- "import chess\n",
32
- "import chess.svg\n",
33
- "from autogen import ConversableAgent, register_function\n",
34
- "from IPython.display import SVG\n",
35
- "from typing_extensions import Annotated"
36
- ],
37
- "metadata": {
38
- "id": "VenicfTZMtYl"
39
- },
40
- "execution_count": null,
41
- "outputs": []
42
- },
43
- {
44
- "cell_type": "code",
45
- "source": [
46
- "made_move = False\n",
47
- "\n",
48
- "board = chess.Board()\n",
49
- "\n",
50
- "def get_legal_moves() -> Annotated[str, \"A list of legal moves in UCI format\"]:\n",
51
- " return \"Possible moves are: \" + \",\".join(\n",
52
- " [str(move) for move in board.legal_moves]\n",
53
- " )\n",
54
- "\n",
55
- "def make_move(move: Annotated[str, \"A move in UCI format.\"]) -> Annotated[str, \"Result of the move.\"]:\n",
56
- " move = chess.Move.from_uci(move)\n",
57
- " board.push_uci(str(move))\n",
58
- " global made_move\n",
59
- " made_move = True\n",
60
- "\n",
61
- " SVG(\n",
62
- " chess.svg.board(\n",
63
- " board,\n",
64
- " arrows=[(move.from_square, move.to_square)],\n",
65
- " fill={move.from_square: \"gray\"},\n",
66
- " size=200\n",
67
- " )\n",
68
- " )\n",
69
- "\n",
70
- " piece = board.piece_at(move.to_square)\n",
71
- " piece_symbol = piece.unicode_symbol()\n",
72
- " piece_name = (\n",
73
- " chess.piece_name(piece.piece_type).capitalize()\n",
74
- " if piece_symbol.isupper()\n",
75
- " else chess.piece_name(piece.piece_type)\n",
76
- " )\n",
77
- " return f\"Moved {piece_name} ({piece_symbol}) from \"\\\n",
78
- " f\"{chess.SQUARE_NAMES[move.from_square]} to \"\\\n",
79
- " f\"{chess.SQUARE_NAMES[move.to_square]}.\"\n",
80
- "\n",
81
- "def check_made_move(msg):\n",
82
- " global made_move\n",
83
- " if made_move:\n",
84
- " made_move = False\n",
85
- " return True\n",
86
- " else:\n",
87
- " return False"
88
- ],
89
- "metadata": {
90
- "id": "a4dIJbL3MuIJ"
91
- },
92
- "execution_count": null,
93
- "outputs": []
94
- },
95
- {
96
- "cell_type": "code",
97
- "source": [
98
- " llm_config = {\"model\": llm}\n",
99
- "\n",
100
- " board_proxy = ConversableAgent(\n",
101
- " name=\"Board Proxy\",\n",
102
- " llm_config=False,\n",
103
- " is_termination_msg=check_made_move,\n",
104
- " default_auto_reply=\"Please make a move.\",\n",
105
- " human_input_mode=\"NEVER\",\n",
106
- " )\n",
107
- "\n",
108
- " player_white = ConversableAgent(\n",
109
- " name=\"Player White\",\n",
110
- " system_message=\"You are a chess player and you play as white. \"\n",
111
- " \"First call get_legal_moves(), to get a list of legal moves. \"\n",
112
- " \"Then call make_move(move) to make a move. \"\n",
113
- " \"After a move is made, chitchat to make the game fun.\",\n",
114
- " llm_config=llm_config,\n",
115
- " )\n",
116
- "\n",
117
- " player_black = ConversableAgent(\n",
118
- " name=\"Player Black\",\n",
119
- " system_message=\"You are a chess player and you play as black. \"\n",
120
- " \"First call get_legal_moves(), to get a list of legal moves. \"\n",
121
- " \"Then call make_move(move) to make a move. \"\n",
122
- " \"After a move is made, chitchat to make the game fun.\",\n",
123
- " llm_config=llm_config,\n",
124
- " )\n",
125
- "\n",
126
- " for caller in [player_white, player_black]:\n",
127
- " register_function(\n",
128
- " get_legal_moves,\n",
129
- " caller=caller,\n",
130
- " executor=board_proxy,\n",
131
- " name=\"get_legal_moves\",\n",
132
- " description=\"Get legal moves.\",\n",
133
- " )\n",
134
- "\n",
135
- " register_function(\n",
136
- " make_move,\n",
137
- " caller=caller,\n",
138
- " executor=board_proxy,\n",
139
- " name=\"make_move\",\n",
140
- " description=\"Call this tool to make a move.\",\n",
141
- " )\n",
142
- "\n",
143
- " player_white.register_nested_chats(\n",
144
- " trigger=player_black,\n",
145
- " chat_queue=[\n",
146
- " {\n",
147
- " \"sender\": board_proxy,\n",
148
- " \"recipient\": player_white,\n",
149
- " \"summary_method\": \"last_msg\",\n",
150
- " \"silent\": True,\n",
151
- " }\n",
152
- " ],\n",
153
- " )\n",
154
- "\n",
155
- " player_black.register_nested_chats(\n",
156
- " trigger=player_white,\n",
157
- " chat_queue=[\n",
158
- " {\n",
159
- " \"sender\": board_proxy,\n",
160
- " \"recipient\": player_black,\n",
161
- " \"summary_method\": \"last_msg\",\n",
162
- " \"silent\": True,\n",
163
- " }\n",
164
- " ],\n",
165
- " )\n",
166
- "\n",
167
- " #player_black.llm_config[\"tools\"]\n",
168
- "\n",
169
- " chat_result = player_black.initiate_chat(\n",
170
- " player_white,\n",
171
- " message=\"Let's play chess! Your move.\",\n",
172
- " max_turns=2,\n",
173
- " verbose=True\n",
174
- " )"
175
- ],
176
- "metadata": {
177
- "id": "jOYDXwx4M0sI"
178
- },
179
- "execution_count": null,
180
- "outputs": []
181
- },
182
- {
183
- "cell_type": "code",
184
- "source": [
185
- "print(chat)"
186
- ],
187
- "metadata": {
188
- "id": "sEtS9vaAM62l"
189
- },
190
- "execution_count": null,
191
- "outputs": []
192
- }
193
- ]
194
- }