Source code for council.contexts._execution_log

import json
from typing import Any, Dict

from ._execution_log_entry import ExecutionLogEntry


[docs] class ExecutionLog: """ represents the log of execution for each executable items (i.e. :class:`~council.agents.Agent`, :class:`~council.chains.Chain`, :class:`~council.skills.SkillBase` ...) """ def __init__(self): self._entries = []
[docs] def new_entry(self, name: str) -> ExecutionLogEntry: """ adds a new entry into the log Args: name: name of the new entry Returns: the newly added entry """ result = ExecutionLogEntry(name) self._entries.append(result) return result
[docs] def to_json(self) -> str: """ serialize the execution log as a `json` string Returns: a `json` string """ return json.dumps(self.to_dict(), indent=2)
[docs] def to_dict(self) -> Dict[str, Any]: """ convert into a dictionary """ result = {"entries": [item.to_dict() for item in self._entries]} return result