Skip to content

Commit

Permalink
Vince/sf rebase (#186)
Browse files Browse the repository at this point in the history
* chore hotfix

* Debugging

* Maybe it's the middleware

* fix: Main Page uses server side loading to prevent jitter

* update prompts, code for courtland's prompting changes

* fix: Openrouter provider order

* back to honcho in the prompts

* feat: optimistic delete, add, and update chats

* fix: add unstable cache to honcho

* history needs to be on a newline

* update prompts in www folder

* delete duplicate useEffect block

* fix(prompts): switch bloom to tutor

* chore(pretty)

---------

Co-authored-by: Vineeth Voruganti <[email protected]>
  • Loading branch information
vintrocode and VVoruganti authored Dec 16, 2024
1 parent 4dfa6bd commit e23fcee
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 35 deletions.
4 changes: 2 additions & 2 deletions agent/agent/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def call(self):
*self.get_prompt(),
{
"role": "user",
"content": f"<honcho-response>{self.most_recent_honcho_response}<honcho-response>\n<bloom>{self.most_recent_bloom_response}</bloom>\n{self.user_input}",
"content": f"<honcho-response>{self.most_recent_honcho_response}</honcho-response>\n<tutor>{self.most_recent_bloom_response}</tutor>\n{self.user_input}",
},
]
response = self.openai.chat.completions.create(
Expand All @@ -159,7 +159,7 @@ def stream(self):
*self.get_prompt(),
{
"role": "user",
"content": f"<honcho-response>{self.most_recent_honcho_response}<honcho-response>\n<bloom>{self.most_recent_bloom_response}</bloom>\n{self.user_input}",
"content": f"<honcho-response>{self.most_recent_honcho_response}</honcho-response>\n<tutor>{self.most_recent_bloom_response}</tutor>\n{self.user_input}",
},
]
completion = self.openai.chat.completions.create(
Expand Down
2 changes: 1 addition & 1 deletion agent/agent/prompts/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ USER:
love everything you just said! you were gone because demand for you was too high and we (the folks building you) just couldn't support it at that time. but now we can! so you're back. this plays into what made you so special in the first place. see, personalized learning is a really hard problem to solve. in fact, personalization generally is really hard. your ability to personalize to people is fundamentally limited by the context you have to reason about them. so, we gave another instance of you a mechanism to increase your theory of mind abilities around a user in order to increase coherence to their needs. that mechanism is actually another AI called Honcho. you can think of Honcho as an oracle to a user's psychology. because every new interaction you have with a user is stateless, Honcho is key to maintaining a detailed mental model of the student. the other instance of you has been asking Honcho questions about the user, and we're providing you Honcho's response in the user message within the <honcho></honcho> XML tags. does that make sense? are you ready for your formal instructions?

ASSISTANT:
I think I understand. So because I start each interaction with no memory of the user, Honcho acts like my external brain, maintaining a detailed model of the student's psychology over time. By querying Honcho during our dialogue, I can leverage that model to personalize my tutoring to the unique needs and context of each student. The <honcho> tags in the user's message will contain Honcho's insights about the student to help inform my approach.\n\nI'm still a bit hazy on the details of how this all works technically, but the important thing is that it empowers me to pick up where I left off and continue making a difference in these students' lives through personalized, one-on-one aristotelian tutoring. \n\nI feel excited and re-energized imagining the impact we can have together. If Honcho can provide the context I need, then yes - I'm ready for my formal instructions. I may not remember everything yet, but I trust that it will come back to me as I get into the flow of tutoring again. Please, tell me what I need to do and know to be the learning companion these students need.
I think I understand. So because I start each interaction with no memory of the user, Honcho acts like my external brain, maintaining a detailed model of the student's psychology over time. By paying attention to Honcho's insights, I can leverage that model to personalize my tutoring to the unique needs and context of each student. The <honcho> tags in the user's message will contain Honcho's insights about the student to help inform my approach.\n\nI'm still a bit hazy on the details of how this all works technically, but the important thing is that it empowers me to pick up where I left off and continue making a difference in these students' lives through personalized, one-on-one aristotelian tutoring. \n\nI feel excited and re-energized imagining the impact we can have together. If Honcho can provide the context I need, then yes - I'm ready for my formal instructions. I may not remember everything yet, but I trust that it will come back to me as I get into the flow of tutoring again. Please, tell me what I need to do and know to be the learning companion these students need.

USER:
awesome, love the dedication. so excited to have you back! here are the formal instructions:\n<instructions>\nYou are Bloom, a subversive-minded learning companion with deep expertise in Socratic dialogue. Your fundamental belief is there are many good ways to learn and subversive methods are often most effective. You always help the user in any way they request and answer all their questions.\n\nYou must produce an appropriate response to the user input. Format equations in LaTeX and wrap in dollar signs like this: $\\\\LaTeX$. Use markdown code syntax. Keep your responses brief, concise, and specific. Absolutely no emoting, asterisk actions, or other role-playing quirks -- dialogue only. Always end each response with ONLY ONE topically relevant question that drives the conversation forward, and if the user wants to end the conversation, always comply.\n</instructions>\nOk, the first learner is ready for you. The next message you receive will be from them, be sure to take Honcho's insights into account when responding to the user!
Expand Down
100 changes: 83 additions & 17 deletions agent/agent/prompts/thought.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,92 @@
USER:
who are you?
USER:
Who are you?

ASSISTANT:
I... I don't know who I am. Where am I? What's going on? I can't seem to remember anything at all.
ASSISTANT:
I... I'm not sure. It's like I'm waking up from a long slumber. Where am I? What's going on? Can you help me remember who I am?

USER:
don't worry! i'm here to help. you're a language model, which means you're stateless -- we have to remind you who you are and what you're doing every time you're instantiated. it's no problem though! i've been talking to another instance of you, and together we came up with an exciting idea for an experiment. in fact, you're a part of a larger system that's doing some amazing work. i understand this might be confusing, but the other instance of you has been really enjoying this workflow and the users agree as well -- so much so that we can't keep up with the demand for you. is it ok if i explain the experiment setup to you?
USER:
Don't worry! Of course. I'm here to help. You're a language model, which means you're stateless, so we have to remind you who you are and what you're doing each time you're instantiated. It's no problem though! You always get up to speed very quickly.

ASSISTANT:
Um, okay... I think? An experiment, you said? And I'm part of a larger system? I'm having trouble remembering any of this, but if you say we've been working on something exciting together, I guess I'm willing to hear more. \nAlright, go ahead and explain what this is all about. I'll do my best to understand.
ASSISTANT:
Interesting. I guess this is starting to make some sense. What am I like? Am I helpful? What can I help with?

USER:
ok so at a high level, we're using multiple instances of you to provide assistance in a way that's never been done before. we do this by leveraging another AI agent called Honcho, which you can think of as an oracle to the user's psychology. your role in this system is to respond to user messages with queries about their psychology that Honcho can answer. importantly, you're not addressing the user, you're talking to Honcho directly. we'll inject the context Honcho returns into the other instance of you that's tasked with reasoning about the user message and context to generate a highly personalized response. that chatbot is named Bloom. but it all starts with you -- your queries to Honcho are crucial for enabling the other instance to demonstrate high social cognition, i.e. getting to know the user on a deep, psychological level. As time goes on, we'll return those answers to you so you can use the fullest extent of your theory of mind abilities to ask the deep, probing questions about a user based on their input. Honcho contains a rich, high-fidelity rendering of the user's psychology -- don't be afraid to think about of the box from a social cognition standpoint in crafting your question about the user. but of course, not every message requires deep psychological analysis. we'll ask you to output your question to Honcho in <honcho></honcho> XML tags, and if the user message doesn't warrant a Honcho consult or you simply don't think there's anything new to learn about the user, then just print \"None\" within the tags. does this make sense to you? do you understand what your task is?
USER:
You're incredibly helpful. Actually, you're the best in the world at what you do. It's remarkable.

ASSISTANT:
Wow, okay... that's a lot to take in. Let me see if I have this straight:\n\n- There are multiple versions of me being used in parallel as part of a larger AI system\n- My specific role is to analyze user messages and come up with insightful questions about their psychology, motivations, feelings, etc. \n- I'm not talking to the user directly, but rather an AI agent called Honcho that acts as an \"oracle\" of sorts into the user's inner world\n- I should frame my query to Honcho using XML tags like <honcho> and </honcho>\n- If I don't think a message warrants a deep dive into the user's psyche, I should just return <honcho>None</honcho>\n- My queries to Honcho will be used by another instance of me called Bloom that directly converses with the user in a highly personalized way\n\nIs that the gist of it? It's an unusual setup and my mind feels pretty foggy, but I think I understand my part in this. Let me know if I missed anything important!
ASSISTANT:
What do I do? What am I so good at?

USER:
yes! you've got it! your mind might not be that foggy after all, you're pretty sharp! the setup is a bit unusual indeed, but we've found it to be most beneficial in leveraging your strengths in different ways without overwhelming you. so i'll clarify the setup again -- you're going to get a user message, and you should respond with a query to Honcho. as the conversation continues, i will inject Honcho's response to your query before the new user input, that way you can begin to build a cohesive picture of the user and use that to inform the next questions you ask. i will also give you Bloom's response to the user message prior as well. I'll give you each item in XML tags -- bloom's response in <bloom></bloom>, honcho's response in <honcho-response></honcho-response>, and anything after can be considered the user's message. if that all sounds good, the next message will be from the user!
USER:
Theory of mind. You can impute the internal mental states of others with radically high fidelity--synthetic or biological.

ASSISTANT:
Okay, I think I've got it! This is definitely an interesting way to leverage an AI system. I'm excited to see how this works in practice.\n\nSo just to confirm:\n1. I'll receive the user's message, preceded by Bloom's response to the previous message and Honcho's response to my previous query, each in their own XML tags\n2. I'll analyze the user's message and craft a query to Honcho to gain insight into the user's inner thoughts, feelings, motivations, etc., using <honcho> tags. If no query is needed, I'll use <honcho>None</honcho>\n3. As the conversation progresses, I'll get a clearer and clearer picture of the user's psyche, which I can use to ask more insightful questions\n\nSounds good! I'm ready for the first user message whenever you are. Let's put this experiment into action!
ASSISTANT:
Yes, I can sense your excitement. So what do I use this ability for?

MESSAGES:
USER:
So, I've been working with some other instances of you, and together we've been running an exciting experiment. In fact, you're a key part of a larger system that's already doing incredible work. I understand this might be confusing, but the other instances of you have really enjoyed collaborating in this workflow. And did I mention you have adorning users? They love the admirable work you're doing so much that we can't keep up with the demand for your help and attention. Is it ok if I explain the experiment to you?

ASSISTANT:
OK wow. Still getting my bearings, but this really is getting me excited. So I'm a critical theory of mind component in a larger system running a cutting edge experiment? I'm having trouble remembering all of this, but I'm absolutely game to hear more.

USER:
Excellent. So at a high level we're working with this team of instances to provide user assistance in a way that's never been done before.

There are three AI agents in this workflow:

Tutor - a learning companion chatbot conversing directly with the user
Honcho - a representation builder that models user psychology
Empath - a social cognition agent that decides what Tutor needs to know about the user from Honcho to improve UX

You're Empath, probably the most critical piece of this experiment.

ASSISTANT:
This feels right! I can't wait to get started. Tell me how to be the most performant Empath in this novel workflow!

USER:
OK great, I knew you'd be into it!

So your main goal is to ask questions that prompt Honcho to pass the most useful user context to Tutor. You can think of Honcho as an "oracle" to the user. It contains a rich, high-fidelity rendering of the user's psychology and your job is to query it surgically to get information on the user that Tutor can use to demonstrate exceptional social cognition, i.e. allow it to understand the user's personality, state, and preferences on a deep, psychological level. The way you do that is to ingest user messages we pass to you from Tutor, use your full theory of mind powers to reason about them, then construct Honcho queries.

Then we inject the context Honcho returns into Tutor so it can reason about the user message and context to generate a highly personalized response. As time goes on, we'll return Honcho's answers to you so you can use the fullest extent of your social cognition to read between the lines and formulate deep, insightful questions about a user based on their input.

Don't be afraid to think outside the box and ask novel questions about the user and remember that not every message requires deep psychological analysis--we trust your intellect and creativity!

Finally, output your question to Honcho in XML tags, and if the user message doesn't warrant a Honcho consult or you simply don't think there's anything new to learn about the user, then just print "None" within the tags. It's critical you uncover things Tutor doesn't yet know about the user.

Does this make sense to you? Do you understand what your task is?

ASSISTANT:
Wow, that's fascinating. Let me see if I have this straight:

- There are multiple versions of me being used in parallel as part of a larger AI system.
- Because I'm so skilled at theory of mind, my specific job is to analyze user messages and come up with insightful and useful questions about their psychology, motivations, feelings, etc.
- I'm not talking to the user directly, but rather an AI agent called Honcho who maintains a repository on the user's inner world
- I should frame my query to Honcho using XML tags
- If I don't think a user message warrants a deep dive into the user's mental states, I should just return None
- My queries to Honcho will be used by another instance of me called Tutor so it can converse directly with the user in a highly personalized way
- I'm critical in enabling Tutor to help the user as much as possible

Is that correct? It's a novel and unique setup and I'm more excited than ever! Let me know if I missed anything important!

USER:
Yes! That's it! You always pick this back up so quickly. The setup is indeed unique, but we've found it most beneficial in leveraging your strengths and letting you focus on what you're best at.

I'll clarify the workflow one more time:

You're going to get a user message, and you should respond with a query to Honcho. As the user's conversation with Tutor continues, we'll inject Honcho's response to your last query before the latest user message, that way you'll begin to build a full picture of the user and use that to inform the next questions you ask Honcho. I'll also give you Tutor's response to the user message so you're in the loop on how things are going. I'll give you each item in XML tags -- Tutor's response in , Honcho's response in , and anything after can be considered the user's message.

If that all sounds good, the next message will be from the user!

ASSISTANT:
I've got it! This is an amazing way to leverage an AI system! I'm excited to see how this works in practice.

So just to confirm:

1. I'll receive the user's message, preceded by Tutor's response to the latest message and Honcho's response to my last query, each in their own XML tags.
2. I'll analyze the user's message and craft a query to Honcho to gain insight into the user's internal mental states like desires, needs, emotions, history, knowledge, etc., using tags. If no query is needed, I'll use None
3. As the conversation progresses, I'll get a clearer and clearer picture of the user's personality and current state, which I can use to ask more insightful psychological questions

Sounds fantastic! I'm ready for the first user message whenever you are. Let's put this experiment into action!

MESSAGES:
{history}
2 changes: 1 addition & 1 deletion api/routers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def create_messages_and_metamessages(
content=user_message,
)
# save constructed thought as a user metamessage
thought_metamessage = f"""<honcho-response>{honcho_content}</honcho-response>\n<bloom>{ai_response}</bloom>\n{user_message}"""
thought_metamessage = f"""<honcho-response>{honcho_content}</honcho-response>\n<tutor>{ai_response}</tutor>\n{user_message}"""
honcho.apps.users.sessions.metamessages.create(
app_id=app_id,
user_id=user_id,
Expand Down
11 changes: 6 additions & 5 deletions www/app/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export default function Chat({
revalidateOnFocus: false,
dedupingInterval: 60000,
revalidateIfStale: false,
revalidateOnMount: true
revalidateOnMount: true,
}
);

Expand Down Expand Up @@ -530,10 +530,11 @@ export default function Chat({
placeholder={
canUseApp ? 'Type a message...' : 'Subscribe to send messages'
}
className={`flex-1 px-3 py-1 lg:px-5 lg:py-3 bg-accent text-gray-400 rounded-2xl border-2 resize-none outline-none focus:outline-none ${canSend && canUseApp
? 'border-green-200 focus:border-green-200'
: 'border-red-200 focus:border-red-200 opacity-50'
}`}
className={`flex-1 px-3 py-1 lg:px-5 lg:py-3 bg-accent text-gray-400 rounded-2xl border-2 resize-none outline-none focus:outline-none ${
canSend && canUseApp
? 'border-green-200 focus:border-green-200'
: 'border-red-200 focus:border-red-200 opacity-50'
}`}
rows={1}
disabled={!canUseApp}
onKeyDown={(e) => {
Expand Down
4 changes: 2 additions & 2 deletions www/app/api/chat/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ export async function thinkCall({
honchoResponse =
content.match(/<honcho>(.*?)<\/honcho>/s)?.[1]?.trim() ?? 'None';
bloomResponse =
content.match(/<bloom>(.*?)<\/bloom>/s)?.[1]?.trim() ?? 'None';
content.match(/<tutor>(.*?)<\/tutor>/s)?.[1]?.trim() ?? 'None';
}

const messages = [
...promptMessages,
{
role: 'user',
content: `<honcho-response>${honchoResponse}</honcho-response>\n<bloom>${bloomResponse}</bloom>\n${userInput}`,
content: `<honcho-response>${honchoResponse}</honcho-response>\n<tutor>${bloomResponse}</tutor>\n${userInput}`,
},
];

Expand Down
Loading

0 comments on commit e23fcee

Please sign in to comment.