This workflow generates and maintains comprehensive sports fan personas based on user metadata and reading history. It leverages historical persona data and AI-powered analysis to create detailed user profiles for content personalization.
+----------------------------------+
| Workflow: User Persona Creation |
+----------------------------------+
|
v
+--------------------------------+
| Get User from PPID |
+--------------------------------+
|
v
+--------------------------------+
| Extract Current Persona |
| - Get existing persona if any |
+--------------------------------+
|
v
+--------------------------------+
| Generate New Persona |
+--------------------------------+
|
v
+--------------------------------+
| Create Persona Document |
| - Store updated persona |
+--------------------------------+
name: Create User Persona
# Define the input schema for the workflow
input_schema:
type: object
properties:
user_ppid:
type: string
articles_read:
type: array
items:
type: string
required:
- user_ppid
- articles_read
# Define the tools that are going to be used in the workflow
tools:
- name: get_user_from_ppid
description: Get a user from the user ppid
type: system
system:
resource: user
operation: list
- name: list_user_docs
description: List the user docs
type: system
system:
resource: user
subresource: doc
operation: list
- name: create_user_doc
description: Create a user doc
type: system
system:
resource: user
subresource: doc
operation: create
main:
# Get the user from the ppid using metadata_filter (returns a list)
- tool: get_user_from_ppid
arguments:
metadata_filter:
ppid: inputs[0].user_ppid
# Unwrap the list to get the user
- evaluate:
user: outputs[0][0]
# Get the user persona document using metadata_filter (returns a list)
- tool: list_user_docs
arguments:
user_id: outputs[1].user.id
limit: 1
# Get the doc if it exists
- evaluate:
doc: outputs[2][0] if len(outputs[2]) > 0 else {}
# Get the user persona from the doc if the doc exists
- evaluate:
user_persona: outputs[3].get('content', "")
# Create the user persona using the prompt step
- prompt:
- role: user
content: |
Create a comprehensive sports fan persona based on the provided user data and article reads
User details:
$$_ outputs[1].user.metadata
User reading history:
$$_ inputs[0].articles_read
User past persona:
$$_ outputs[2].content
unwrap: true
# Create a new persona document
- tool: create_user_doc
arguments:
user_id: outputs[1].user.id
data:
embed_instruction: "'Represent the query for User persona used for document retrieval: '"
title: "'User Persona'"
content: outputs[4]
This workflow enables personalized sports article recommendations based on user personas and hybrid search capabilities. It combines user profiling, document embeddings, and AI-powered ranking to deliver tailored news content for sports enthusiasts.
+------------------------------------+
| Workflow: News Article Recommender |
+------------------------------------+
|
v
+--------------------------------+
| Get User from PPID |
+--------------------------------+
|
v
+--------------------------------+
| Get User Documents |
+--------------------------------+
|
v
+--------------------------------+
| Extract User Information |
| - User Embedding |
| - User Persona |
+--------------------------------+
|
v
+---------------------------------+
| Hybrid Search Docs (top 50 doc) |
| |
| - Vector search |
| - Text search |
+---------------------------------+
|
v
+--------------------------------+
| AI Selection of Top 5 |
| - Rank articles |
| - Diversify across sports |
| - Consider user persona |
+--------------------------------+
|
v
+--------------------------------+
| Generate Newsletter Title |
+--------------------------------+
|
v
+--------------------------------+
| Final Output |
| - Newsletter title |
| - Top 5 article titles |
+--------------------------------+
name: Recommend News Articles
input_schema:
type: object
properties:
user_ppid:
type: string
tools:
- name: get_user_from_ppid
description: Get a user from the user ppid
type: system
system:
resource: user
operation: list
- name: get_user_docs
description: Get user docs
type: system
system:
resource: user
subresource: doc
operation: list
- name : search_agent_docs
description: Get agent docs
type: system
system:
resource: agent
subresource: doc
operation: search
main:
# Get the user from the ppid using metadata_filter (returns a list)
- tool: get_user_from_ppid
arguments:
metadata_filter:
ppid: inputs[0].user_ppid
# Unwrap the list to get the user
- evaluate:
user: outputs[0][0]
# Get the user docs
- tool: get_user_docs
arguments:
user_id: outputs[1].user.id
sort_by: "'created_at'"
direction: "'desc'"
# Get the user persona
- evaluate:
user_embedding: outputs[2][0].embeddings[0]
persona: outputs[2][0].content[0]
# Hybrid search for docs using the user persona
- tool: search_agent_docs
arguments:
vector: outputs[3].user_embedding
text: outputs[3].persona
agent_id: inputs[0].agent_id
# Get top 50 matching docs
- if: "len(outputs[4].docs) > 0"
then:
evaluate:
top_titles: "[doc.title for doc in outputs[4].docs[:50]]"
else:
return:
newsletter_title: "'No recommendations found'"
titles: "[]"
# Filter out the top 5 articles
- prompt:
- role: user
content: >-
Rank and return the top 5 most relevant article titles as YAML.
Diversify across different sports, based on the user's persona.
User persona:
{{outputs[3].persona}}
Top 5 articles:
{{outputs[5].top_titles}}
unwrap: true
- evaluate:
titles: extract_yaml_content(outputs[6]).articles
# Generate a newsletter title
- prompt:
- role: user
content: >-
Draft a catchy newsletter title based on these 5 titles for sports news articles
Top 5 articles:
$$_ outputs[7].titles
User persona:
$$_ outputs[3].persona
unwrap: true
# Return the newsletter title and the top 5 articles
- evaluate:
newsletter_title: outputs[8]
titles: outputs[7].get('titles', [])