1616import json
1717import logging
1818from pathlib import PurePosixPath
19- from typing import Any , Self , TypedDict , override
19+ from typing import Any , Self , TypedDict , cast , override
2020
2121import openai
2222
2323from ..common import JSONObject , UnreachableError , config_string , reindent
24+ from ..instructions import SYSTEM_PROMPT
2425from .common import ActionSummary , Bot , Goal , UserFeedback , Worktree
2526
2627
@@ -159,19 +160,6 @@ def params(self) -> Sequence[openai.types.chat.ChatCompletionToolParam]:
159160 ]
160161
161162
162- # https://aider.chat/docs/more-info.html
163- # https://github.com/Aider-AI/aider/blob/main/aider/prompts.py
164- _INSTRUCTIONS = """
165- You are an expert software engineer, who writes correct and concise code.
166- Use the provided functions to find the files you need to answer the query,
167- read the content of the relevant ones, and save the changes you suggest.
168-
169- You should stop when and ONLY WHEN all the files you need to change have
170- been updated. If you do not have enough information to complete your task,
171- use the provided tool to request it from the user, then stop.
172- """
173-
174-
175163class _ToolHandler [V ]:
176164 def __init__ (self , tree : Worktree , feedback : UserFeedback ) -> None :
177165 self ._tree = tree
@@ -241,7 +229,7 @@ async def act(
241229 tool_handler = _CompletionsToolHandler (tree , feedback )
242230
243231 messages : list [openai .types .chat .ChatCompletionMessageParam ] = [
244- {"role" : "system" , "content" : reindent ( _INSTRUCTIONS ) },
232+ {"role" : "system" , "content" : SYSTEM_PROMPT },
245233 {"role" : "user" , "content" : goal .prompt },
246234 ]
247235
@@ -254,10 +242,12 @@ async def act(
254242 tool_choice = "required" ,
255243 )
256244 assert len (response .choices ) == 1
245+ choice = response .choices [0 ]
257246 request_count += 1
258247
259248 done = True
260- calls = response .choices [0 ].message .tool_calls
249+ messages .append (cast (Any , choice .message .to_dict (mode = "json" )))
250+ calls = choice .message .tool_calls
261251 for call in calls or []:
262252 output = tool_handler .handle_function (call .function )
263253 if output is not None :
@@ -302,7 +292,7 @@ def __init__(self, client: openai.OpenAI, model: str) -> None:
302292 def _load_assistant_id (self ) -> str :
303293 kwargs : JSONObject = dict (
304294 model = self ._model ,
305- instructions = reindent ( _INSTRUCTIONS ) ,
295+ instructions = SYSTEM_PROMPT ,
306296 tools = _ToolsFactory (strict = True ).params (),
307297 )
308298 path = self .state_folder_path (ensure_exists = True ) / "ASSISTANT_ID"
0 commit comments