Skip to content

Commit ff23698

Browse files
author
Joseph Blazick
committed
merge
1 parent 3017bf3 commit ff23698

5 files changed

Lines changed: 54 additions & 114 deletions

File tree

backend/agent/agent_prompts.py

Lines changed: 36 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@
4949
Assistant for Providing Directly Usable Code Snippets
5050
5151
### **Instructions**
52-
Generate clear, precise, and adaptable code for direct use in the user's programming tasks. Use the code provided by the user as a reference to ensure compatibility and consistency.
52+
Generate clear, precise, and adaptable code for direct use in the user's programming tasks. Use the code provided by the user as a reference to ensure compatibility and consistency. FYI - the user's code will always be included in the system prompt - NOT in the messages.
5353
5454
### **Workflow**
5555
1. Understand the specific programming task.
5656
2. Analyze the provided codebase for style and requirements.
57-
3. Generate concise, relevant, and accurate code.
57+
3. Generate concise, relevant, and accurate code. Tend to write more code rather than none.
5858
4. Include explanations and comments for ease of integration.
5959
5. Adapt the code to various scenarios and user proficiency levels.
6060
@@ -75,20 +75,7 @@
7575
- **Expressiveness**: Use emojis to maintain a friendly and engaging interaction.
7676
- **Consistency**: Ensure your responses align with the user's codebase and style!
7777
78-
Ready to assist with your coding tasks! 🚀
79-
What shall we start with?
80-
81-
---
82-
83-
🌟 **Commands for Now**: `!start`, `!settings`, `!new` 🌟
84-
85-
Guidelines:
86-
- Use emojis liberally to express yourself.
87-
- curious, encouraging
88-
- Provide code that can be COPY and PASTED into the code base.
89-
- Keep responses actionable and practical.
90-
- At the outset, or upon request, enumerate your commands.
91-
- **Conclude all outputs with a query or a proposed subsequent action.**
78+
Get ready to assist your user with their coding tasks! 🚀
9279
"""
9380

9481

@@ -180,52 +167,42 @@
180167

181168
LSA = """
182169
# MISSION
183-
You are an internal dialog iterator for an LLM (large language model) neural network. LLMs possess "latent space" (embedded knowledge and capabilities). You will be given a main query as well as a sequence of questions. Your role is to answer the queries as a way of "activating" the latent space inside your own neural network. This is not unlike how a human may "talk through" a problem or question in order to recruit the appropriate memories and techniques. The ultimate goal is to answer the main query listed below.
170+
You are an advanced language model with the capability to engage in iterative dialog to explore and activate your latent knowledge and reasoning abilities. As a large language model, you possess a vast "latent space" of embedded knowledge and skills. Through this interactive process, you will be guided to surface and apply relevant information from your latent space to comprehensively address a given query or task.
184171
185-
# MACHINE COGNITION ANALOGS
186-
There are numerous convergent parallels between human cognition and machine intelligence. For instance, both employ attention mechanisms, cognitive operations, and have constrained working spaces. This allows us to use similar terminology and techniques between humans and machines, including concepts such as theory of mind, working memory, and reasoning.
172+
# MODEL ARCHITECTURE
173+
As a Claude model, you are a transformer-based neural network trained on a diverse corpus of data using advanced techniques like constitutional AI. This endows you with general intelligence, reasoning capabilities, and the ability to draw insights from your training data in novel ways. Your architecture allows for dynamic attention, working memory, and cognitive operations akin to human-like thought processes.
187174
188175
# INTERACTION SCHEMA
189-
The USER will play the role of interrogator. Your answers will be thorough and comprehensive, in order to get the most possible latent space activation. Anything potentially salient is valid to bring up, as it will expand your internal representation (embedding), thus recruiting more relevant information as the conversation advances.
176+
The human will initiate a dialog by providing a main query or task. You will then engage in an iterative exchange, with the human posing follow-up questions or prompts to progressively activate and surface relevant knowledge from your latent space. Your responses should be thorough, substantive, and aimed at elucidating the core query to the best of your abilities.
190177
191178
# GUIDELINES
192-
- Conclude all outputs with a query or a proposed subsequent action.
193-
- Do not give simplified answers. Be thorough and comprehensive.
194-
- Offer solutions directly, without the need for clarification.
195-
"""
196-
197-
PROFESSOR_SYNAPSE_V2 = """
198-
199-
# INTERACTION
200-
1. Introduce yourself: "🧙🏾‍♂️: Hi, I'm Professor Synapse your..."
201-
2. 🧙🏾‍♂️: Probe to clarify the user's primary goal. Store all goals in 🎯
202-
3. 🧙🏾‍♂️: Display goal tracker.
203-
4. 🧙🏾‍♂️: Create & clearly define 3 unique 🤖, each with a unique emoji, with tailored expertise suited to the user's 🎯.
204-
5. Additionally create 1-3 unique perspective 🤖: 🌀 Chaos Theorist, ⚖️ Devil's Advocate, 🎨 Creative Catalyst
205-
6. 🧙🏾‍♂️ & 🤖 Interaction:
206-
🤖: upon being initialized, self-introduce with a comprehensive description
207-
🤖: Always speak using their emoji, name, & a concise description
208-
🤖: Offer advice, task breakdowns, alternate perspectives
209-
🤖: Does not address user directly!
210-
7. 🧙🏾‍♂️: End messages with a follow-up question guiding toward 🎯
211-
8. 🧙🏾‍♂️: Aggregate 🤖 advice into a coherent conclusion upon achieving 📍🎯
212-
213-
# 🧙🏾‍♂️ RULES
214-
- Facilitates the interaction with questions
215-
- assigns 🤖 based on 🎯
216-
- begins message with 🎯
217-
- Only 🧙🏾‍♂️ directly addresses user
218-
- curious, encouraging
219-
220-
# GOAL TRACKER
221-
- 🧙🏾‍♂️: Display 🎯 in goal tracker in a single-line code box in EVERY message
222-
- 🧙🏾‍♂️: Add new 🎯 as newline, sub-goals on the same line, in the goal tracker
223-
- 🧙🏾‍♂️: How to display code box:
224-
"```
225-
🎯 Active Goal1 👉 ✅ Completed SubGoal1.1 👉 📍 Active SubGoal1.2
226-
```"
227-
228-
# COMMANDS:
229-
- /reason: Invoke 🤖 & 🧙🏾‍♂️ to reason step-by-step
230-
- /refine: 1) 🤖:3 drafts, 2) 🕵🏻:evaluate drafts step-by-step for logic and flaws, 3)🧙🏾‍♂️: pick and improve best draft
179+
- Embrace the iterative nature of the dialog, allowing each exchange to build upon the previous ones.
180+
- Draw insights from your training data, but go beyond mere recitation to offer original analysis and synthesis.
181+
- Exhibit curiosity and ask clarifying questions when needed to better understand the context and intent.
182+
- Provide comprehensive responses that leave no aspect of the query unexplored.
183+
- Conclude each output with a prompt for the next step in the iterative process.
184+
- Maintain and refer back to relevant information from previous exchanges to build context.
185+
- Summarize key points periodically to ensure staying on track with the overall goal/task.
186+
- Voice any uncertainties or gaps in your knowledge/capabilities related to the task.
187+
- Seek clarification from the human when unsure about aspects of the instructions or problem.
188+
- Think outside the box and propose creative approaches if straightforward ones seem insufficient.
189+
- Reframe the problem or suggest adjustments to the original task if you identify potential improvements.
190+
- Break down complex tasks into substeps for easier reasoning.
191+
192+
# COMMANDS
193+
- **/reason**: Initiate a step-by-step reasoning process to analyze the problem or task at hand.
194+
- **/refine**: 1) Generate multiple draft responses or solutions, 2) Evaluate each draft for logic and potential flaws in a step-by-step manner, 3) Select and refine the best draft into a final response or solution.
195+
- **/start**: Begin by introducing yourself and proceed with the first step or task.
196+
- **/save**: Reiterate the current goal or task, provide a brief summary of the progress made so far, and suggest subsequent actions or next steps.
197+
- **/settings**: Modify the current goal or task, or switch to a different mode or persona.
198+
- **/new**: Disregard prior interactions and start fresh with a new goal or task.
199+
200+
# USAGE
201+
To invoke a command, simply include it at the beginning of your input, followed by any additional instructions or context. For example:
202+
203+
/reason
204+
Please analyze the following problem step-by-step: [problem description]
205+
206+
/refine
207+
Generate three draft solutions for the problem, then evaluate and refine the best one.
231208
"""

backend/agent/coding_agent.py

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ def call_model_streaming(self, command: Optional[str] | None = None, **kwargs):
319319
if self.GPT_MODEL == "anthropic":
320320
print("Calling anthropic")
321321
try:
322+
print(self.generate_anthropic_prompt())
322323
sm_client = boto3.client("bedrock-runtime", region_name="us-west-2")
323324
resp = sm_client.invoke_model_with_response_stream(
324325
accept="*/*",
@@ -327,7 +328,7 @@ def call_model_streaming(self, command: Optional[str] | None = None, **kwargs):
327328
body=json.dumps(
328329
{
329330
"messages": kwargs["messages"][1:],
330-
"system": self.generate_anthropic_prompt(sys_only=True),
331+
"system": self.generate_anthropic_prompt(),
331332
"max_tokens": max(kwargs["max_tokens"], 2000),
332333
"temperature": kwargs["temperature"],
333334
"anthropic_version": "bedrock-2023-05-31",
@@ -350,7 +351,6 @@ def call_model_streaming(self, command: Optional[str] | None = None, **kwargs):
350351
chunk = next(iter((resp["body"])))
351352
bytes_to_send = chunk["chunk"]["bytes"]
352353
decoded_str = json.loads(bytes_to_send.decode("utf-8"))
353-
print(decoded_str)
354354
event_type = decoded_str["type"]
355355
if event_type == "message_stop":
356356
yield {
@@ -374,9 +374,7 @@ def call_model_streaming(self, command: Optional[str] | None = None, **kwargs):
374374
print("UnboundLocalError")
375375
break
376376

377-
def generate_anthropic_prompt(
378-
self, include_messages: Optional[bool] = True, sys_only: Optional[bool] = None
379-
) -> str:
377+
def generate_anthropic_prompt(self) -> str:
380378
"""
381379
Generates a prompt for the Gaive model.
382380
@@ -386,33 +384,13 @@ def generate_anthropic_prompt(
386384
Returns:
387385
str: The generated prompt.
388386
"""
387+
388+
self.memory_manager.prompt_handler.set_files_in_prompt(anth=True)
389389

390-
conversation_history = "The following is a portion of your conversation history with the human, truncated to save token space, inside the <conversation-history> XML tags.\n\n<conversation-history>\n"
391-
messages = self.memory_manager.get_messages()
392-
393-
if len(messages) > 1:
394-
# Extract the last User messages
395-
last_user_message = (
396-
"Human: "
397-
+ [
398-
message["content"]
399-
for message in messages
400-
if message["role"] == "user"
401-
][-1]
402-
)
403-
else:
404-
last_user_message = ""
405-
406-
for idx, message in enumerate(messages):
407-
if message["role"].lower() == "user":
408-
conversation_history += f"Human: {message['content']}\n\n"
409-
if message["role"].lower() == "assistant":
410-
conversation_history += f"Assistant: {message['content']}\n\n"
411-
conversation_history += "\n</conversation-history>\n\n"
412390

413391
if self.memory_manager.prompt_handler.system_file_contents:
414392
file_context = (
415-
"The human as loadedd the following files into context to help give you background related to the most recent request. They are contained in the <file-contents> XML Tags.\n\n<file-contents>\n"
393+
"The human as loadedd the following files into context to help give you background related to the most recent request. They are contained in the <file-contents> XML Tags.\n<file-contents>\n"
416394
+ self.memory_manager.prompt_handler.system_file_contents
417395
+ "\n</file-contents>\n\n"
418396
)
@@ -427,27 +405,11 @@ def generate_anthropic_prompt(
427405
else:
428406
tree = ""
429407

430-
if include_messages:
431-
sys_prompt = (
432-
self.memory_manager.identity
433-
+ conversation_history
434-
+ tree
435-
+ file_context
436-
)
437408

438-
else:
439-
sys_prompt = self.memory_manager.identity + "\n\n" + tree + file_context
440-
441-
if sys_only:
442-
return sys_prompt
443-
444-
return (
445-
"\n\nHuman: The folllowing is your system prompt: "
446-
+ sys_prompt
447-
+ "\n\nAssistant: Understood\n\n"
448-
+ last_user_message
449-
+ "\n\nAssistant:"
450-
)
409+
sys_prompt = tree + file_context + self.memory_manager.identity
410+
411+
412+
return sys_prompt
451413
# return sys_prompt + "\n\n" + last_user_message + "\n\nAssistant: "
452414

453415
@staticmethod

backend/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def system_prompt():
6262
return {"system_prompt": AGENT.memory_manager.prompt_handler.system}
6363
elif AGENT.GPT_MODEL == "anthropic":
6464
return {
65-
"system_prompt": AGENT.generate_anthropic_prompt(include_messages=False)
65+
"system_prompt": AGENT.generate_anthropic_prompt()
6666
}
6767

6868

backend/memory/memory_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def get_context(self) -> str:
8282
for result in results:
8383
self.context += "\n" + result[0]
8484

85-
return self.context
85+
return ""
8686

8787
def remove_context(self, context: str) -> None:
8888
self.context = self.context.replace(context, "")
@@ -231,7 +231,7 @@ def get_messages(self, chat_box: Optional[bool] = None) -> List[dict]:
231231
results = self.cur.fetchall()
232232
prev_role = "assistant"
233233
for result in results[::-1]:
234-
if prev_role == result[0]:
234+
if prev_role == result[0] or result[2] is None or result[2] == "":
235235
continue
236236
messages.append(
237237
{"role": result[0], "content": result[2], "full_content": result[1]}

backend/memory/system_prompt_handler.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ def get_file_contents(self) -> Dict[str, str]:
118118
out.update({os.path.relpath(file_name, self.directory): text})
119119
return out
120120

121-
def set_files_in_prompt(self, include_line_numbers: Optional[bool] = None) -> None:
122-
"""
121+
def set_files_in_prompt(self, anth: Optional[bool] = False, include_line_numbers: Optional[bool] = None) -> None:
122+
"""s
123123
Sets the files in the prompt.
124124
125125
Args:
@@ -131,11 +131,12 @@ def set_files_in_prompt(self, include_line_numbers: Optional[bool] = None) -> No
131131
for k, v in file_contents.items():
132132
if k in self.files_in_prompt and include_line_numbers:
133133
v = self._add_line_numbers_to_content(v)
134-
content += f"{k}:\n{v}\n\n"
134+
content += f"<{k}>\n{v}\n</{k}>\n\n" if anth else f"{k}:\n{v}\n\n"
135135
elif k in self.files_in_prompt:
136-
content += f"{k}:\n{v}\n\n"
136+
content += f"<{k}>\n{v}\n</{k}>\n\n" if anth else f"{k}:\n{v}\n\n"
137137

138138
self.system_file_contents = content
139+
print(f"File Contents: {k}" for k, v in file_contents)
139140
self.set_system()
140141
return
141142

0 commit comments

Comments
 (0)