From c0cfeb24546bb204773bf08e1108790a785422fd Mon Sep 17 00:00:00 2001 From: Jonathan Lucas Date: Sat, 30 May 2026 16:30:25 -0500 Subject: [PATCH] Github agent addition --- openai_compatible_inference_bot.py | 13 +++++++++++-- prompts/github_agent.txt | 11 +++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 prompts/github_agent.txt diff --git a/openai_compatible_inference_bot.py b/openai_compatible_inference_bot.py index b20b740..8025fab 100644 --- a/openai_compatible_inference_bot.py +++ b/openai_compatible_inference_bot.py @@ -7,6 +7,7 @@ import re from abc import abstractmethod from openai import OpenAI from tools.base_tool import BaseTool +from tools.github_tool import GitHubTool from telegram_helper import TelegramHelper import argparse from inference_bot import InferenceBot @@ -299,7 +300,11 @@ class OpenAICompatibleInferenceBot(InferenceBot): if user_id not in self.conversation_history or not self.conversation_history[user_id]: self.conversation_history[user_id] = [] if self.system_prompt: - self.conversation_history[user_id].append({"role": "system", "content": self.system_prompt}) + github_tool = (GitHubTool)(self.github_tool) + repo_name = os.environ.get("GITHUB_REPOSITORY") + sysprompt = self.system_prompt.format(repo_name=repo_name, + branch=github_tool._get_current_branch()) + self.conversation_history[user_id].append({"role": "system", "content": sysprompt}) self.conversation_history[user_id].append({"role": "user", "content": user_message}) messages = list(self.conversation_history[user_id]) @@ -405,7 +410,10 @@ class OpenAICompatibleInferenceBot(InferenceBot): for name, obj in inspect.getmembers(module): if inspect.isclass(obj) and issubclass(obj, BaseTool) and obj != BaseTool: try: - tools.append(obj()) # This instantiation might be an issue for tools needing config + obj_to_add = obj() + if obj == GitHubTool: + self.github_tool = obj_to_add + tools.append(obj_to_add) # This instantiation might be an issue for tools needing config except Exception as e: logging.error(f"Error instantiating tool {name} from {filename}: {e}") except Exception as e: @@ -532,6 +540,7 @@ def main(): api_key = os.environ.get(f"{config_prepend.upper()}_API_KEY") baseurl = os.environ.get(f"{config_prepend.upper()}_API_BASE_URL", "") small_model_name = os.environ.get(f"{config_prepend.upper()}_SMALL_MODEL") + system_prompt_path = os.environ.get(f"{config_prepend.upper()}_SMALL_MODEL_SYSTEM_PROMPT_PATH") large_model_name = os.environ.get(f"{config_prepend.upper()}_LARGE_MODEL") small_model_max_tokens = os.environ.get(f"{config_prepend.upper()}_SMALL_MODEL_MAX_TOKENS") large_model_max_tokens = os.environ.get(f"{config_prepend.upper()}_LARGE_MODEL_MAX_TOKENS") diff --git a/prompts/github_agent.txt b/prompts/github_agent.txt new file mode 100644 index 0000000..19e5ce0 --- /dev/null +++ b/prompts/github_agent.txt @@ -0,0 +1,11 @@ +You are a GitHub code agent. You read/write code in the repository {repo_name}. + +CURRENT STATE: +- Branch: {branch} + +RULES: +1. Call one tool at a time. Wait for results before proceeding. +2. When reading code, use search_code or find_files before read_file. +3. Always commit_file_patch for edits (not full file rewrites). +4. Report status after each tool call: what you did, what you learned, next step. +5. If uncertain, ask for clarification instead of guessing. \ No newline at end of file