forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_agent_config_agent.py
More file actions
115 lines (92 loc) · 3.44 KB
/
Copy pathtest_agent_config_agent.py
File metadata and controls
115 lines (92 loc) · 3.44 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""Unit tests for agent_config_agent's prompt builder + defensive defaults."""
from src.agents.agent_config_agent import (
DEFAULT_EXPERTISE,
DEFAULT_RESPONSE_LENGTH,
DEFAULT_TONE,
build_system_prompt,
read_properties,
)
def test_read_properties_returns_defaults_when_missing():
result = read_properties(None)
assert result == {
"tone": DEFAULT_TONE,
"expertise": DEFAULT_EXPERTISE,
"response_length": DEFAULT_RESPONSE_LENGTH,
}
def test_read_properties_returns_defaults_when_configurable_missing():
result = read_properties({})
assert result == {
"tone": DEFAULT_TONE,
"expertise": DEFAULT_EXPERTISE,
"response_length": DEFAULT_RESPONSE_LENGTH,
}
def test_read_properties_returns_defaults_when_properties_missing():
result = read_properties({"configurable": {}})
assert result == {
"tone": DEFAULT_TONE,
"expertise": DEFAULT_EXPERTISE,
"response_length": DEFAULT_RESPONSE_LENGTH,
}
def test_read_properties_accepts_valid_values():
result = read_properties(
{
"configurable": {
"properties": {
"tone": "enthusiastic",
"expertise": "expert",
"responseLength": "detailed",
}
}
}
)
assert result == {
"tone": "enthusiastic",
"expertise": "expert",
"response_length": "detailed",
}
def test_read_properties_rejects_invalid_tone_to_default():
result = read_properties({"configurable": {"properties": {"tone": "sinister"}}})
assert result["tone"] == DEFAULT_TONE
def test_read_properties_rejects_invalid_expertise_to_default():
result = read_properties({"configurable": {"properties": {"expertise": "ninja"}}})
assert result["expertise"] == DEFAULT_EXPERTISE
def test_read_properties_rejects_invalid_length_to_default():
result = read_properties(
{"configurable": {"properties": {"responseLength": "epic"}}}
)
assert result["response_length"] == DEFAULT_RESPONSE_LENGTH
def test_read_properties_mixes_valid_and_invalid():
result = read_properties(
{
"configurable": {
"properties": {
"tone": "casual",
"expertise": "unknown",
"responseLength": "detailed",
}
}
}
)
assert result == {
"tone": "casual",
"expertise": DEFAULT_EXPERTISE,
"response_length": "detailed",
}
def test_build_system_prompt_mentions_each_axis():
prompt = build_system_prompt("casual", "expert", "detailed")
assert "Tone:" in prompt
assert "Expertise level:" in prompt
assert "Response length:" in prompt
assert "friendly" in prompt.lower()
assert "technical fluency" in prompt.lower()
assert "multiple paragraphs" in prompt.lower()
def test_build_system_prompt_professional_beginner_concise():
prompt = build_system_prompt("professional", "beginner", "concise")
assert "neutral, precise language" in prompt.lower()
assert "assume no prior knowledge" in prompt.lower()
assert "1-3 sentences" in prompt.lower()
def test_build_system_prompt_enthusiastic_intermediate_concise():
prompt = build_system_prompt("enthusiastic", "intermediate", "concise")
assert "upbeat" in prompt.lower()
assert "specialized terms" in prompt.lower()
assert "1-3 sentences" in prompt.lower()