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

[Feature Request]: enable OnCondition string to load context variables #348

Closed
linmou opened this issue Jan 3, 2025 · 2 comments
Closed
Labels
enhancement New feature or request swarm

Comments

@linmou
Copy link
Collaborator

linmou commented Jan 3, 2025

Is your feature request related to a problem? Please describe.

Current OnCondition string is just a plain text describing the condition when the handoff function to be chose.
However, such an implementation can not solve some complex logic like " transfer to Agent B when context_variables['situation'] == 'B' "

So, I would like to build a new interface for OnCondition string which can load context_variables.

Describe the solution you'd like

So, I would like to build a new interface for OnCondition string which can load context_variables.
current class UPDATE_SYSTEM_MESSAGE has implemented context_variable loading in a string. We can build a similar class (like UPDATE_ONCONDITION) or a more general class.
The final interface for OnCondition may look like:

agentA.register_hand_off(ON_CONDITION( agentB, UPDATE_ONCONDITION('Transfer to Agent B when {key} is B '), available))

Additional context

Compare with ON_CONDITION.available:

ON_CONDITION.available can also load a callable function to check the value of context variables, but it is the prerequisite for condition string, which means it is an 'and' logic between available and OnCondition string.
While an OnCondition string can enable more versatile logic between context variables and text-described situation, e.g.

ON_CONDITION(agentC, 
            UPDATE_ONCONDITION("transfer to AgentC when user is frustrated or {situation} == 'B' or {situation} == 'C' "),  
            'user_login')
@marklysze
Copy link
Collaborator

marklysze commented Jan 6, 2025

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.

@sonichi, are you able to provide your feedback on this change in PR #349

@marklysze
Copy link
Collaborator

Thanks @linmou, #349 merged, closing :)

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

No branches or pull requests

2 participants