repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | --- |
| #2 | title: Collaborative Task Assistant |
| #3 | description: "Coordinate multi-user projects with shared memories and roles." |
| #4 | --- |
| #5 | |
| #6 | |
| #7 | ## Overview |
| #8 | |
| #9 | Build a multi-user collaborative chat or task management system with Mem0. Each message is attributed to its author, and all messages are stored in a shared project space. Mem0 makes it easy to track contributions, sort and group messages, and collaborate in real time. |
| #10 | |
| #11 | ## Setup |
| #12 | |
| #13 | Install the required packages: |
| #14 | |
| #15 | ```bash |
| #16 | pip install openai mem0ai |
| #17 | ``` |
| #18 | |
| #19 | ## Full Code Example |
| #20 | |
| #21 | ```python |
| #22 | from openai import OpenAI |
| #23 | from mem0 import Memory |
| #24 | import os |
| #25 | from datetime import datetime |
| #26 | from collections import defaultdict |
| #27 | |
| #28 | # Set your OpenAI API key |
| #29 | os.environ["OPENAI_API_KEY"] = "sk-your-key" |
| #30 | |
| #31 | # Shared project context |
| #32 | RUN_ID = "project-demo" |
| #33 | |
| #34 | # Initialize Mem0 |
| #35 | mem = Memory() |
| #36 | |
| #37 | class CollaborativeAgent: |
| #38 | def __init__(self, run_id): |
| #39 | self.run_id = run_id |
| #40 | self.mem = mem |
| #41 | |
| #42 | def add_message(self, role, name, content): |
| #43 | msg = {"role": role, "name": name, "content": content} |
| #44 | self.mem.add([msg], run_id=self.run_id, infer=False) |
| #45 | |
| #46 | def brainstorm(self, prompt): |
| #47 | # Get recent messages for context |
| #48 | memories = self.mem.search(prompt, run_id=self.run_id, limit=5)["results"] |
| #49 | context = "\n".join(f"- {m['memory']} (by {m.get('actor_id', 'Unknown')})" for m in memories) |
| #50 | client = OpenAI() |
| #51 | messages = [ |
| #52 | {"role": "system", "content": "You are a helpful project assistant."}, |
| #53 | {"role": "user", "content": f"Prompt: {prompt}\nContext:\n{context}"} |
| #54 | ] |
| #55 | reply = client.chat.completions.create( |
| #56 | model="gpt-4.1-nano-2025-04-14", |
| #57 | messages=messages |
| #58 | ).choices[0].message.content.strip() |
| #59 | self.add_message("assistant", "assistant", reply) |
| #60 | return reply |
| #61 | |
| #62 | def get_all_messages(self): |
| #63 | return self.mem.get_all(run_id=self.run_id)["results"] |
| #64 | |
| #65 | def print_sorted_by_time(self): |
| #66 | messages = self.get_all_messages() |
| #67 | messages.sort(key=lambda m: m.get('created_at', '')) |
| #68 | print("\n--- Messages (sorted by time) ---") |
| #69 | for m in messages: |
| #70 | who = m.get("actor_id") or "Unknown" |
| #71 | ts = m.get('created_at', 'Timestamp N/A') |
| #72 | try: |
| #73 | dt = datetime.fromisoformat(ts.replace('Z', '+00:00')) |
| #74 | ts_fmt = dt.strftime('%Y-%m-%d %H:%M:%S') |
| #75 | except Exception: |
| #76 | ts_fmt = ts |
| #77 | print(f"[{ts_fmt}] [{who}] {m['memory']}") |
| #78 | |
| #79 | def print_grouped_by_actor(self): |
| #80 | messages = self.get_all_messages() |
| #81 | grouped = defaultdict(list) |
| #82 | for m in messages: |
| #83 | grouped[m.get("actor_id") or "Unknown"].append(m) |
| #84 | print("\n--- Messages (grouped by actor) ---") |
| #85 | for actor, mems in grouped.items(): |
| #86 | print(f"\n=== {actor} ===") |
| #87 | for m in mems: |
| #88 | ts = m.get('created_at', 'Timestamp N/A') |
| #89 | try: |
| #90 | dt = datetime.fromisoformat(ts.replace('Z', '+00:00')) |
| #91 | ts_fmt = dt.strftime('%Y-%m-%d %H:%M:%S') |
| #92 | except Exception: |
| #93 | ts_fmt = ts |
| #94 | print(f"[{ts_fmt}] {m['memory']}") |
| #95 | ``` |
| #96 | |
| #97 | ## Usage |
| #98 | |
| #99 | ```python |
| #100 | # Example usage |
| #101 | agent = CollaborativeAgent(RUN_ID) |
| #102 | agent.add_message("user", "alice", "Let's list tasks for the new landing page.") |
| #103 | agent.add_message("user", "bob", "I'll own the hero section copy.") |
| #104 | agent.add_message("user", "carol", "I'll choose product screenshots.") |
| #105 | |
| #106 | # Brainstorm with context |
| #107 | print("\nAssistant reply:\n", agent.brainstorm("What are the current open tasks?")) |
| #108 | |
| #109 | # Print all messages sorted by time |
| #110 | agent.print_sorted_by_time() |
| #111 | |
| #112 | # Print all messages grouped by actor |
| #113 | agent.print_grouped_by_actor() |
| #114 | ``` |
| #115 | |
| #116 | ## Key Points |
| #117 | |
| #118 | - Each message is attributed to a user or agent (actor) |
| #119 | - All messages are stored in a shared project space (`run_id`) |
| #120 | - You can sort messages by time, group by actor, and format timestamps for clarity |
| #121 | - Mem0 makes it easy to build collaborative, attributed chat/task systems |
| #122 | |
| #123 | ## Conclusion |
| #124 | |
| #125 | Mem0 enables fast, transparent collaboration for teams and agents, with full attribution, flexible memory search, and easy message organization. |
| #126 | |
| #127 | --- |
| #128 | |
| #129 | <CardGroup cols={2}> |
| #130 | <Card title="Partition Memories by Entity" icon="layers" href="/cookbooks/essentials/entity-partitioning-playbook"> |
| #131 | Learn how to scope memories across users, agents, and runs for team workflows. |
| #132 | </Card> |
| #133 | <Card title="Support Inbox with Mem0" icon="headset" href="/cookbooks/operations/support-inbox"> |
| #134 | Apply collaborative memory patterns to customer support scenarios. |
| #135 | </Card> |
| #136 | </CardGroup> |
| #137 |