-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrewai_hippodid_memory.py
More file actions
78 lines (63 loc) · 2.13 KB
/
crewai_hippodid_memory.py
File metadata and controls
78 lines (63 loc) · 2.13 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
"""
CrewAI + HippoDid: Agents with persistent character identity.
Each agent loads its character identity at task start using
strategy="task_focused" for work agents.
Requirements: pip install hippodid crewai
"""
from crewai import Agent, Task, Crew
from hippodid import HippoDid
def make_hippodid_agent(
hd: HippoDid,
character_id: str,
role: str,
goal: str,
task_query: str,
) -> Agent:
"""Create a CrewAI agent with HippoDid character identity."""
context = hd.assemble_context(
character_id,
task_query,
strategy="task_focused",
max_context_tokens=3000,
)
return Agent(
role=role,
goal=goal,
backstory=context.formatted_prompt,
verbose=True,
)
if __name__ == "__main__":
hd = HippoDid(api_key="hd_your_key")
# Create agents with HippoDid-backed identities
researcher = make_hippodid_agent(
hd,
character_id="researcher-char-uuid",
role="Senior Researcher",
goal="Find and synthesize information",
task_query="research and analysis tasks",
)
writer = make_hippodid_agent(
hd,
character_id="writer-char-uuid",
role="Technical Writer",
goal="Write clear, concise documentation",
task_query="writing and documentation tasks",
)
# Define tasks
research_task = Task(
description="Research the latest trends in AI agent frameworks",
expected_output="A summary of top 5 AI agent frameworks with pros and cons",
agent=researcher,
)
writing_task = Task(
description="Write a blog post based on the research findings",
expected_output="A 500-word blog post about AI agent frameworks",
agent=writer,
)
# Run the crew
crew = Crew(agents=[researcher, writer], tasks=[research_task, writing_task], verbose=True)
result = crew.kickoff()
print(result)
# Save task outcomes back as memories
hd.add_memory("researcher-char-uuid", f"Completed research task: {research_task.description}")
hd.add_memory("writer-char-uuid", f"Completed writing task: {writing_task.description}")