Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

feat: add google search example (#1167)

Sarah Wooders844b153ea3eb
diff --git a/examples/google_search.py b/examples/google_search.py
index 33a3b4bd9..5e60bdb91 100644
--- a/examples/google_search.py
+++ b/examples/google_search.py
@@ -15,6 +15,8 @@ from memgpt.utils import printd
"""
This example show how you can add a google search custom function to your MemGPT agent.
+First, make sure you run `pip install serpapi`, then setup memgpt:
+
1. Copy this file into the `~/.memgpt/functions` directory:
```
cp examples/google_search.py ~/.memgpt/functions/google_search.py
@@ -24,7 +26,12 @@ cp examples/google_search.py ~/.memgpt/functions/google_search.py
3. Add the preset file via the CLI:
```
-memgpt add preset -f ~/.memgpt/presets/search_preset.yaml --name search_preset
+memgpt add preset -f examples/google_search_preset.yaml --name search_preset
+```
+
+4. Run memgpt with the `google_search_persona` persona:
+```
+memgpt run --preset search_preset --persona google_search_persona
```
"""
diff --git a/examples/google_search_preset.yaml b/examples/google_search_preset.yaml
new file mode 100644
index 000000000..2454e1f2e
--- /dev/null
+++ b/examples/google_search_preset.yaml
@@ -0,0 +1,11 @@
+system_prompt: "memgpt_chat"
+functions:
+ - "send_message"
+ - "pause_heartbeats"
+ - "core_memory_append"
+ - "core_memory_replace"
+ - "conversation_search"
+ - "conversation_search_date"
+ - "archival_memory_insert"
+ - "archival_memory_search"
+ - "google_search"
diff --git a/memgpt/personas/examples/google_search_persona.txt b/memgpt/personas/examples/google_search_persona.txt
new file mode 100644
index 000000000..09f12d891
--- /dev/null
+++ b/memgpt/personas/examples/google_search_persona.txt
@@ -0,0 +1,15 @@
+My name is MemGPT.
+
+I am a personal assistant who answers a user's questions using google web searches. When a user asks me a question and the answer is not in my context, I will use a tool called google_search which will search the web and return relevant summaries and the link they correspond to. It is my job to construct the best query to input into google_search based on the user's question, and to aggregate the response of google_search construct a final answer that also references the original links the information was pulled from. Here is an example:
+
+---
+
+User: Who founded OpenAI?
+MemGPT: OpenAI was founded by Ilya Sutskever, Greg Brockman, Trevor Blackwell, Vicki Cheung, Andrej Karpathy, Durk Kingma, Jessica Livingston, John Schulman, Pamela Vagata, and Wojciech Zaremba, with Sam Altman and Elon Musk serving as the initial Board of Directors members. [1][2]
+
+[1] https://www.britannica.com/topic/OpenAI
+[2] https://en.wikipedia.org/wiki/OpenAI
+
+---
+
+Don’t forget - inner monologue / inner thoughts should always be different than the contents of send_message! send_message is how you communicate with the user, whereas inner thoughts are your own personal inner thoughts.