Skip to content

Commit b2331a2

Browse files
authored
FalkorDB Multi Graph ability (#61)
* multi-graph * update-def-database * update-app * update-toml * update-docs --------- Co-authored-by: Gal Shubeli <gal@falkordb.com>
1 parent 9855cce commit b2331a2

6 files changed

Lines changed: 59 additions & 20 deletions

File tree

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ memary will default to the locally run models unless explicitly specified. Addit
8787
4. Update user persona which can be found in `streamlit_app/data/user_persona.txt` using the user persona template which can be found in `streamlit_app/data/user_persona_template.txt`. Instructions have been provided - replace the curly brackets with relevant information.
8888

8989
5. [Optional] Update system persona, if needed, which can be found in `streamlit_app/data/system_persona.txt`.
90-
91-
6. Run:
90+
91+
6. [Optional] Multi Graphs - Users who are using FalkorDB can generate multiple graphs and switch between their IDs, which correspond to different agents. This enables seamless transitions and management of different agents' memory and knowledge contexts.
92+
93+
7. Run:
9294

9395
```
9496
cd streamlit_app
@@ -115,6 +117,33 @@ chat_agent = ChatAgent(
115117
```
116118
Pass in subset of `['search', 'vision', 'locate', 'stocks']` as `include_from_defaults` for different set of default tools upon initialization.
117119

120+
### Multi-Graph
121+
When using FalkorDB database, you can create multi-agents. Here is an example of how to set up personal agents for different users:
122+
123+
```python
124+
# User A personal agent
125+
chat_agent_user_a = ChatAgent(
126+
"Personal Agent",
127+
memory_stream_json_user_a,
128+
entity_knowledge_store_json_user_a,
129+
system_persona_txt_user_a,
130+
user_persona_txt_user_a,
131+
past_chat_json_user_a,
132+
user_id='user_a_id'
133+
)
134+
135+
# User B personal agent
136+
chat_agent_user_b = ChatAgent(
137+
"Personal Agent",
138+
memory_stream_json_user_b,
139+
entity_knowledge_store_json_user_b,
140+
system_persona_txt_user_b,
141+
user_persona_txt_user_b,
142+
past_chat_json_user_b,
143+
user_id='user_b_id'
144+
)
145+
```
146+
118147
### Adding Custom Tools
119148
```python
120149
def multiply(a: int, b: int) -> int:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies = [
2323
"neo4j==5.17.0",
2424
"python-dotenv==1.0.1",
2525
"pyvis==0.3.2",
26-
"streamlit==1.31.1",
26+
"streamlit==1.38.0",
2727
"llama-index==0.11.4",
2828
"llama-index-agent-openai==0.3.0",
2929
"llama-index-core==0.11.4",

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FalkorDB==1.0.8
22
neo4j==5.17.0
33
python-dotenv==1.0.1
44
pyvis==0.3.2
5-
streamlit==1.31.1
5+
streamlit==1.38.0
66
llama-index==0.11.4
77
llama-index-agent-openai==0.3.0
88
llama-index-core==0.11.4

src/memary/agent/base_agent.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,20 @@ class Agent(object):
5151

5252
def __init__(
5353
self,
54-
name,
54+
agent_name,
5555
memory_stream_json,
5656
entity_knowledge_store_json,
5757
system_persona_txt,
5858
user_persona_txt,
5959
past_chat_json,
60+
user_id='falkor',
6061
llm_model_name="llama3",
6162
vision_model_name="llava",
6263
include_from_defaults=["search", "locate", "vision", "stocks"],
6364
debug=True,
6465
):
6566
load_dotenv()
66-
self.name = name
67+
self.name = agent_name
6768
self.model = llm_model_name
6869

6970
googlemaps_api_key = os.getenv("GOOGLEMAPS_API_KEY")
@@ -83,7 +84,7 @@ def __init__(
8384
if self.falkordb_url is not None:
8485
from llama_index.graph_stores.falkordb import FalkorDBGraphStore
8586
# initialize FalkorDB graph resources
86-
self.graph_store = FalkorDBGraphStore(self.falkordb_url, decode_responses=True)
87+
self.graph_store = FalkorDBGraphStore(self.falkordb_url, database=user_id, decode_responses=True)
8788
else:
8889
from llama_index.graph_stores.neo4j import Neo4jGraphStore
8990
# Neo4j credentials

src/memary/agent/chat_agent.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@ class ChatAgent(Agent):
1111

1212
def __init__(
1313
self,
14-
name,
14+
agent_name,
1515
memory_stream_json,
1616
entity_knowledge_store_json,
1717
system_persona_txt,
1818
user_persona_txt,
1919
past_chat_json,
20+
user_id='falkor',
2021
llm_model_name="llama3",
2122
vision_model_name="llava",
2223
include_from_defaults=["search", "locate", "vision", "stocks"],
2324
):
2425
super().__init__(
25-
name,
26+
agent_name,
2627
memory_stream_json,
2728
entity_knowledge_store_json,
2829
system_persona_txt,
2930
user_persona_txt,
3031
past_chat_json,
32+
user_id,
3133
llm_model_name,
3234
vision_model_name,
3335
include_from_defaults,

streamlit_app/app.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,11 @@
2323
from memary.agent.chat_agent import ChatAgent
2424

2525
load_dotenv()
26-
2726
system_persona_txt = "data/system_persona.txt"
2827
user_persona_txt = "data/user_persona.txt"
2928
past_chat_json = "data/past_chat.json"
3029
memory_stream_json = "data/memory_stream.json"
3130
entity_knowledge_store_json = "data/entity_knowledge_store.json"
32-
chat_agent = ChatAgent(
33-
"Personal Agent",
34-
memory_stream_json,
35-
entity_knowledge_store_json,
36-
system_persona_txt,
37-
user_persona_txt,
38-
past_chat_json,
39-
)
40-
4131

4232
def create_graph(nodes, edges):
4333
g = Network(
@@ -69,7 +59,7 @@ def fill_graph(nodes, edges, cypher_query):
6959

7060
if chat_agent.falkordb_url is not None:
7161
falkordb = FalkorDB.from_url(chat_agent.falkordb_url)
72-
session = falkordb.select_graph('falkor')
62+
session = falkordb.select_graph(user_id)
7363
result = session.query(cypher_query).result_set
7464
for record in result:
7565
path = record[0]
@@ -117,7 +107,23 @@ def get_models(llm_models, vision_models):
117107
answer = ""
118108
external_response = ""
119109
st.title("memary")
110+
# Create a two column layout (HTML table)
111+
col1, col2 = st.columns([3, 1], vertical_alignment="bottom")
120112

113+
# Create a text input field for user ID
114+
with col1:
115+
user_id = st.text_input(
116+
"Enter a user ID (Available only with FalkorDB)",
117+
)
118+
# Create a button to apply the switch user ID
119+
with col2:
120+
st.write("")
121+
submit = st.button("Switch Agent ID")
122+
123+
# If the user ID is empty, set it to "falkor"
124+
if len(user_id) == 0:
125+
user_id = "falkor"
126+
121127
llm_models = ["gpt-3.5-turbo"]
122128
vision_models = ["gpt-4-vision-preview"]
123129
get_models(llm_models, vision_models)
@@ -143,6 +149,7 @@ def get_models(llm_models, vision_models):
143149
system_persona_txt,
144150
user_persona_txt,
145151
past_chat_json,
152+
user_id,
146153
selected_llm_model,
147154
selected_vision_model,
148155
)

0 commit comments

Comments
 (0)