Update multi_agent.py
Browse files- multi_agent.py +1 -66
multi_agent.py
CHANGED
@@ -1,71 +1,6 @@
|
|
1 |
-
import
|
2 |
-
from autogen import ConversableAgent, register_function
|
3 |
-
from typing_extensions import Annotated
|
4 |
-
|
5 |
-
board = None
|
6 |
-
board_svgs = None
|
7 |
-
made_move = None
|
8 |
-
|
9 |
-
def get_legal_moves() -> Annotated[str, "A list of legal moves in UCI format"]:
|
10 |
-
return "Possible moves are: " + ",".join(
|
11 |
-
[str(move) for move in board.legal_moves]
|
12 |
-
)
|
13 |
-
|
14 |
-
def make_move(move: Annotated[str, "A move in UCI format."]) -> Annotated[str, "Result of the move."]:
|
15 |
-
move = chess.Move.from_uci(move)
|
16 |
-
board.push_uci(str(move))
|
17 |
-
global made_move
|
18 |
-
made_move = True
|
19 |
-
|
20 |
-
board_svgs.append(chess.svg.board(
|
21 |
-
board,
|
22 |
-
arrows=[(move.from_square, move.to_square)],
|
23 |
-
fill={move.from_square: "gray"},
|
24 |
-
size=250
|
25 |
-
))
|
26 |
-
|
27 |
-
piece = board.piece_at(move.to_square)
|
28 |
-
piece_symbol = piece.unicode_symbol()
|
29 |
-
piece_name = (
|
30 |
-
chess.piece_name(piece.piece_type).capitalize()
|
31 |
-
if piece_symbol.isupper()
|
32 |
-
else chess.piece_name(piece.piece_type)
|
33 |
-
)
|
34 |
-
|
35 |
-
return f"Moved {piece_name} ({piece_symbol}) from "\
|
36 |
-
f"{chess.SQUARE_NAMES[move.from_square]} to "\
|
37 |
-
f"{chess.SQUARE_NAMES[move.to_square]}."
|
38 |
-
|
39 |
-
def check_made_move(msg):
|
40 |
-
global made_move
|
41 |
-
|
42 |
-
if made_move:
|
43 |
-
made_move = False
|
44 |
-
return True
|
45 |
-
else:
|
46 |
-
return False
|
47 |
-
|
48 |
-
def get_num_turns(num_moves):
|
49 |
-
# Each turn includes two moves (one by each player)
|
50 |
-
# The first move by player black kicks off the chat
|
51 |
-
# The first move by player white starts the game
|
52 |
-
|
53 |
-
num_turns = math.ceil(num_moves / 2)
|
54 |
-
|
55 |
-
if num_moves % 2 == 0:
|
56 |
-
num_turns += 1
|
57 |
-
|
58 |
-
return num_turns
|
59 |
-
|
60 |
-
def initialize():
|
61 |
-
global board, board_svgs, made_move
|
62 |
-
board = chess.Board()
|
63 |
-
board_svgs = []
|
64 |
-
made_move = False
|
65 |
|
66 |
def run_multi_agent(llm, task):
|
67 |
-
#initialize()
|
68 |
-
|
69 |
llm_config = {"model": llm}
|
70 |
|
71 |
user_proxy = autogen.ConversableAgent(
|
|
|
1 |
+
import autogen
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def run_multi_agent(llm, task):
|
|
|
|
|
4 |
llm_config = {"model": llm}
|
5 |
|
6 |
user_proxy = autogen.ConversableAgent(
|