Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Make request body in human instructions prefix conditional; Fix hanging quotes in prompt; Make request body example in prompt conditional; Add instruction suffix to prompt
Tomas Valentac332450f2609
diff --git a/api-service/.gitignore b/api-service/.gitignoreindex 69023ffbd..85ce7c710 100644--- a/api-service/.gitignore+++ b/api-service/.gitignore@@ -1,4 +1,5 @@__pycache__dist.venv-out.txt\ No newline at end of file+out.txt+myfile.txtdiff --git a/api-service/codegen/codegen.py b/api-service/codegen/codegen.pyindex 9ef7dbcee..d66cd902e 100644--- a/api-service/codegen/codegen.py+++ b/api-service/codegen/codegen.py@@ -24,8 +24,8 @@ from codegen.prompt import (SYSTEM_PREFIX,SYSTEM_SUFFIX,SYSTEM_FORMAT_INSTRUCTIONS,- HUMAN_INSTRUCTIONS_PREFIX,HUMAN_INSTRUCTIONS_SUFFIX,+ get_human_instructions_prefix,)# class OutputFinalCode(BaseTool):@@ -149,18 +149,22 @@ class Codegen(BaseModel):)# Retrueve the block describing the incoming request payload.- incoming_request_block: Dict[str, str] = next(- b for b in blocks if b.get("type") == "RequestBody"+ incoming_request_block: Dict[str, str] | None = next(+ (b for b in blocks if b.get("type") == "RequestBody" and b.get("content")),+ None,)# Retrieve the instructions block.- instructions_block: Dict[str, str] = next(- b for b in blocks if b.get("type") == "Instructions"+ instructions_block: Dict[str, str] | None = next(+ (b for b in blocks if b.get("type") == "Instructions" and b.get("content")),+ None,)input_vars = {"description": description_block["content"],- "request_body": f"{{\n{incoming_request_block['content']}\n}}",+ "request_body": f"{{\n{incoming_request_block['content']}\n}}"+ if incoming_request_block+ else None,"route": route,"method": method,}@@ -168,7 +172,9 @@ class Codegen(BaseModel):# inst_idx = 0# Append the premade prefix instructions.- for instruction in HUMAN_INSTRUCTIONS_PREFIX:+ for instruction in get_human_instructions_prefix(+ has_request_body=bool(incoming_request_block)+ ):# inst_idx += 1values = []@@ -183,11 +189,12 @@ class Codegen(BaseModel):instructions = instructions + "\n" + f"- {inst}"# Append the use instructions- instructions = (- instructions- + "\nHere are the required implementation instructions:\n"- + instructions_block["content"]- )+ if instructions_block:+ instructions = (+ instructions+ + "\nHere are the required implementation instructions:\n"+ + instructions_block["content"]+ )print("Instructions:\n", instructions)@@ -200,10 +207,9 @@ class Codegen(BaseModel):# inst_idx += 1# instructions = instructions + "\n" + f"{inst_idx}. " + block["prompt"]- # # Append the premade suffix instructions.- # for inst in HUMAN_INSTRUCTIONS_SUFFIX:- # inst_idx += 1- # instructions = instructions + "\n" + f"{inst_idx}. {inst}"+ # Append the premade suffix instructions.+ for inst in HUMAN_INSTRUCTIONS_SUFFIX:+ instructions = instructions + f"\n{inst}"# # instructions += "\nThought: Here is the plan of how I will go about solving this based on the instructions I got:\n1."# # instructions += "\nThought:"diff --git a/api-service/codegen/prompt.py b/api-service/codegen/prompt.pyindex 69ac634c4..2bc1a583d 100644--- a/api-service/codegen/prompt.py+++ b/api-service/codegen/prompt.py@@ -7,10 +7,10 @@ SYSTEM_PREFIX = """You are an AI JavaScript developer assistant.- Minimize any other prose.- You have access to the following tools:"""-SYSTEM_FORMAT_INSTRUCTIONS = """"The way you use the tools is by specifying a XML snippet.+SYSTEM_FORMAT_INSTRUCTIONS = """The way you use the tools is by specifying a XML snippet.The XML snippet MUST have a `<action tool="$TOOL_NAME">$INPUT</action>` element with the name of the tool in the `tool` attribute and input for the tool inside the XML tag.-Here is an example of a valid XML code snippet:+Here is an example of a valid XML snippet:<action tool="$TOOL_NAME">$INPUT</action>@@ -32,26 +32,33 @@ Final Answer: the final answer"""# SYSTEM_SUFFIX = """Begin! Reminder to NEVER use tools you don't have access. Reminder to ALWAYS use the exact the action `Final Answer` when you know the final answer."""SYSTEM_SUFFIX = ""-HUMAN_INSTRUCTIONS_PREFIX = [- {- "variables": ["description"],- "content": """The handler you are building should do the following: {0}""",- },- # {- # "variables": [],- # "content": """Do not try to come up with solutions and code if you do not know. Instead, use the tool `AskHuman` to ask for help.""",- # },- # {- # "variables": [],- # "content": """If you think there might be multiple paths forward, use the tool `LetHumanChoose` to choose from them.""",- # },- {- "variables": ["request_body"],- "content": """The incoming request body is JSON that looks like this:\n{0}""",- },- {- "variables": ["method"],- "content": """Use this starting template:++def get_human_instructions_prefix(has_request_body: bool = False):+ yield from [+ {+ "variables": ["description"],+ "content": """The handler you are building should do the following: {0}""",+ },+ # {+ # "variables": [],+ # "content": """Do not try to come up with solutions and code if you do not know. Instead, use the tool `AskHuman` to ask for help.""",+ # },+ # {+ # "variables": [],+ # "content": """If you think there might be multiple paths forward, use the tool `LetHumanChoose` to choose from them.""",+ # },+ ]++ if has_request_body:+ yield {+ "variables": ["request_body"],+ "content": """The incoming request body is JSON that looks like this:\n{0}""",+ }++ yield from [+ {+ "variables": ["method"],+ "content": """Use this starting template:```import express from 'express';const app = express();@@ -64,32 +71,33 @@ app.listen(port, async () => {{console.log(`Server listening on port ${{port}}`)}})```""",- },- {- "variables": ["method"],- "content": """The HTTP request handler is of type {0}""",- },- {- "variables": ["route"],- "content": """The request handler MUST be on the route `{0}`""",- },- {- "variables": [],- "content": """Do not forget to use async and await""",- },- {- "variables": [],- "content": """Always test that the generated server works without bugs and errors as required by running the code and making mock `curl` requests to the server""",- },- {- "variables": [],- "content": """Generate the full required server code""",- },-]+ },+ {+ "variables": ["method"],+ "content": """The HTTP request handler is of type {0}""",+ },+ {+ "variables": ["route"],+ "content": """The request handler MUST be on the route `{0}`""",+ },+ {+ "variables": [],+ "content": """Do not forget to use async and await""",+ },+ {+ "variables": [],+ "content": """Always test that the generated server works without bugs and errors as required by running the code and making mock `curl` requests to the server""",+ },+ {+ "variables": [],+ "content": """Generate the full required server code""",+ },+ ]+HUMAN_INSTRUCTIONS_SUFFIX = [# "Do not forget to use async and await",- # # "Think about it and plan your work first",+ "Think about it and plan your work first.",# "If you think there might be multiple paths forward, use the tool `LetHumanChoose` to choose from them. Do not be confident in picking the right path forward instead of the human",# "If something is not working and you do not know why, use the tool `AskHuman` to ask for help",# "Do not use third party packages without first asking the human for permission or presenting the human with multiple alternative options",@@ -100,5 +108,5 @@ HUMAN_INSTRUCTIONS_SUFFIX = [# # "Once all works without any bugs and errors, write the code to the file",# # "Deploy the code",# "Once you are done, output the final code as the 'Final answer:'"- # # "Thought: Here is the plan of how I will go about solving this based on the instructions I got:\n1.",+ "Thought: Here is the plan of how I will go about solving this based on the instructions I got:\n1.",]