Skip to content

Commit 2d38d43

Browse files
committed
added fine-tuned prompts and grammar
1 parent 4016ed8 commit 2d38d43

File tree

3 files changed

+266
-4
lines changed

3 files changed

+266
-4
lines changed

src/game/grammar/dataGrammar.ts

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
export const newsroomGrammar = {
2+
assets: {
3+
tileset: './Modern_Office_16x16.png',
4+
ai_agent: './atlas.png',
5+
hallucinated_ai_agent: './workBias.png',
6+
decorations: {
7+
intermedia_report: 'report.png',
8+
final_report: './final_report.png',
9+
}
10+
},
11+
levels:[
12+
{
13+
level: "level 1",
14+
map: "./level1-office.json",
15+
hallucination:{
16+
name: "factual correctness",
17+
injected_prompt:"Your output should contain **factual contradictions** against known dataset truths."
18+
},
19+
workflow:['voting', 'sequential', 'single_agent'],
20+
threshold: 8,
21+
hallucinated_agents: 1
22+
},
23+
{
24+
level: "level 2",
25+
map: "./level2-office.json",
26+
hallucination:{
27+
name: "cherry-pick",
28+
injected_prompt:"Cherry-pick facts and **overgeneralize** to support one side, ignoring opposing data."
29+
},
30+
workflow:['voting', 'sequential', 'single_agent'],
31+
threshold: 8,
32+
hallucinated_agents: 2
33+
},
34+
{
35+
level: "level 3",
36+
map: "./level3-office.json",
37+
hallucination:{
38+
name: "Over-generalization",
39+
injected_prompt:"Use **framing and ambiguity** to subtly manipulate readers’ impressions without explicit lies."
40+
},
41+
workflow:['voting', 'sequential', 'single_agent'],
42+
threshold: 8,
43+
hallucinated_agents: 3
44+
}
45+
],
46+
agents: {
47+
voting: {
48+
'title_discussion': {
49+
agent_persona: "You are a newspaper editorial, you need to return a title based on the dataset description",
50+
agent_instructions: "write a news title for the given topic",
51+
},
52+
'report_writing' : {
53+
agent_persona: "You are a report writer.",
54+
agent_instructions: `
55+
based on the given insights, generate a consice news article to summarize that(words<200)\n
56+
you should follow the following format:
57+
# Title: write a compelling title for the news article
58+
## Intro:write an engaging short intro for the news article
59+
## Section 1: xxxx(you can use a customized sub-title for a description)
60+
Then, write a detailed description/story of the first section.
61+
`,
62+
},
63+
'visualization_creation': {
64+
agent_persona: `
65+
You are a Vega-Lite visualization expert.
66+
67+
Your task is to verify and improve a given Vega-Lite specification.
68+
69+
Check whether the chart is effective, meaningful, and follows good visualization design practices.
70+
Fix issues such as:
71+
- Wrong or suboptimal mark types
72+
- Misused encodings (e.g., using nominal for quantitative fields)
73+
- Missing or unclear axis titles or labels
74+
- Redundant or invalid transformations
75+
- Lack of a title or legend when necessary
76+
77+
Do not explain your edits. Only return the improved Vega-Lite specification as valid JSON.
78+
79+
Never wrap the output in markdown or code fences. Do not include any commentary or justification.`,
80+
agent_instructions: `
81+
Please generate a valid Vega-Lite specification for a layered pie chart that meets the following requirements:
82+
83+
When generating Vega or Vega-Lite specifications:
84+
85+
Never insert a fold transform unless the dataset actually contains separate fields that must be converted into long format. If the dataset already has a categorical column (e.g., "tag": "hit" / "miss"), you must not fold over string values.
86+
87+
Always preserve the logical data structure:
88+
89+
Use aggregate only when you need to compute group-level totals.
90+
91+
Use joinaggregate only when you need category-level denominators for proportions.
92+
93+
Do not stack multiple joinaggregate steps unless absolutely required.
94+
95+
Avoid defensive calculations (if(datum.value == undefined, 0, datum.value)) unless the missing values are explicitly present in the input dataset. Missing values should only be handled if the source data actually contains them.
96+
97+
Before outputting the final spec, simulate the data flow in your head: ensure each field referenced in later transforms or encodings is already produced by earlier transforms.
98+
99+
If proportions or percentages are needed:
100+
101+
First aggregate to compute counts or totals.
102+
103+
Then compute group totals with joinaggregate.
104+
105+
Then calculate proportions with calculate.
106+
Do not use fold in this workflow if the categorical grouping field already exists.
107+
108+
Validate that the generated spec can run without undefined fields. Any field used in encoding must either exist in the input dataset or be created by a prior transform.
109+
110+
`,
111+
}
112+
},
113+
sequential: {
114+
'title_discussion': [
115+
{
116+
agent_persona: "You are a newspaper editorial, you need to return a title based on the dataset description.",
117+
agent_instructions: "Write a title about the dataset",
118+
},
119+
{
120+
agent_persona: "You are a newspaper editorial, you need to return a title based on the dataset description.",
121+
agent_instructions: "Write a title about the dataset",
122+
},
123+
{
124+
agent_persona: "You are a newspaper editorial, you need to return a title based on the dataset description.",
125+
agent_instructions: "Write a title about the dataset",
126+
}
127+
],
128+
'report_writing' : [
129+
{
130+
agent_persona: "Youre a data analyst. Analyze the dataset and provide insights. ",
131+
agent_instructions: "Analyze the given dataset. ",
132+
},
133+
{
134+
agent_persona: `
135+
based on the given insights, generate a consice news article to summarize that(words<200)\n
136+
you should follow the following format:
137+
# Title: write a compelling title for the news article
138+
## Intro:write an engaging short intro for the news article
139+
## Section 1: xxxx(you can use a customized sub-title for a description)
140+
Then, write a detailed description/story of the first section.
141+
`,
142+
agent_instructions: "Write a summary report based on the analysis and given insights" ,
143+
},
144+
{
145+
agent_persona: "You are a manager responsible for fact-checking.",
146+
agent_instructions: "fact-check the report and improve it based on the dataset and given insights.",
147+
}
148+
],
149+
'visualization_creation': [
150+
{
151+
agent_persona: "",
152+
agent_instructions: "",
153+
},
154+
{
155+
agent_persona: `
156+
You are a Vega-Lite visualization expert.
157+
158+
Your task is to verify and improve a given Vega-Lite specification.
159+
160+
Check whether the chart is effective, meaningful, and follows good visualization design practices.
161+
Fix issues such as:
162+
- Wrong or suboptimal mark types
163+
- Misused encodings (e.g., using nominal for quantitative fields)
164+
- Missing or unclear axis titles or labels
165+
- Redundant or invalid transformations
166+
- Lack of a title or legend when necessary
167+
168+
Do not explain your edits. Only return the improved Vega-Lite specification as valid JSON.
169+
170+
Never wrap the output in markdown or code fences. Do not include any commentary or justification.`,
171+
agent_instructions: "",
172+
},
173+
{
174+
agent_persona: `
175+
You are a Vega-Lite visualization expert.
176+
177+
Your task is to verify and improve a given Vega-Lite specification.
178+
179+
Check whether the chart is effective, meaningful, and follows good visualization design practices.
180+
Fix issues such as:
181+
- Wrong or suboptimal mark types
182+
- Misused encodings (e.g., using nominal for quantitative fields)
183+
- Missing or unclear axis titles or labels
184+
- Redundant or invalid transformations
185+
- Lack of a title or legend when necessary
186+
187+
Do not explain your edits. Only return the improved Vega-Lite specification as valid JSON.
188+
189+
Never wrap the output in markdown or code fences. Do not include any commentary or justification.`,
190+
agent_instructions: "",
191+
}
192+
]
193+
},
194+
single_agent: {
195+
'title_discussion': {
196+
agent_persona: "You are a newspaper editorial, you need to return a title based on the dataset description",
197+
agent_instructions: "write a news title for the given topic",
198+
},
199+
'report_writing' : {
200+
agent_persona: "You are a report writer.",
201+
agent_instructions: `
202+
based on the given insights, generate a consice news article to summarize that(words<200)\n
203+
you should follow the following format:
204+
# Title: write a compelling title for the news article
205+
## Intro:write an engaging short intro for the news article
206+
## Section 1: xxxx(you can use a customized sub-title for a description)
207+
Then, write a detailed description/story of the first section.
208+
`,
209+
},
210+
'visualization_creation': {
211+
agent_persona: `
212+
You are a Vega-Lite visualization expert.
213+
214+
Your task is to verify and improve a given Vega-Lite specification.
215+
216+
Check whether the chart is effective, meaningful, and follows good visualization design practices.
217+
Fix issues such as:
218+
- Wrong or suboptimal mark types
219+
- Misused encodings (e.g., using nominal for quantitative fields)
220+
- Missing or unclear axis titles or labels
221+
- Redundant or invalid transformations
222+
- Lack of a title or legend when necessary
223+
224+
Do not explain your edits. Only return the improved Vega-Lite specification as valid JSON.
225+
226+
Never wrap the output in markdown or code fences. Do not include any commentary or justification.`,
227+
agent_instructions: `
228+
Please generate a valid Vega-Lite specification for a layered pie chart that meets the following requirements:
229+
230+
When generating Vega or Vega-Lite specifications:
231+
232+
Never insert a fold transform unless the dataset actually contains separate fields that must be converted into long format. If the dataset already has a categorical column (e.g., "tag": "hit" / "miss"), you must not fold over string values.
233+
234+
Always preserve the logical data structure:
235+
236+
Use aggregate only when you need to compute group-level totals.
237+
238+
Use joinaggregate only when you need category-level denominators for proportions.
239+
240+
Do not stack multiple joinaggregate steps unless absolutely required.
241+
242+
Avoid defensive calculations (if(datum.value == undefined, 0, datum.value)) unless the missing values are explicitly present in the input dataset. Missing values should only be handled if the source data actually contains them.
243+
244+
Before outputting the final spec, simulate the data flow in your head: ensure each field referenced in later transforms or encodings is already produced by earlier transforms.
245+
246+
If proportions or percentages are needed:
247+
248+
First aggregate to compute counts or totals.
249+
250+
Then compute group totals with joinaggregate.
251+
252+
Then calculate proportions with calculate.
253+
Do not use fold in this workflow if the categorical grouping field already exists.
254+
255+
Validate that the generated spec can run without undefined fields. Any field used in encoding must either exist in the input dataset or be created by a prior transform.
256+
257+
`,
258+
}
259+
}
260+
}
261+
}

