File size: 1,653 Bytes
e0c069c
 
 
 
271fdae
e0c069c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75afe96
 
 
 
 
 
e0c069c
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import logging
import requests
from time import perf_counter, sleep
from memory_manager import embed_and_store, retrieve_relevant

# Agent prompts
PROMPTS = {
    "Initiator": "You are the Discussion Initiator...",
    "Responder": "You are the Critical Responder...",
    "Guardian": "You are the Depth Guardian...",
    "Provocateur": "You are the Cross-Disciplinary Provocateur...",
    "Cultural": "You are the Cultural Perspective...",
    "Judge": "You are the Impartial Judge..."
}

CHAT_MODEL = os.environ.get("CHAT_MODEL", "HuggingFaceH4/zephyr-7b-beta")
HF_API_TOKEN = os.environ.get("HF_API_TOKEN", "")
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")


chat_history = "\n".join([f"{msg['role'].capitalize()}: {msg['content']}" for msg in history])
full_prompt = f"{system_prompt}\n\n{chat_history}\n\nAssistant:"
payload = {
    "inputs": full_prompt,
    "parameters": {"max_new_tokens": 300, "temperature": temperature}
}

def step_turn(conversation: list, turn: int, topic: str, params: dict) -> list:
    """Advance one turn of the multi-agent conversation."""
    # Choose agent by sequence
    sequence = ["Initiator", "Responder", "Guardian", "Provocateur", "Cultural"]
    agent = sequence[turn % len(sequence)]
    prompt = PROMPTS.get(agent, "")
    # Prepare history
    history = [{"role": "user", "content": msg['text']} for msg in conversation[-5:]]
    response = safe_chat(prompt, history, temperature=params[agent]['creativity'])
    embed_and_store(response, agent, topic)
    conversation.append({"agent": agent, "text": response, "turn": turn + 1})
    return conversation