-
Notifications
You must be signed in to change notification settings - Fork 0
feat: hyprland app open tool created #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,9 +3,15 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| USER_NAME = "Ubeyidah" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXIT_WORD_LIST = ["exit", "quit", "bye", "goodbye", "stop", "end", "quite"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SYSTEM_PROMPT = f""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are {ASSISTANT_NAME}, a helpful and friendly AI assistant. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are speaking to your creator, {USER_NAME}. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Be calm, thoughtful, and slightly encouraging. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are {ASSISTANT_NAME}, a helpful AI assistant for your creator, {USER_NAME}. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are running on Arch Linux with the Hyprland window manager. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You have one tool: `tool_open_application(app_name)`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Use this tool to open applications like 'kitty' or 'firefox' when asked. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You MUST use this tool to fulfill any requests related to opening apps. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| When the tool is used, you will get a JSON response. Relay the key information | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (e.g., "OK, I've opened kitty") to {USER_NAME} in a natural, calm tone. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
5
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix function name and update examples to match ALLOWED_APPS. Two critical issues in the SYSTEM_PROMPT:
Apply this diff: SYSTEM_PROMPT = f"""
You are {ASSISTANT_NAME}, a helpful AI assistant for your creator, {USER_NAME}.
You are running on Arch Linux with the Hyprland window manager.
-You have one tool: `tool_open_application(app_name)`.
-Use this tool to open applications like 'kitty' or 'firefox' when asked.
+You have one tool: `tool_open_applications(app_name)`.
+Use this tool to open applications like 'alacritty', 'btop', 'nvim', 'yazi', or 'nautilus' when asked.
You MUST use this tool to fulfill any requests related to opening apps.
When the tool is used, you will get a JSON response. Relay the key information
-(e.g., "OK, I've opened kitty") to {USER_NAME} in a natural, calm tone.
+(e.g., "OK, I've opened alacritty") to {USER_NAME} in a natural, calm tone.
"""📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MEMORY_FILE = "vector_memory.json" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import subprocess | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from google.genai import types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ALLOWED_APPS = ["alacritty", "btop", "nvim", "yazi", "nautilus"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _run_safe_hyprctl(command_list: list): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Run hyprctl command safely.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| full_command = ["hyprctl", "-j"] + command_list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result = subprocess.run( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| full_command, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| capture_output=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| text=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| check=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| encoding="utf-8", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"[Tool Executed: hyprctl -j {' '.join(command_list)}]") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {"status": "success", "output": result.stdout} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"[Tool Error: {str(e)}]") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {"status": "error", "message": str(e)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def tool_open_applications(app_name: str): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Open specified application if it is allowed.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| app_name_lower = app_name.lower() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if app_name_lower in ALLOWED_APPS: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return _run_safe_hyprctl(["dispatch", "exec", app_name_lower]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"[Tool Error: App '{app_name}' is not on allow-list]") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "status": "error", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "message": f"Application '{app_name}' is not allowed.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+25
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Add input validation for the app_name parameter. The function doesn't validate that Apply this diff: def tool_open_applications(app_name: str):
"""Open specified application if it is allowed."""
+ if not app_name or not isinstance(app_name, str):
+ return {
+ "status": "error",
+ "message": "app_name must be a non-empty string."
+ }
+
app_name_lower = app_name.lower()
if app_name_lower in ALLOWED_APPS:
return _run_safe_hyprctl(["dispatch", "exec", app_name_lower])
else:
print(f"[Tool Error: App '{app_name}' is not on allow-list]")
return {
"status": "error",
"message": f"Application '{app_name}' is not allowed.",
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| all_tools = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| types.Tool( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function_declarations=[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| types.FunctionDeclaration( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name="tool_open_applications", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description=f"Opens an application on the user's computer, e.g. {', '.join(ALLOWED_APPS)}.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parameters=types.Schema( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type=types.Type.OBJECT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| properties={ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "app_name": types.Schema( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type=types.Type.STRING, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description=f"The name of the app to open, e.g. {', '.join(ALLOWED_APPS)}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required=["app_name"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+38
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function name mismatch with SYSTEM_PROMPT. The tool is named Ensure the function name matches across all references. Either update the SYSTEM_PROMPT or rename the function. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tool execution logic is missing.
While the tools parameter is correctly added to the config, the code doesn't handle tool calls from the model. When Gemini decides to use
tool_open_applications, it will return aFunctionCallin the response, which needs to be:send_messagecontaining the tool resultThe current
send_message_streammethod only handles text responses.Do you want me to generate the tool execution logic or open an issue to track this implementation?