File size: 1,577 Bytes
e854e57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# © 2025 Elena Marziali — Code released under Apache 2.0 license.
# See LICENSE in the repository for details.
# Removal of this copyright is prohibited.

# Estrai il contenuto testuale dalla risposta
response_text = getattr(response, "content", str(response)).strip()

# Ora puoi tagliare i primi 1000 caratteri
response_short = response_text[:1000]

reflection_prompt = f"""
You responded to the following prompt:
"{prompt}"

Your answer:
"{response_short}"


Now reflect briefly on how you arrived at this answer.

- What reasoning path led you to this response?
- What criteria guided your choices?
- Were there any risks or ambiguities you considered?
- How does this reflect your cognitive style?

Write a concise reflection in 2–3 paragraphs, using a clear and analytical tone.
"""

reflection = llm.invoke(reflection_prompt).content.strip()

journal = {}

def record_journal(journal_id, prompt, response, reflection):
    journal[journal_id] = {
        "prompt": prompt,
        "response": response,
        "reflection": reflection
    }

record_journal(journal_id=0, prompt=prompt, response=response, reflection=reflection)

def save_journal_markdown(data, file_name):
    with open(file_name, "w", encoding="utf-8") as f:
        f.write(f"# Reflective Journal\n\n")
        f.write(f"## Prompt\n> {data['prompt']}\n\n")
        f.write(f"## Response\n{data['response']}\n\n")
        f.write(f"## Metacognitive Reflection\n{data['reflection']}\n")

filename = f"journal_{datetime.datetime.utcnow().isoformat()}.md"
save_journal_markdown(journal[0], filename)