|
5 | 5 | from ruamel.yaml import YAML, YAMLError |
6 | 6 | from ruamel.yaml.scalarstring import FoldedScalarString |
7 | 7 | from agentstack import conf, log |
| 8 | +from agentstack import frameworks |
8 | 9 | from agentstack.exceptions import ValidationError |
9 | 10 |
|
10 | 11 |
|
11 | 12 | AGENTS_FILENAME: Path = Path("src/config/agents.yaml") |
| 13 | +AGENTS_PROMPT_TPL: str = "You are {role}. {backstory}\nYour personal goal is: {goal}" |
12 | 14 |
|
13 | 15 | yaml = YAML() |
14 | 16 | yaml.preserve_quotes = True # Preserve quotes in existing data |
@@ -67,6 +69,23 @@ def __init__(self, name: str): |
67 | 69 | error_str += f"{' '.join([str(loc) for loc in error['loc']])}: {error['msg']}\n" |
68 | 70 | raise ValidationError(f"Error loading agent {name} from {filename}.\n{error_str}") |
69 | 71 |
|
| 72 | + @property |
| 73 | + def provider(self) -> str: |
| 74 | + return frameworks.parse_llm(self.llm)[0] |
| 75 | + |
| 76 | + @property |
| 77 | + def model(self) -> str: |
| 78 | + return frameworks.parse_llm(self.llm)[1] |
| 79 | + |
| 80 | + @property |
| 81 | + def prompt(self) -> str: |
| 82 | + """Concatenate the prompts for role, goal, and backstory.""" |
| 83 | + return AGENTS_PROMPT_TPL.format(**{ |
| 84 | + 'role': self.role, |
| 85 | + 'goal': self.goal, |
| 86 | + 'backstory': self.backstory, |
| 87 | + }) |
| 88 | + |
70 | 89 | def model_dump(self, *args, **kwargs) -> dict: |
71 | 90 | dump = super().model_dump(*args, **kwargs) |
72 | 91 | dump.pop('name') # name is the key, so keep it out of the data |
@@ -106,3 +125,9 @@ def get_all_agent_names() -> list[str]: |
106 | 125 |
|
107 | 126 | def get_all_agents() -> list[AgentConfig]: |
108 | 127 | return [AgentConfig(name) for name in get_all_agent_names()] |
| 128 | + |
| 129 | + |
| 130 | +def get_agent(name: str) -> Optional[AgentConfig]: |
| 131 | + """Get an agent configuration by name.""" |
| 132 | + return AgentConfig(name) |
| 133 | + |
0 commit comments