Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,17 +7,45 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
| 10 |
@tool
|
| 11 |
+
def game_memory_tool(
|
| 12 |
+
game: str,
|
| 13 |
+
event_type: Literal["observation", "decision", "battle", "quest", "inventory", "strategy"],
|
| 14 |
+
content: str,
|
| 15 |
+
importance: int
|
| 16 |
+
) -> str:
|
| 17 |
+
"""
|
| 18 |
+
A tool that stores important game memories for an autonomous game-playing agent.
|
| 19 |
+
|
| 20 |
Args:
|
| 21 |
+
game: The name of the game the agent is playing, e.g. "Pokemon Emerald".
|
| 22 |
+
event_type: The type of memory being saved. Options: observation, decision, battle, quest, inventory, strategy.
|
| 23 |
+
content: A clear description of what happened or what the agent decided.
|
| 24 |
+
importance: A number from 1 to 10 showing how important this memory is.
|
| 25 |
"""
|
| 26 |
+
try:
|
| 27 |
+
if importance < 1 or importance > 10:
|
| 28 |
+
return "Error: importance must be between 1 and 10."
|
| 29 |
+
|
| 30 |
+
memory = {
|
| 31 |
+
"game": game,
|
| 32 |
+
"event_type": event_type,
|
| 33 |
+
"content": content,
|
| 34 |
+
"importance": importance,
|
| 35 |
+
"timestamp": datetime.datetime.now().isoformat()
|
| 36 |
+
}
|
| 37 |
|
| 38 |
+
with open("game_agent_memory.jsonl", "a", encoding="utf-8") as file:
|
| 39 |
+
file.write(json.dumps(memory, ensure_ascii=False) + "\n")
|
| 40 |
+
|
| 41 |
+
return (
|
| 42 |
+
f"Memory saved for {game}. "
|
| 43 |
+
f"Type: {event_type}. "
|
| 44 |
+
f"Importance: {importance}/10."
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
except Exception as e:
|
| 48 |
+
return f"Error saving game memory: {str(e)}"
|
| 49 |
@tool
|
| 50 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 51 |
"""A tool that fetches the current local time in a specified timezone.
|