medali002/AlfredAgent
0
1import yaml2import os3from smolagents import GradioUI, CodeAgent, InferenceClientModel,DuckDuckGoSearchTool, Tool, tool, VisitWebpageTool4from smolagents import FinalAnswerTool as FinalAnswer5 6# Get current directory path7CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))8 9 10model = InferenceClientModel(11model_id='Qwen/Qwen3-Next-80B-A3B-Thinking',12)13 14final_answer = FinalAnswer()15 16 17@tool18def suggest_menu(occasion: str) -> str:19 """20 Suggests a menu based on the occasion.21 Args:22 occasion: The type of occasion for the party.23 """24 if occasion == "casual":25 return "Pizza, snacks, and drinks."26 elif occasion == "formal":27 return "3-course dinner with wine and dessert."28 elif occasion == "superhero":29 return "Buffet with high-energy and healthy food."30 else:31 return "Custom menu for the butler."32 33@tool34def catering_service_tool(query: str) -> str:35 """36 This tool returns the highest-rated catering service in Gotham City.37 38 Args:39 query: A search term for finding catering services.40 """41 # Example list of catering services and their ratings42 services = {43 "Gotham Catering Co.": 4.9,44 "Wayne Manor Catering": 4.8,45 "Gotham City Events": 4.7,46 }47 48 # Find the highest rated catering service (simulating search query filtering)49 best_service = max(services, key=services.get)50 51 return best_service52 53class SuperheroPartyThemeTool(Tool):54 name = "superhero_party_theme_generator"55 description = """56 This tool suggests creative superhero-themed party ideas based on a category.57 It returns a unique party theme idea."""58 59 inputs = {60 "category": {61 "type": "string",62 "description": "The type of superhero party (e.g., 'classic heroes', 'villain masquerade', 'futuristic Gotham').",63 }64 }65 66 output_type = "string"67 68 def forward(self, category: str):69 themes = {70 "classic heroes": "Justice League Gala: Guests come dressed as their favorite DC heroes with themed cocktails like 'The Kryptonite Punch'.",71 "villain masquerade": "Gotham Rogues' Ball: A mysterious masquerade where guests dress as classic Batman villains.",72 "futuristic Gotham": "Neo-Gotham Night: A cyberpunk-style party inspired by Batman Beyond, with neon decorations and futuristic gadgets."73 }74 75 return themes.get(category.lower(), "Themed party idea not found. Try 'classic heroes', 'villain masquerade', or 'futuristic Gotham'.")76 77 78 79 80with open(os.path.join(CURRENT_DIR, "prompts.yaml"), 'r') as stream:81 prompt_templates = yaml.safe_load(stream)82 83agent = CodeAgent(84 model=model,85 tools=[DuckDuckGoSearchTool(), 86 VisitWebpageTool(),87 suggest_menu,88 catering_service_tool,89 SuperheroPartyThemeTool(),90 FinalAnswerTool()],91 managed_agents=[],92 max_steps=20,93 verbosity_level=1,94 planning_interval=None,95 name=None,96 description=None,97 executor_type='local',98 executor_kwargs={},99 max_print_outputs_length=None,100 prompt_templates=prompt_templates101)102if __name__ == "__main__":103 GradioUI(agent).launch()104 