-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_ensemble.py
More file actions
89 lines (71 loc) · 2.4 KB
/
Copy pathbasic_ensemble.py
File metadata and controls
89 lines (71 loc) · 2.4 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
81
82
83
84
85
86
87
88
89
"""
Basic example of creating and running a KhazarLLMs ensemble.
This demonstrates how to create agents, assemble them into an ensemble,
and run a creative collaboration session.
"""
import asyncio
from pathlib import Path
from khazar_llms.agents.personas import (
DreamerAgent,
CriticAgent,
SynthesizerAgent,
PhilosopherAgent,
)
from khazar_llms.orchestration.ensemble import Ensemble, ConversationMode
from khazar_llms.orchestration.session import CreativeSession
async def main():
"""Run a basic ensemble example."""
# Create agents with different personas
# Using 'mock' provider for demo (no API keys needed)
agents = [
DreamerAgent(provider="mock"),
CriticAgent(provider="mock"),
SynthesizerAgent(provider="mock"),
PhilosopherAgent(provider="mock"),
]
# Create an ensemble in sequential mode
ensemble = Ensemble(
agents=agents,
mode=ConversationMode.SEQUENTIAL,
max_iterations=3,
)
# Create a creative session
session = CreativeSession(
ensemble=ensemble,
output_dir=Path("./output/sessions"),
)
# Define a creative task
task = """
Design a new form of social network that prioritizes human connection
over engagement metrics. How would it work? What makes it different?
"""
print("\n" + "=" * 80)
print("STARTING KHAZAR LLMs CREATIVE SESSION")
print("=" * 80)
print(f"\nTask: {task.strip()}")
print(f"\nAgents: {len(agents)}")
for agent in agents:
print(f" - {agent.name} ({agent.role.value})")
print(f"\nMode: {ensemble.mode}")
print(f"Iterations: {ensemble.max_iterations}")
print("\nRunning collaboration...\n")
# Run the session
results = await session.run(task)
# Print results
session.print_summary(results)
# Save outputs
json_path = session.save_session(results, format="json")
txt_path = session.save_session(results, format="txt")
print(f"\nSession saved:")
print(f" JSON: {json_path}")
print(f" Text: {txt_path}")
# Display conversation
print("\n" + "=" * 80)
print("CONVERSATION TRANSCRIPT")
print("=" * 80 + "\n")
for i, msg in enumerate(results["conversation"], 1):
print(f"\n[{i}] {msg.sender} ({msg.role.value}) - Iteration {msg.iteration}")
print("-" * 40)
print(msg.content)
if __name__ == "__main__":
asyncio.run(main())