Skip to content
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: User-defined AfterWork string for agent selection using LLM #368

Closed
wants to merge 31 commits into from

Conversation

marklysze
Copy link
Collaborator

@marklysze marklysze commented Jan 7, 2025

Closing, will base on 'swarmagenttoconversable' branch.

Why are these changes needed?

In line with #26, this provides the developer with an option to specify a string prompt for an LLM to use to select the next agent in an agent's AfterWork hand off.

It extends the AfterWorkOption.SWARM_MANAGER (which, by default, uses the default auto speaker selection options) with an additional AfterWork parameter, next_agent_selection_msg, which becomes the selection prompt used by the LLM.

next_agent_selection_msg can be a string or a Callable that returns a string.

The signature for the Callable is:
def my_selection_message(agent: ConversableAgent, messages: List[Dict[str, Any]]) -> str

The string provided, or returned from the Callable, will have the following string substitutions:

  • {agentlist} will be replaced by a comma-delimited list of agents
  • context variable keys will be replaced by their values

The underlying groupchat's GroupChatManager will be used for the speaker selection and must, therefore, have an LLM Config. This can be set through the new swarm_manager_args parameter on a/initiate_swarm_chat.

Example:

context_variables = {
    "order_id": "ABC1234"
}

register_handoff(
    from=planner,
    hand_to=[
        AfterWork(agent=AfterWorkOption.SWARM_MANAGER, next_agent_selection_msg="Select the next agent from this list {agentlist}. From the list please select the order_mgmt_agent. Order Id is {order_id}"),
    ]
)

_, _, _ = initiate_swarm_chat(
    ...,
    swarm_manager_args={"llm_config": llm_config}
)

Related issue number

#26

Checks

marklysze and others added 30 commits December 30, 2024 03:54
Signed-off-by: Mark Sze <[email protected]>
Signed-off-by: Mark Sze <[email protected]>
add new class UpdateCondition to load context variables in  OnCondition.condition
Signed-off-by: Mark Sze <[email protected]>
Signed-off-by: Mark Sze <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request swarm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants