ContextVariables

ContextVariables(data: dict[str, Any] | None = None, **kwargs: Any)

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.

Parameters:
NameDescription
dataType: dict[str, typing.Any] | None

Default: None
**kwargsType: Any

Class Attributes

data



model_config



Static Methods

from_dict

from_dict(data: dict[str, Any]) -> ContextVariables

Create a new ContextVariables instance from a dictionary.
E.g.:
my_context = {“user_id”: “12345”, “settings”: {“theme”: “dark”}} context = ContextVariables.from_dict(my_context)

Parameters:
NameDescription
dataDictionary of key-value pairs

Type: dict[str, typing.Any]
Returns:
TypeDescription
ContextVariablesNew ContextVariables instance

Instance Methods

clear

clear(self) -> None

Clear all keys and values from the context.


contains

contains(self, key: str) -> bool

Check if a key exists in the context.

Parameters:
NameDescription
keyThe key to check

Type: str
Returns:
TypeDescription
boolTrue if the key exists, False otherwise

get

get(
    self,
    key: str,
    default: Any | None = None
) -> Any | None

Get a value from the context by key.

Parameters:
NameDescription
keyThe key to retrieve

Type: str
defaultThe default value to return if key is not found

Type: Any | None

Default: None
Returns:
TypeDescription
Any | NoneThe value associated with the key or default if not found

items

items(self) -> Iterable[tuple[str, Any]]

Get all key-value pairs in the context.
Returns:
An iterable of all key-value pairs

Returns:
TypeDescription
Iterable[tuple[str, Any]]An iterable of all key-value pairs

keys

keys(self) -> Iterable[str]

Get all keys in the context.
Returns:
An iterable of all keys

Returns:
TypeDescription
Iterable[str]An iterable of all keys

remove

remove(self, key: str) -> bool

Remove a key from the context.

Parameters:
NameDescription
keyThe key to remove

Type: str
Returns:
TypeDescription
boolTrue if the key was removed, False if it didn’t exist

set

set(
    self,
    key: str,
    value: Any
) -> None

Set a value in the context by key.

Parameters:
NameDescription
keyThe key to set

Type: str
valueThe value to store

Type: Any

to_dict

to_dict(self) -> dict[str, Any]

Convert context variables to a dictionary.
Returns:
Dictionary representation of all context variables

Returns:
TypeDescription
dict[str, typing.Any]Dictionary representation of all context variables

update

update(self, other: dict[str, Any]) -> None

Update context with key-value pairs from another dictionary.

Parameters:
NameDescription
otherDictionary containing key-value pairs to add

Type: dict[str, typing.Any]

values

values(self) -> Iterable[Any]

Get all values in the context.
Returns:
An iterable of all values

Returns:
TypeDescription
Iterable[Any]An iterable of all values