-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvironment.py
More file actions
27 lines (23 loc) · 768 Bytes
/
environment.py
File metadata and controls
27 lines (23 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import time
import traceback
from typing import Any
from actions import Action
class Environment:
def execute_action(self, action: Action, args: dict) -> dict:
"""Execute an action and return the result."""
try:
result = action.execute(**args)
return self.format_result(result)
except Exception as e:
return {
"tool_executed": False,
"error": str(e),
"traceback": traceback.format_exc()
}
def format_result(self, result: Any) -> dict:
"""Format the result with metadata."""
return {
"tool_executed": True,
"result": result,
"timestamp": time.strftime("%Y-%m-%dT%H:%M:%S%z")
}