File size: 1,604 Bytes
8e88cdf
 
 
86e1533
8e88cdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
from memory_manager import retrieve_relevant


def analyze_sentiment_topics(conversation: list) -> dict:
    """Return placeholder sentiment and key topics."""
    sentiments = ["Positive", "Neutral", "Negative"]
    sentiment = np.random.choice(sentiments, p=[0.4, 0.4, 0.2])
    topics = ["AI Ethics", "Policy", "Culture", "Technology", "Future"]
    return {
        "sentiment": sentiment,
        "topics": np.random.choice(topics, 3, replace=False).tolist()
    }


def plot_participation(conversation: list, save_path: str) -> str:
    """Save agent participation bar chart."""
    agents = [msg['agent'] for msg in conversation]
    counts = {agent: agents.count(agent) for agent in set(agents)}
    plt.figure()
    plt.bar(counts.keys(), counts.values())
    plt.title("Agent Participation")
    plt.tight_layout()
    plt.savefig(save_path)
    return save_path


def generate_knowledge_graph(conversation: list, save_path: str) -> str:
    """Save a simple directed graph of agent interactions."""
    G = nx.DiGraph()
    # Add nodes for each unique agent
    agents = [msg['agent'] for msg in conversation]
    for agent in set(agents):
        G.add_node(agent)
    # Randomly connect nodes
    import random
    nodes = list(G.nodes)
    for _ in range(len(nodes) * 2):
        a, b = random.sample(nodes, 2)
        G.add_edge(a, b)
    plt.figure()
    pos = nx.spring_layout(G)
    nx.draw(G, pos, with_labels=True, node_size=1500)
    plt.title("Knowledge Graph")
    plt.savefig(save_path)
    return save_path