Skip to content

Commit

Permalink
Updated parameter name to update_agent_state_before_reply
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sze <[email protected]>
  • Loading branch information
marklysze committed Dec 15, 2024
1 parent 58ba2ad commit 2c3e063
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions autogen/agentchat/contrib/swarm_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def __init__(
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "NEVER",
description: Optional[str] = None,
code_execution_config=False,
update_agent_before_reply: Optional[
update_agent_state_before_reply: Optional[
Union[List[Union[Callable, UPDATE_SYSTEM_MESSAGE]], Callable, UPDATE_SYSTEM_MESSAGE]
] = None,
**kwargs,
Expand Down Expand Up @@ -385,9 +385,9 @@ def __init__(
# List of Dictionaries containing the nested_chats and condition
self._nested_chat_handoffs = []

self.register_update_agent_before_reply(update_agent_before_reply)
self.register_update_agent_state_before_reply(update_agent_state_before_reply)

def register_update_agent_before_reply(self, functions: Optional[Union[List[Callable], Callable]]):
def register_update_agent_state_before_reply(self, functions: Optional[Union[List[Callable], Callable]]):
"""
Register functions that will be called when the agent is selected and before it speaks.
You can add your own validation or precondition functions here.
Expand Down
6 changes: 3 additions & 3 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,7 @@ def generate_reply(
messages = self._oai_messages[sender]

# Call the hookable method that gives registered hooks a chance to update agent state, used for their context variables.
self.process_update_agent_states(messages)
self.update_agent_state_before_reply(messages)

# Call the hookable method that gives registered hooks a chance to process the last message.
# Message modifications do not affect the incoming messages or self._oai_messages.
Expand Down Expand Up @@ -2166,7 +2166,7 @@ async def a_generate_reply(
messages = self._oai_messages[sender]

# Call the hookable method that gives registered hooks a chance to update agent state, used for their context variables.
self.process_update_agent_states(messages)
self.update_agent_state_before_reply(messages)

# Call the hookable method that gives registered hooks a chance to process all messages.
# Message modifications do not affect the incoming messages or self._oai_messages.
Expand Down Expand Up @@ -2854,7 +2854,7 @@ def register_hook(self, hookable_method: str, hook: Callable):
assert hook not in hook_list, f"{hook} is already registered as a hook."
hook_list.append(hook)

def process_update_agent_states(self, messages: List[Dict]) -> None:
def update_agent_state_before_reply(self, messages: List[Dict]) -> None:
"""
Calls any registered capability hooks to update the agent's state.
Primarily used to update context variables.
Expand Down
8 changes: 4 additions & 4 deletions website/docs/topics/swarm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@
"source": [
"### Update Agent state before replying\n",
"\n",
"It can be useful to update an agent's state before they reply, particularly their system message/prompt.\n",
"It can be useful to update a swarm agent's state before they reply. For example, using an agent's context variables you could change their system message based on the state of the workflow.\n",
"\n",
"When initialising an agent you can use the `update_agent_before_reply` to register the updates run when the agent is selected, but before they reply.\n",
"When initialising a swarm agent use the `update_agent_state_before_reply` parameter to register updates that run after the agent is selected, but before they reply.\n",
"\n",
"The `update_agent_before_reply` takes a list of any combination of the following (executing them in the provided order):\n",
"`update_agent_state_before_reply` takes a list of any combination of the following (executing them in the provided order):\n",
"\n",
"- `UPDATE_SYSTEM_MESSAGE` provides a simple way to update the agent's system message via an f-string that substitutes the values of context variables, or a Callable that returns a string\n",
"- Callable with two parameters of type `ConversableAgent` for the agent and `List[Dict[str Any]]` for the messages, and does not return a value\n",
Expand All @@ -198,7 +198,7 @@
"customer_service = SwarmAgent(\n",
" name=\"CustomerServiceRep\",\n",
" system_message=\"You are a customer service representative.\",\n",
" update_agent_before_reply=[\n",
" update_agent_state_before_reply=[\n",
" UPDATE_SYSTEM_MESSAGE(\"You are a customer service representative. Quote passport number '{passport_number}'\"),\n",
" UPDATE_SYSTEM_MESSAGE(create_system_prompt_function),\n",
" my_callable_state_update_function]\n",
Expand Down

0 comments on commit 2c3e063

Please sign in to comment.