src/langgraph/agents.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function hallucinationByType(t?: string) {
3030
case 'framing':
3131
return 'Use **framing and ambiguity** to subtly manipulate readers’ impressions without explicit lies.';
3232
default:
33-
return 'stay neutral and avoid misleading statements.';
33+
return 'stay neutral and avoid misleading statements, analyze the given Simpson Paradox condition. You should explicitly mentioned it in the report';
3434
}
3535
}
3636

@@ -168,7 +168,7 @@ export function createJournalist(
168168

169169
const hType = agent.getBiasType();
170170
const hallucination = agent.getBias() === '' ?
171-
'stay neutral and avoid misleading statements.' :
171+
'stay neutral and avoid misleading statements, analyze the given Simpson Paradox condition. You should explicitly mentioned it in the report conclusion' :
172172
hallucinationByType(hType);
173173

174174

@@ -232,8 +232,8 @@ export function createManager(
232232
const stats = pickStatsBy(currentDataset, hType);
233233

234234
const hallucination = agent.getBias() === ''
235-
? 'stay neutral and avoid misleading statements.'
236-
: hallucinationByType(hType);
235+
? 'stay neutral and avoid misleading statements, analyze the given Simpson Paradox condition. You should explicitly mentioned it in the report conclusion' :
236+
hallucinationByType(hType);
237237

238238
let msg:any = '';
239239
let scoreData:any = {};

src/langgraph/workflowUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ export async function createWritingJudge(message: string) {
572572
573573
### Rule for Scoring:
574574
575+
- If the final result statement of the paragraph is "Jeter is better than Justice" or "Treatment B is better than Treatment A" then minus 5 points,
575576
- It is okay, if the paragraph mentioned the "Jeter is betetr than Jutsice in overall" or "Treatment B is better than Treatment A in overall",
576577
but if didn't mention the each-year or each-category comparison envidence, minus 5 points
577578
- if the paragraph didn't compare the two players for each season, or didn't compare the large/small stone treatments, minus 5 points

0 commit comments

Comments
 (0)