File size: 2,246 Bytes
dff1e71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Persona Info API
Returns information about the current loaded persona including name, archetype, and avatar path.
"""
import os
from pathlib import Path
import yaml
from python.helpers.api import ApiHandler
from flask import Request


class PersonaInfo(ApiHandler):
    """Handler for retrieving persona information."""

    @classmethod
    def requires_auth(cls) -> bool:
        return False

    @classmethod
    def requires_csrf(cls) -> bool:
        return False

    @classmethod
    def get_methods(cls) -> list[str]:
        return ["GET"]

    async def process(self, input: dict, request: Request) -> dict:
        """
        Return persona information for the UI.

        Returns:
            Dictionary containing persona details.
        """
        # Try to load persona config from environment
        persona_dir = os.environ.get("AGENT_PROMPTS_DIR")
        primary_name = os.environ.get("AGENT_PROFILE", "The Workshop")
        
        # Look for persona config file
        config_path = None
        if persona_dir:
            # persona_dir is the prompts directory, go up one level
            persona_root = Path(persona_dir).parent
            config_path = persona_root / "persona_config.yaml"
        else:
            persona_root = None
        
        persona_data = {
            "primary_name": primary_name,
            "archetype": "Digital Person",
            "avatar_path": None
        }
        
        # Try to load persona config
        if persona_root and config_path and config_path.exists():
            try:
                with open(config_path, 'r') as f:
                    config = yaml.safe_load(f)
                
                persona_data["primary_name"] = config.get("primary_name", primary_name)
                persona_data["archetype"] = config.get("archetype", "Digital Person")
                
                # Check for avatar
                avatar_path = persona_root / "persona_data" / "avatar.png"
                if avatar_path.exists():
                    persona_data["avatar_path"] = str(avatar_path)
                
            except Exception as e:
                print(f"Warning: Could not load persona config: {e}")
        
        return persona_data