-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swarm: Allow functions to update agent's state, including system message, before replying #104
Conversation
…n selected Signed-off-by: Mark Sze <mark@sze.family>
Signed-off-by: Mark Sze <mark@sze.family>
Thanks your implement about SwarmAgent.update_state! It also matches my thoughts. How about building a more general interface like register_update_function ? So that users can register their own functions to modify other attributes besides sys_msg. In this version we can simply add a new key in hook_lists. |
I have added a new commit 22189f1 as a demo for you to discuss. In this implementation, I created a new hook update_states_once_selected to let users pass in a function to update the agent state. |
Signed-off-by: Mark Sze <mark@sze.family>
Signed-off-by: Mark Sze <mark@sze.family>
Signed-off-by: Mark Sze <mark@sze.family>
Signed-off-by: Mark Sze <mark@sze.family>
All tests passed except Dall-e 3 image generation, unrelated to the changes. Will merge and address that test separately. Thanks all! |
Why are these changes needed?
To provide more control over the SwarmAgent's state, just before they reply, this PR provides the ability to define functions to update state when they are selected in the swarm.
A list of functions can be set when creating an agent through the
update_agent_state_before_reply
parameter. These will be executed once selected and before creating their reply.UPDATE_SYSTEM_MESSAGE
A special function called
UPDATE_SYSTEM_MESSAGE
can be passed in here and this function allows an easy way to update the agent's system message using a Callable or an f-string. The Callable must return a string. The f-string will automatically merge in context_variable values into the string.IMPORTANT NOTE: context variables have been moved from the SwarmAgent to ConversableAgent (in this PR but it will be done in #137 and aim to merge that before this). The following functions are available on a ConversableAgent to access state:
Note: No additional documentation has been added. Once the code looks good, I'll add to or update existing documentation.
Related issue number
#77
Checks