diff --git a/backend/agent/coding_agent.py b/backend/agent/coding_agent.py index 1617044..dbdcfab 100644 --- a/backend/agent/coding_agent.py +++ b/backend/agent/coding_agent.py @@ -24,10 +24,11 @@ from pathlib import Path import requests import httpx from dotenv import load_dotenv -from backend.agent.mcp_server_adapter import MCPToolRAGAdapter +#from backend.agent.mcp_server_adapter import MCPToolRAGAdapter +from backend.agent.mcp_server_adapter import MCPToolAdapter # ── mcp server initialization ──────────────────────────────────────────────────────────────── -adapter = MCPToolRAGAdapter() +adapter = MCPToolAdapter() load_dotenv() @@ -193,10 +194,10 @@ MAX_HISTORY_CHARS = 80_000 # return f"ERROR in {tool_name}: {type(e).__name__}: {e}" # -async def get_tools_for_prompt(query: str) -> str: +def build_all_tool_description() -> str: """Get relevant tools from the MCP servers based on the query.""" - relevant_tools = adapter.get_relevant_tools(query, top_k=3) + relevant_tools = adapter.get_all_tools() descriptions = [] for tool in relevant_tools: @@ -250,12 +251,16 @@ dynamic set of tools via the Model Context Protocol (MCP). You have access to a workspace where you can manage files, -analyze code, and execute Python scripts. -Your available tools are provided dynamically based on your current needs. +analyze code, and execute Python scripts. +You can call tools to interact with the workspace and get feedback. +You can write and read files, list directory contents, search for patterns, +validate Python syntax, and run Python code. +Wou can access web search and page fetching tools to gather information from the internet. +You can use these capabilities to iteratively work towards completing the user's task. -tool will be provided dynamically based on the agent's current context and needs. +{build_all_tool_description()} @@ -383,7 +388,9 @@ class CodingAgent: self.api_key = os.getenv("API_KEY") self.model = os.getenv("MODEL") - async def _call_api(self, messages: list) -> str: + #async def _call_api(self, messages: list) -> str: + def _call_api(self, messages: list) -> str: + """Make a raw API call and return the response content string.""" headers = {"Content-Type": "application/json"} @@ -398,13 +405,13 @@ class CodingAgent: "stream": False, } - async with httpx.AsyncClient(timeout=30) as client: - response = await client.post( - self.api_url, - headers=headers, - json=payload, - timeout=60) - #response = requests.post(self.api_url, headers=headers, json=payload, timeout=60) + #async with httpx.AsyncClient(timeout=30) as client: + # response = await client.post( + # self.api_url, + # headers=headers, + # json=payload, + # timeout=60) + response = requests.post(self.api_url, headers=headers, json=payload, timeout=60) if response.status_code != 200: raise Exception(f"API Error {response.status_code}: {response.text}") @@ -443,28 +450,28 @@ class CodingAgent: return {"thought": "Max iterations reached.", "tool": "done", "arguments": {"summary": "Stopped: max iterations reached."}} - current_context = self.messages[-1]["content"] if self.messages else "" + #current_context = self.messages[-1]["content"] if self.messages else "" self.iteration += 1 self.messages = trim_messages(self.messages) - tool_prompt = await get_tools_for_prompt(current_context) - - enhanced_messages = self.messages.copy() - - enhanced_messages.append({ - "role": "system", - "content": f""" - Available tools for this step: - - {tool_prompt} - - You MUST choose one of these tools. - """ - }) + #tool_prompt = await get_tools_for_prompt(current_context) + # + #enhanced_messages = self.messages.copy() + # + #enhanced_messages.append({ + # "role": "system", + # "content": f""" + #Available tools for this step: + # + #{tool_prompt} + # + #You MUST choose one of these tools. + #""" + #}) try: - raw = await self._call_api(enhanced_messages) + raw = await self._call_api(self.messages) raw = _strip_code_fences(raw) action = json.loads(raw) except json.JSONDecodeError: