agentsociety.agent.context

Module Contents

Classes

AgentContext

Agent Context

BlockContext

Block Context

DotDict

A dictionary that supports dot notation access to its items.

Functions

context_to_dot_dict

Converts an AgentContext to a DotDict for dot notation access.

auto_deepcopy_dotdict

Decorator that automatically deep copies DotDict arguments.

apply_auto_deepcopy_to_module

Applies the auto_deepcopy_dotdict decorator to all functions in a module.

API

class agentsociety.agent.context.AgentContext

Bases: pydantic.BaseModel

Agent Context

class agentsociety.agent.context.BlockContext

Bases: pydantic.BaseModel

Block Context

class agentsociety.agent.context.DotDict(*args, **kwargs)

Bases: dict

A dictionary that supports dot notation access to its items.

  • Description:

    • Extends the standard dictionary to allow attribute-style access

    • Example: d = DotDict({‘foo’: ‘bar’}); d.foo == ‘bar’

    • Supports merging with other DotDict instances

    • Maintains reference to original dictionaries when merged

  • Args:

    • Same as dict constructor

  • Returns:

    • A dictionary with attribute-style access

Initialization

Initialize self. See help(type(self)) for accurate signature.

__getattr__(key)
__setattr__(key, value)
__delattr__(key)
merge(other)

Merges another DotDict into this one.

  • Description:

    • Merges another DotDict into this one

    • Maintains references to original dictionaries

    • Updates are synchronized with original dictionaries

  • Args:

    • other (DotDict): The DotDict to merge with

  • Returns:

    • self (DotDict): The merged DotDict

__or__(other)

Implements the | operator for merging DotDicts.

  • Description:

    • Allows using the | operator to merge DotDicts

    • Example: c = a | b

  • Args:

    • other (DotDict): The DotDict to merge with

  • Returns:

    • DotDict: A new merged DotDict

__ior__(other)

Implements the |= operator for in-place merging.

  • Description:

    • Allows using the |= operator for in-place merging

    • Example: a |= b

  • Args:

    • other (DotDict): The DotDict to merge with

  • Returns:

    • self (DotDict): The updated DotDict

agentsociety.agent.context.context_to_dot_dict(context: Union[agentsociety.agent.context.AgentContext, agentsociety.agent.context.BlockContext]) agentsociety.agent.context.DotDict

Converts an AgentContext to a DotDict for dot notation access.

  • Description:

    • Converts a Pydantic AgentContext model to a dictionary with dot notation access

    • Preserves nested structure while enabling attribute-style access

  • Args:

    • context (AgentContext): The AgentContext to convert

  • Returns:

    • dot_dict (DotDict): A dictionary that supports attribute-style access

agentsociety.agent.context.auto_deepcopy_dotdict(func)

Decorator that automatically deep copies DotDict arguments.

  • Description:

    • Wraps a function to automatically deep copy any DotDict arguments

    • Prevents modifications to DotDict arguments from affecting the original

  • Args:

    • func (callable): The function to decorate

  • Returns:

    • wrapper (callable): The decorated function

agentsociety.agent.context.apply_auto_deepcopy_to_module(module)

Applies the auto_deepcopy_dotdict decorator to all functions in a module.

  • Description:

    • Scans a module for functions and applies the decorator to each

    • Makes all functions in the module automatically deep copy DotDict arguments

  • Args:

    • module (module): The module to process

  • Returns:

    • None