Skip to content

Commit 45f9fb3

Browse files
committed
fix: profile agent prompt
1 parent e77e551 commit 45f9fb3

File tree

2 files changed

+109
-55
lines changed

2 files changed

+109
-55
lines changed

examples/preference_agent_demo.py

Lines changed: 101 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -162,57 +162,111 @@ async def demonstrate_profile_analysis(preference_agent, user_history,
162162
display_analysis_results(analyzed_profile)
163163

164164

165-
def display_analysis_results(profile: Dict[str, Any]):
166-
"""Display the analyzed profile results in a readable format."""
167-
165+
def display_analysis_results(profile):
166+
"""Display the analysis results in a formatted way."""
168167
print("\n📊 AI Analysis Results:")
169168
print("=" * 30)
170169

171-
if not profile or 'profile_summary' not in profile:
170+
# Handle both dict and Pydantic model formats
171+
if hasattr(profile, 'profile_summary'):
172+
# Pydantic model format
173+
summary = profile.profile_summary
174+
interests = [interest.value if hasattr(interest, 'value') else str(interest) for interest in summary.interests]
175+
176+
print(f"🎯 Identified Interests ({len(interests)}):")
177+
for interest in interests:
178+
print(f" • {interest}")
179+
180+
# Display preferences
181+
if summary.preferences:
182+
prefs = summary.preferences
183+
print(f"\n✍️ Content Style:")
184+
print(f" Description: {prefs.content_style or 'N/A'}")
185+
186+
# Handle content style tags
187+
content_tags = []
188+
if prefs.content_style_tags:
189+
content_tags = [tag.value if hasattr(tag, 'value') else str(tag) for tag in prefs.content_style_tags]
190+
print(f" Tags: {content_tags}")
191+
192+
print(f"\n💬 Interaction Style:")
193+
print(f" Description: {prefs.interaction_style or 'N/A'}")
194+
195+
# Handle interaction style tags
196+
interaction_tags = []
197+
if prefs.interaction_style_tags:
198+
interaction_tags = [tag.value if hasattr(tag, 'value') else str(tag) for tag in prefs.interaction_style_tags]
199+
print(f" Tags: {interaction_tags}")
200+
201+
# Handle active periods
202+
active_periods = []
203+
if prefs.active_periods:
204+
active_periods = [period.value if hasattr(period, 'value') else str(period) for period in prefs.active_periods]
205+
print(f"\n🕒 Active Periods: {active_periods}")
206+
207+
# Display behavioral summary
208+
if summary.behavioral_summary:
209+
print(f"\n🧠 Behavioral Analysis:")
210+
print(f" {summary.behavioral_summary}")
211+
212+
# Handle behavioral archetype tags
213+
if summary.behavioral_archetype_tags:
214+
behavioral_tags = [tag.value if hasattr(tag, 'value') else str(tag) for tag in summary.behavioral_archetype_tags]
215+
print(f" Archetype Tags: {behavioral_tags}")
216+
217+
# Display community profile
218+
if summary.community_profile:
219+
cp = summary.community_profile
220+
print(f"\n👥 Community Profile:")
221+
print(f" Affinity: {cp.affinity or 'N/A'}")
222+
print(f" Potential Role: {cp.potential_role or 'N/A'}")
223+
224+
# Handle role tags
225+
role_tags = []
226+
if cp.potential_role_tags:
227+
role_tags = [tag.value if hasattr(tag, 'value') else str(tag) for tag in cp.potential_role_tags]
228+
print(f" Role Tags: {role_tags}")
229+
230+
elif isinstance(profile, dict) and 'profile_summary' in profile:
231+
# Original dict format (fallback)
232+
summary = profile['profile_summary']
233+
interests = summary.get('interests', [])
234+
print(f"🎯 Identified Interests ({len(interests)}):")
235+
for interest in interests:
236+
print(f" • {interest}")
237+
238+
# Display preferences
239+
if 'preferences' in summary:
240+
prefs = summary['preferences']
241+
print(f"\n✍️ Content Style:")
242+
print(f" Description: {prefs.get('content_style', 'N/A')}")
243+
print(f" Tags: {prefs.get('content_style_tags', [])}")
244+
245+
print(f"\n💬 Interaction Style:")
246+
print(f" Description: {prefs.get('interaction_style', 'N/A')}")
247+
print(f" Tags: {prefs.get('interaction_style_tags', [])}")
248+
249+
print(f"\n🕒 Active Periods: {prefs.get('active_periods', [])}")
250+
251+
# Display behavioral summary
252+
behavioral_summary = summary.get('behavioral_summary', '')
253+
if behavioral_summary:
254+
print(f"\n🧠 Behavioral Analysis:")
255+
print(f" {behavioral_summary}")
256+
257+
behavioral_tags = summary.get('behavioral_archetype_tags', [])
258+
if behavioral_tags:
259+
print(f" Archetype Tags: {behavioral_tags}")
260+
261+
# Display community profile
262+
if 'community_profile' in summary:
263+
cp = summary['community_profile']
264+
print(f"\n👥 Community Profile:")
265+
print(f" Affinity: {cp.get('affinity', 'N/A')}")
266+
print(f" Potential Role: {cp.get('potential_role', 'N/A')}")
267+
print(f" Role Tags: {cp.get('potential_role_tags', [])}")
268+
else:
172269
print("❌ No valid profile data received")
173-
return
174-
175-
summary = profile['profile_summary']
176-
177-
# Display interests
178-
interests = summary.get('interests', [])
179-
print(f"🎯 Identified Interests ({len(interests)}):")
180-
for interest in interests:
181-
print(f" • {interest}")
182-
183-
# Display preferences
184-
if 'preferences' in summary:
185-
prefs = summary['preferences']
186-
print(f"\n✍️ Content Style:")
187-
print(f" Description: {prefs.get('content_style', 'N/A')}")
188-
print(f" Tags: {prefs.get('content_style_tags', [])}")
189-
190-
print(f"\n💬 Interaction Style:")
191-
print(f" Description: {prefs.get('interaction_style', 'N/A')}")
192-
print(f" Tags: {prefs.get('interaction_style_tags', [])}")
193-
194-
print(f"\n🕒 Active Periods: {prefs.get('active_periods', [])}")
195-
196-
# Display behavioral summary
197-
behavioral_summary = summary.get('behavioral_summary', '')
198-
if behavioral_summary:
199-
print(f"\n🧠 Behavioral Analysis:")
200-
print(f" {behavioral_summary}")
201-
202-
behavioral_tags = summary.get('behavioral_archetype_tags', [])
203-
if behavioral_tags:
204-
print(f" Archetype Tags: {behavioral_tags}")
205-
206-
# Display community profile
207-
if 'community_profile' in summary:
208-
cp = summary['community_profile']
209-
print(f"\n👥 Community Profile:")
210-
print(f" Affinity: {cp.get('affinity', 'N/A')}")
211-
print(f" Potential Role: {cp.get('potential_role', 'N/A')}")
212-
print(f" Role Tags: {cp.get('potential_role_tags', [])}")
213-
214-
print(f"\n💾 Complete Profile Structure:")
215-
print(json.dumps(profile, indent=2, ensure_ascii=False))
216270

217271

218272
async def demonstrate_new_user_scenario(preference_agent):

oasis/user_profile_agent/agent.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _format_user_prompt(self, history: dict, profile: dict,
7575
* **Interaction Style**: Provide a descriptive text. Then, map the findings to 1-2 tags chosen from the EXACT `Valid InteractionStyleEnum Tags` list below.
7676
- **Valid `InteractionStyleEnum` Tags**: "Friendly & Supportive", "Formal & Professional", "Casual & Friendly", "Analytical & Inquisitive", "Supportive & Encouraging", "Humorous & Witty", "Direct & Straightforward", "Thoughtful & Reflective"
7777
* **Active Periods**: Select one or more tags from the EXACT `Valid ActivePeriodEnum Tags` list below.
78-
- **Valid `ActivePeriodEnum` Tags**: "上午", "下午", "晚上", "深夜"
78+
- **Valid `ActivePeriodEnum` Tags**: "Morning", "Afternoon", "Evening", "Night"
7979
8080
4. **Summarize Behavioral Patterns**:
8181
* Provide a qualitative summary text for `behavioral_summary`.
@@ -115,17 +115,17 @@ def _format_user_prompt(self, history: dict, profile: dict,
115115
"profile_summary": {
116116
"interests": ["Business Strategy", "Economics & Markets", "Hospitality Industry"],
117117
"preferences": {
118-
"content_style": "专业深度分析,结合行业经验分享实用见解",
118+
"content_style": "Professional in-depth analysis, sharing practical insights combined with industry experience",
119119
"content_style_tags": ["Professional Insights", "Educational & Tutorials"],
120-
"interaction_style": "正式专业但友好支持,乐于分享经验和建议",
120+
"interaction_style": "Formal and professional yet friendly and supportive, willing to share experience and advice",
121121
"interaction_style_tags": ["Formal & Professional", "Supportive & Encouraging"],
122-
"active_periods": ["下午", "晚上"]
122+
"active_periods": ["Afternoon", "Evening"]
123123
},
124-
"behavioral_summary": "用户表现为经验丰富的行业专家,积极参与专业讨论,乐于分享见解和建议,具有明显的思想领袖特质",
124+
"behavioral_summary": "User demonstrates expertise as an experienced industry professional, actively participating in professional discussions, eager to share insights and advice, with clear thought leadership qualities",
125125
"behavioral_archetype_tags": ["Thought Leader", "Knowledge Seeker"],
126126
"community_profile": {
127-
"affinity": "倾向于加入商业、经济和酒店旅游行业的专业社区,重视知识分享和行业交流",
128-
"potential_role": "在专业社区中担任经验分享者和指导者角色,为新人提供行业见解",
127+
"affinity": "Tends to join professional communities in business, economics, and hospitality industries, values knowledge sharing and industry exchange",
128+
"potential_role": "Acts as an experience sharer and mentor in professional communities, providing industry insights for newcomers",
129129
"potential_role_tags": ["Expert Contributor", "Mentor & Guide"]
130130
}
131131
}
@@ -149,7 +149,7 @@ def _format_user_prompt(self, history: dict, profile: dict,
149149
"content_style_tags": ["Long-form Posts", "Professional Insights"],
150150
"interaction_style": "Their tone is formal and professional, often engaging in inquisitive discussions.",
151151
"interaction_style_tags": ["Formal & Professional", "Analytical & Inquisitive"],
152-
"active_periods": ["晚上", "下午"]
152+
"active_periods": ["Evening", "Afternoon"]
153153
},
154154
"behavioral_summary": "The user follows a pattern of observing first, then engaging deeply as a content creator.",
155155
"behavioral_archetype_tags": ["Content Creator", "Thought Leader"],

0 commit comments

Comments
 (0)