Skip to content

core / state / types

core.state.types

AgentProperties

Source code in core\state\types.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class AgentProperties:
    def __init__(self, current_task_id: str, action_count: int, current_step_index: int = 0):
        self.current_task_id = current_task_id
        self.current_step_index: int = current_step_index
        self.action_count: int = action_count
        self.max_actions_per_task: int = MAX_ACTIONS_PER_TASK        
        self.token_count: int = 0
        self.max_tokens_per_task: int = MAX_TOKEN_PER_TASK        

        # Validate config value
        if self.max_actions_per_task < 5:
            logger.warning(f"[MAX ACTIONS] The maximum actions per task is set to {self.max_actions_per_task}, which is lesser than the minimum. Resetting maximum actions per task to 5")
            self.max_actions_per_task = 5

        if self.max_tokens_per_task < 100000:
            logger.warning(f"[MAX TOKENS] The maximum tokens per task is set to {self.max_tokens_per_task}, which is lesser than the minimum. Resetting maximum tokens per task to 100,000")
            self.max_tokens_per_task = 100000


    # ───────────────
    # Public API
    # ───────────────

    def set_property(self, key: str, value: Any) -> None:
        """Public: set or override an agent property"""
        setattr(self, key, value)

    def get_property(self, key: str, default: Any = None) -> Any:
        """Public: safely read a property"""
        return getattr(self, key, default)

    def to_dict(self) -> Dict[str, Any]:
        """Public: external-safe snapshot of agent state"""
        return self._to_dict()

    # ───────────────
    # Internal helpers
    # ───────────────

    def _to_dict(self) -> Dict[str, Any]:
        """Internal: canonical source of agent state"""
        return {
            "current_task_id": self.current_task_id,
            "current_step_index": self.current_step_index,
            "action_count": self.action_count,
            "max_actions_per_task": self.max_actions_per_task,
            "token_count": self.token_count,
            "max_tokens_per_task": self.max_tokens_per_task,
        }

set_property(key, value)

Public: set or override an agent property

Source code in core\state\types.py
28
29
30
def set_property(self, key: str, value: Any) -> None:
    """Public: set or override an agent property"""
    setattr(self, key, value)

get_property(key, default=None)

Public: safely read a property

Source code in core\state\types.py
32
33
34
def get_property(self, key: str, default: Any = None) -> Any:
    """Public: safely read a property"""
    return getattr(self, key, default)

to_dict()

Public: external-safe snapshot of agent state

Source code in core\state\types.py
36
37
38
def to_dict(self) -> Dict[str, Any]:
    """Public: external-safe snapshot of agent state"""
    return self._to_dict()