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 context variables to ConversableAgent #137

Merged
merged 4 commits into from
Dec 4, 2024
Merged

Conversation

marklysze
Copy link
Collaborator

@marklysze marklysze commented Dec 2, 2024

Why are these changes needed?

As a means to support the current SwarmAgent implementation and provide future agent-level context variables, we add context variables to a ConversableAgent. Each agent has their own independent context variables.

This will be a dictionary, Dict[str, Any] and interacting with it should be done through getter/setter functions:

  • my_agent.get_context_value - gets a value based on a key (allowing a default to be used)
  • my_agent.set_context_value - updates a key with a value
  • my_agent.set_context_values - updates with a dictionary
  • my_agent.pop_context_key - removes a key from the context variables

E.g.

my_context = {
    "key_1": value_1,
    "key_2", value_2
}

my_agent = ConversableAgent(..., context_variables=my_context)

my_agent.get_context_value("key_1")
my_agent.set_context_value("key_3", something_here)
my_agent.set_context_values({...})
my_agent.pop_context_key("key_1")

Note: If context variables are passed in when establishing a ConversableAgent it must be able to be deep-copied.

docstring for ConversableAgent has been updated - no other specific documentation has been added. Let me know if it needs it at this stage.

Related issue number

PR #104 is a dependency on this.

Checks

Signed-off-by: Mark Sze <mark@sze.family>
Signed-off-by: Mark Sze <mark@sze.family>
Copy link
Collaborator

@sonichi sonichi left a comment

Choose a reason for hiding this comment

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

LGTM with one optional suggestion.

autogen/agentchat/conversable_agent.py Outdated Show resolved Hide resolved
Signed-off-by: Mark Sze <mark@sze.family>
@marklysze marklysze added this pull request to the merge queue Dec 4, 2024
Merged via the queue into main with commit a6840cf Dec 4, 2024
214 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants