added new summary feature
This commit is contained in:
parent
2ebc3f8d9e
commit
56081c673f
2 changed files with 17 additions and 12 deletions
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
This is a simple Chess game that uses an AI agents - Player black and player white to play the game. There's also a board proxy agent to execute the tools and manage the game. It is important to use a board proxy as a non-LLM "guard rail" to ensure the game is played correctly and to prevent agents from making illegal moves.
|
This is a simple Chess game that uses an AI agents - Player black and player white to play the game. There's also a board proxy agent to execute the tools and manage the game. It is important to use a board proxy as a non-LLM "guard rail" to ensure the game is played correctly and to prevent agents from making illegal moves.
|
||||||
|
|
||||||
|
Two agents (player_white and player_black) are initialized using the OpenAI API key. These agents are configured to play chess as white and black, respectively.
|
||||||
|
A board_proxy agent is created to manage the board state and validate moves.
|
||||||
|
Functions (make_move and available_moves) are registered with the agents to allow them to interact with the board.
|
||||||
|
|
||||||
|
|
||||||
### How to get Started?
|
### How to get Started?
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ if openai_api_key:
|
||||||
st.sidebar.success("API key saved!")
|
st.sidebar.success("API key saved!")
|
||||||
|
|
||||||
# Function to get legal moves
|
# Function to get legal moves
|
||||||
def get_legal_moves() -> Annotated[str, "A list of legal moves in UCI format"]:
|
def available_moves() -> Annotated[str, "A list of available legal moves in the UCI format"]:
|
||||||
legal_moves = [str(move) for move in st.session_state.board.legal_moves]
|
available_moves = [str(move) for move in st.session_state.board.legal_moves]
|
||||||
return "Possible moves are: " + ",".join(legal_moves)
|
return "Available moves are: " + ",".join(available_moves)
|
||||||
|
|
||||||
# Function to make a move
|
# Function to make a move
|
||||||
def make_move(move: Annotated[str, "A move in UCI format."]) -> Annotated[str, "Result of the move."]:
|
def make_move(move: Annotated[str, "A move in UCI format."]) -> Annotated[str, "Result of the move."]:
|
||||||
|
|
@ -83,14 +83,14 @@ def check_made_move(msg):
|
||||||
if st.session_state.openai_api_key:
|
if st.session_state.openai_api_key:
|
||||||
player_white_config_list = [
|
player_white_config_list = [
|
||||||
{
|
{
|
||||||
"model": "gpt-4-turbo-preview",
|
"model": "gpt-4o-mini",
|
||||||
"api_key": st.session_state.openai_api_key,
|
"api_key": st.session_state.openai_api_key,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
player_black_config_list = [
|
player_black_config_list = [
|
||||||
{
|
{
|
||||||
"model": "gpt-4-turbo-preview",
|
"model": "gpt-4o-mini",
|
||||||
"api_key": st.session_state.openai_api_key,
|
"api_key": st.session_state.openai_api_key,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
@ -130,10 +130,10 @@ if st.session_state.openai_api_key:
|
||||||
)
|
)
|
||||||
|
|
||||||
register_function(
|
register_function(
|
||||||
get_legal_moves,
|
available_moves,
|
||||||
caller=player_white,
|
caller=player_white,
|
||||||
executor=board_proxy,
|
executor=board_proxy,
|
||||||
name="get_legal_moves",
|
name="available_moves",
|
||||||
description="Get legal moves.",
|
description="Get legal moves.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -146,10 +146,10 @@ if st.session_state.openai_api_key:
|
||||||
)
|
)
|
||||||
|
|
||||||
register_function(
|
register_function(
|
||||||
get_legal_moves,
|
available_moves,
|
||||||
caller=player_black,
|
caller=player_black,
|
||||||
executor=board_proxy,
|
executor=board_proxy,
|
||||||
name="get_legal_moves",
|
name="available_moves",
|
||||||
description="Get legal moves.",
|
description="Get legal moves.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -192,11 +192,12 @@ if st.session_state.openai_api_key:
|
||||||
|
|
||||||
# Initiate the chat between Player_White and Board_Proxy
|
# Initiate the chat between Player_White and Board_Proxy
|
||||||
chat_result = player_black.initiate_chat(
|
chat_result = player_black.initiate_chat(
|
||||||
player_white,
|
recipient=player_white,
|
||||||
message="Let's play chess! You go first, its your move.",
|
message="Let's play chess! You go first, its your move.",
|
||||||
max_turns=5, # Set a high enough number to allow the game to complete
|
max_turns=5,
|
||||||
|
summary_method="reflection_with_llm" # Set a high enough number to allow the game to complete
|
||||||
)
|
)
|
||||||
st.markdown(chat_result.chat_history)
|
st.markdown(chat_result.summary)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
st.warning("Please enter your OpenAI API key in the sidebar to start the game.")
|
st.warning("Please enter your OpenAI API key in the sidebar to start the game.")
|
||||||
Loading…
Reference in a new issue