|
63 | 63 | from autonomy.deploy.generators.kubernetes.base import KubernetesGenerator |
64 | 64 | from docker import from_env |
65 | 65 |
|
66 | | -from operate.constants import CONFIG_JSON, DEPLOYMENT_DIR, DEPLOYMENT_JSON |
| 66 | +from operate.constants import ( |
| 67 | + AGENT_PERSISTENT_STORAGE_ENV_VAR, |
| 68 | + CONFIG_JSON, |
| 69 | + DEPLOYMENT_DIR, |
| 70 | + DEPLOYMENT_JSON, |
| 71 | +) |
67 | 72 | from operate.keys import KeysManager |
68 | 73 | from operate.operate_http.exceptions import NotAllowed |
69 | 74 | from operate.operate_types import ( |
@@ -927,6 +932,40 @@ def remove_latest_healthcheck(self) -> None: |
927 | 932 | except Exception as e: # pylint: disable=broad-except |
928 | 933 | print(f"Exception deleting {healthcheck_json_path}: {e}") |
929 | 934 |
|
| 935 | + def get_agent_performance(self) -> t.Dict: |
| 936 | + """Return the agent activity""" |
| 937 | + |
| 938 | + # Default values |
| 939 | + agent_performance: t.Dict[str, t.Any] = { |
| 940 | + "timestamp": None, |
| 941 | + "metrics": [], |
| 942 | + "last_activity": None, |
| 943 | + "last_chat_message": None, |
| 944 | + } |
| 945 | + |
| 946 | + agent_performance_json_path = ( |
| 947 | + Path( |
| 948 | + self.env_variables.get( |
| 949 | + AGENT_PERSISTENT_STORAGE_ENV_VAR, {"value": "."} |
| 950 | + ).get("value", ".") |
| 951 | + ) |
| 952 | + / "agent_performance.json" |
| 953 | + ) |
| 954 | + |
| 955 | + if agent_performance_json_path.exists(): |
| 956 | + try: |
| 957 | + with open(agent_performance_json_path, "r", encoding="utf-8") as f: |
| 958 | + data = json.load(f) |
| 959 | + if isinstance(data, dict): |
| 960 | + agent_performance.update(data) |
| 961 | + except (json.JSONDecodeError, OSError) as e: |
| 962 | + # Keep default values if file is invalid |
| 963 | + print( |
| 964 | + f"Error reading file 'agent_performance.json': {e}" |
| 965 | + ) # TODO Use logger |
| 966 | + |
| 967 | + return dict(sorted(agent_performance.items())) |
| 968 | + |
930 | 969 | def update( |
931 | 970 | self, |
932 | 971 | service_template: ServiceTemplate, |
|
0 commit comments