autogen.agentchat.group.context_variables.ContextVariables
ContextVariables
Stores and manages context variables for agentic workflows.
Utilises a dictionary-like interface for setting, getting, and removing variables.
Initialize with data dictionary as an optional positional parameter.
Name | Description |
---|---|
data | Type: dict[str, typing.Any] | None Default: None |
**kwargs | Type: Any |
Class Attributes
data
model_config
Static Methods
from_dict
Create a new ContextVariables instance from a dictionary.
E.g.:
my_context = {“user_id”: “12345”, “settings”: {“theme”: “dark”}}
context = ContextVariables.from_dict(my_context)
Name | Description |
---|---|
data | Dictionary of key-value pairs Type: dict[str, typing.Any] |
Type | Description |
---|---|
ContextVariables | New ContextVariables instance |
Instance Methods
clear
Clear all keys and values from the context.
contains
Check if a key exists in the context.
Name | Description |
---|---|
key | The key to check Type: str |
Type | Description |
---|---|
bool | True if the key exists, False otherwise |
get
Get a value from the context by key.
Name | Description |
---|---|
key | The key to retrieve Type: str |
default | The default value to return if key is not found Type: Any | None Default: None |
Type | Description |
---|---|
Any | None | The value associated with the key or default if not found |
items
Get all key-value pairs in the context.
Returns:
An iterable of all key-value pairs
Type | Description |
---|---|
Iterable[tuple[str, Any]] | An iterable of all key-value pairs |
keys
Get all keys in the context.
Returns:
An iterable of all keys
Type | Description |
---|---|
Iterable[str] | An iterable of all keys |
remove
Remove a key from the context.
Name | Description |
---|---|
key | The key to remove Type: str |
Type | Description |
---|---|
bool | True if the key was removed, False if it didn’t exist |
set
Set a value in the context by key.
Name | Description |
---|---|
key | The key to set Type: str |
value | The value to store Type: Any |
to_dict
Convert context variables to a dictionary.
Returns:
Dictionary representation of all context variables
Type | Description |
---|---|
dict[str, typing.Any] | Dictionary representation of all context variables |
update
Update context with key-value pairs from another dictionary.
Name | Description |
---|---|
other | Dictionary containing key-value pairs to add Type: dict[str, typing.Any] |
values
Get all values in the context.
Returns:
An iterable of all values
Type | Description |
---|---|
Iterable[Any] | An iterable of all values |