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

add new class UpdateCondition to load context variables in OnCondition.condition #349

Merged
merged 6 commits into from
Jan 6, 2025

Conversation

linmou
Copy link
Collaborator

@linmou linmou commented Jan 4, 2025

Why are these changes needed?

This PR solved the feature request in Issue #348 . About a more flexible way to customize the OnCondition.condition string.

The branch is built upon PR #316 I build a new UpdateCondition class, very similar to UpdateSystemMessage. So that OnCondition.condition can be a callable or string format which can load context variables.
And the logic for _update_conditional_functions is changed a little bit to ensure the registered functions are updated.

Related issue number

issue #348

Checks

@linmou linmou requested a review from marklysze January 4, 2025 04:48
@Hk669 Hk669 requested review from qingyun-wu and yiranwu0 January 4, 2025 16:38
@Hk669 Hk669 added the swarm label Jan 4, 2025
@linmou linmou changed the title add new class UpdateCondition, unit test passed. add new class UpdateCondition to load context variables in OnCondition.condition Jan 4, 2025
@marklysze marklysze added the enhancement New feature or request label Jan 6, 2025
@marklysze
Copy link
Collaborator

Thanks @linmou, looks good, I'll give it a test :)

@marklysze
Copy link
Collaborator

Thanks @linmou, I've tested it and it works as expected, injecting the context variable into the condition. The LLM avoided calling the hand off function when the condition in the string was false.

My sample hand-off for testing:

register_hand_off(
    order_triage_agent,
    [
        OnCondition(
            target=authentication_agent,
            condition="The customer is not logged in, authenticate the customer.",
            available="requires_login",
        ),
        OnCondition(
            target=order_mgmt_agent,
            condition=UpdateCondition("The customer is logged in, continue with the order triage if {customer_tier} == 2."),
            available="logged_in",
        ),
        AfterWork(AfterWorkOption.REVERT_TO_USER),
    ],
)

Thanks for using the swarm to conversable agent branch to make the change and for following the UpdateSystemMessage convention.

@marklysze
Copy link
Collaborator

marklysze commented Jan 6, 2025

@linmou, could you add to the documentation in 'swarm.ipynb' under:
'/website/docs/topics/'

@linmou
Copy link
Collaborator Author

linmou commented Jan 6, 2025

@marklysze Thanks for your review and test, also thanks for your implementation of UpdateSystemMessage which inspires me a lot. I have add the document, please check and add your review.

Copy link
Collaborator

@marklysze marklysze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @linmou, looks good!

@marklysze marklysze merged commit 5ad455a into swarmagenttoconversable Jan 6, 2025
7 checks passed
@sonichi sonichi deleted the swarmOnConditionWithContextV branch January 7, 2025 20:52
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.

3 participants