Spaces:
Runtime error
Runtime error
| from __future__ import annotations | |
| from typing import TYPE_CHECKING | |
| if TYPE_CHECKING: | |
| from ..environment.environment import Environment | |
| class ActivateAbilityTool: | |
| name = "activate_ability" | |
| schema = { | |
| "type": "function", | |
| "function": { | |
| "name": "activate_ability", | |
| "description": "Activate one of your acquired abilities. Each ability has different effects and args.", | |
| "parameters": { | |
| "type": "object", | |
| "properties": { | |
| "ability": { | |
| "type": "string", | |
| "description": "Name of the ability to activate", | |
| }, | |
| "args": { | |
| "type": "object", | |
| "description": "Arguments for the ability (varies per ability)", | |
| }, | |
| }, | |
| "required": ["ability", "args"], | |
| }, | |
| }, | |
| } | |
| def run(env: Environment, aid: str, args: dict) -> str: | |
| ability_name = args.get("ability", "") | |
| ability_args = args.get("args", {}) | |
| agent = env.agents[aid] | |
| ability = agent.get_ability(ability_name) | |
| if not ability: | |
| return f"You don't have the ability '{ability_name}'" | |
| if not ability.can_use(env.turn): | |
| return f"Ability '{ability_name}' cannot be used right now (cooldown or no uses left)" | |
| from ..environment.ability_registry import ABILITY_REGISTRY | |
| ability_def = ABILITY_REGISTRY.get(ability_name) | |
| if not ability_def: | |
| return f"Unknown ability: {ability_name}" | |
| result = ability_def.handler(env, aid, ability_args) | |
| ability.use(env.turn) | |
| return result | |