-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_agent.py
More file actions
80 lines (65 loc) · 2.99 KB
/
multi_agent.py
File metadata and controls
80 lines (65 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""Example: Deep Agent with sub-agents sharing Sulcus memory.
The main agent delegates research to a sub-agent. Both agents share
the same Sulcus tenant, so the sub-agent's findings are immediately
available to the main agent and persist across sessions.
This is where Sulcus fundamentally outperforms file-based memory:
sub-agents in DeepAgents get isolated filesystems, so AGENTS.md
changes in a sub-agent are lost when it terminates. Sulcus memories
persist because they're in the shared graph, not the sandbox.
Usage:
pip install sulcus deepagents sulcus-deepagents
export SULCUS_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
python multi_agent.py
"""
import os
from deepagents import create_deep_agent
from deepagents.middleware.subagents import SubAgent
from sulcus import Sulcus
from sulcus_deepagents import SulcusMemoryMiddleware, SulcusMemoryTools
# ── Shared Sulcus client ─────────────────────────────────────────
client = Sulcus(
api_key=os.environ.get("SULCUS_API_KEY", "sk-..."),
server_url=os.environ.get("SULCUS_SERVER_URL", "https://api.sulcus.ca"),
)
memory_tools = SulcusMemoryTools(client=client)
# ── Sub-agent definition ─────────────────────────────────────────
research_subagent: SubAgent = {
"name": "researcher",
"description": (
"A research specialist that finds information and stores "
"findings in persistent memory for later use."
),
"system_prompt": (
"You are a research specialist. When you find important information, "
"ALWAYS store it using sulcus_store before returning results. "
"Search existing memory first to avoid duplicate work."
),
"tools": memory_tools.tools(),
}
# ── Main agent ───────────────────────────────────────────────────
agent = create_deep_agent(
middleware=[
SulcusMemoryMiddleware(client=client),
],
tools=memory_tools.tools(),
subagents=[research_subagent],
system_prompt=(
"You are a project manager with persistent memory. "
"Delegate research to the 'researcher' sub-agent. "
"All findings are stored in shared memory — you can access "
"what the researcher discovers in future sessions."
),
)
# ── Run ──────────────────────────────────────────────────────────
if __name__ == "__main__":
result = agent.invoke({
"messages": [{
"role": "user",
"content": (
"Research the current state of AI agent memory systems. "
"Store your key findings, then give me a summary."
),
}]
})
print("Agent:", result["messages"][-1].content)