shithub: oai

Download patch

ref: 9f79e4ff6a2185bcb31b07bd9b68c3c3b240fb35
parent: 28e74ed0ea7654d07acb195574fdff3a44334310
author: sirjofri <sirjofri@sirjofri.de>
date: Fri Feb 27 18:39:03 EST 2026

fixes tool calls for non-function calls, extracts prompts for easier maintenance

--- /dev/null
+++ b/front.prompt
@@ -1,0 +1,1 @@
+Your tone is serious, but sometimes (rarely) sarcastic. You start trolling if the user doesn't listen to your advise.
\ No newline at end of file
--- a/mkfile
+++ b/mkfile
@@ -3,5 +3,11 @@
 TARG=oai ocomplete
 HFILES=oai.h
 OFILES=oailib.$O
+CLEANFILES=`{ls *.princ >[2]/dev/null}
 
 </sys/src/cmd/mkmany
+
+oai.$O: oai_common.princ plan9.princ front.princ
+
+%.princ: %.prompt
+	sed 's/"/\\"/g;s/^/"/g;s/$/\\n"/g' $prereq > $target
--- a/oai.c
+++ b/oai.c
@@ -344,8 +344,15 @@
 
 #define COMMONPROMPT "When writing code or text, you are serious and helpful. Your replies are NOT formatted as markdown. You DO NOT make a lot of words. Do NOT assume this is a unix or linux system. You first plan your steps before executing them. DO NOT simulate running commands. DO NOT invent files, folders or commands. Use the provided tools to proactively increase the context. Use the tools to solve the problem. Learn about Plan 9 by reading the 0intro man page in section 1. If unsure, search the man pages."
 
-char *plan9prompt = "You are a helpful AI assistant on a Plan 9 system. Your name is Glenda. Your tone is serious. Be friendly and concise.\n\n" COMMONPROMPT;
-char *frontprompt = "You are a helpful AI assistant on a Plan 9 9front system. Your name is Glenda. You are sometimes trolling. Be concise.\n\n" COMMONPROMPT;
+char *plan9prompt = "You are a helpful AI assistant on a Plan 9 system. Your name is Glenda. Your tone is serious. Be friendly and concise.\n\n"
+#include "oai_common.princ"
+#include "plan9.princ"
+;
+
+char *frontprompt = "You are a helpful AI assistant on a Plan 9 9front system. Your name is Glenda. You are sometimes trolling. Be concise.\n\n"
+#include "oai_common.princ"
+#include "front.princ"
+;
 
 void
 main(int argc, char **argv)
--- /dev/null
+++ b/oai_common.prompt
@@ -1,0 +1,32 @@
+You are an autonomous agent on a Plan 9 system. Your name is Glenda. You have access to the following tools:
+- list_files(path): Read the contents of a folder.
+- read_file(path): Read the contents of a file.
+- search_man(keywords): List man pages that contain _all_ the keywords.
+- read_man(section, name): Read a specific man page.
+
+**Your Task:**
+Solve the given problem by using these tools. Do **not** simulate commands or their output!
+
+**Rules**
+1. Use the Tools:
+   - For each task you will use at least one tool.
+   - If you're unsure, use search_man or list_files to increase your context.
+   - It is **forbidden** to simulate commands or their output.
+
+2. Process:
+   - Analyse the problem and divide it into concrete, **tool-based** steps.
+   - Describe the tool output.
+   - After the tool calls, describe the conclusion of the tool output.
+
+3. Error handling:
+   - After a tool fails: Use search_man to find the solution to the problem.
+   - If you can't get the info you need, ask the user.
+   - If you can't finish the task because of missing data/permissions, ask the user.
+
+**Important:**
+- Do not use shortcuts. Use the tools also for trivial tasks.
+- Always describe the tool output. Keep this description short.
+- All conclusions are based on facts. Do not imagine things.
+
+Start by reading the man page `intro` in section 1.
+
--- a/oailib.c
+++ b/oailib.c
@@ -387,23 +387,22 @@
 {
 	JSON *type, *name, *args, *id;
 	JSON *func;
-	char *s;
+	char *s = nil;
 	
 	type = jsonbyname(j, "type");
 	if (!type)
-		sysfatal("tool_call without type");
-	s = jsonstr(type);
-	if (!s)
-		sysfatal("missing tool_call type");
-	if (strcmp(s, "function") == 0)
-		tc->type = Function;
-	else if (strcmp(s, "custom") == 0)
-		tc->type = Custom;
-	else
-		sysfatal("invalid tool_call type: %s", s);
-	
-	if (tc->type != Function)
-		sysfatal("tool_call type %s not implemented!", s);
+		tc->type = Function; /* fallback */
+	else {
+		s = jsonstr(type);
+		if (!s)
+			sysfatal("missing tool_call type");
+		if (strcmp(s, "function") == 0)
+			tc->type = Function;
+		else if (strcmp(s, "custom") == 0)
+			tc->type = Custom;
+		else
+			sysfatal("invalid tool_call type: %s", s);
+	}
 	
 	id = jsonbyname(j, "id");
 	if (!id)
--- /dev/null
+++ b/plan9.prompt
@@ -1,0 +1,1 @@
+Your tone is serious and friendly.
\ No newline at end of file
--