Created
December 15, 2025 22:23
-
-
Save joerodgers/89bbee8c77f65925a13b5887e94c2d4e to your computer and use it in GitHub Desktop.
Copilot Studio YAML example for custom citations using the OnGeneratedResponse topic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| kind: AdaptiveDialog | |
| beginDialog: | |
| kind: OnGeneratedResponse | |
| id: main | |
| priority: 1 | |
| actions: | |
| - kind: ConditionGroup | |
| id: has-answer-conditions | |
| conditions: | |
| - id: has-answer | |
| condition: =!IsBlank(System.Response.FormattedText) | |
| actions: | |
| - kind: SetVariable | |
| id: setVariable_000001 | |
| displayName: Set Fallback Url | |
| variable: Topic.FallbackUrl | |
| value: https://m365cpi68930152.sharepoint.com/sites/baseball-knowledge/Shared Documents | |
| - kind: SetVariable | |
| id: setVariable_000002 | |
| displayName: Set Citation Count | |
| variable: Topic.CitationCount | |
| value: =CountRows(System.Response.Citations) | |
| - kind: SetVariable | |
| id: setVariable_LKxsRA | |
| displayName: Create File Location Mapping | |
| variable: Topic.FilesSources | |
| value: |- | |
| =[ | |
| { | |
| DataverseFileName: "baseball rules and regs - 2025.pdf", | |
| SharePointFileUrl: "https://m365cpi68930152.sharepoint.com/sites/baseball-knowledge/Shared Documents/2025 - MLB Rules/baseball-2025.pdf" | |
| }, | |
| { | |
| DataverseFileName: "baseball-2019.pdf", | |
| SharePointFileUrl: "https://m365cpi68930152.sharepoint.com/sites/baseball-knowledge/Shared Documents/2019 - MLB Rules/baseball-2019.pdf" | |
| }, | |
| { | |
| DataverseFileName: "baseball-2022.pdf", | |
| SharePointFileUrl: "https://m365cpi68930152.sharepoint.com/sites/baseball-knowledge/Shared Documents/2022 - MLB Rules/baseball-2022.pdf" | |
| } | |
| ] | |
| - kind: SetVariable | |
| id: setVariable_9IFwdP | |
| displayName: "Build Citation Response " | |
| variable: Topic.FormattedCitations | |
| value: |- | |
| =With( | |
| { | |
| CitationsTable: System.Response.Citations | |
| }, | |
| Concat( | |
| ForAll( | |
| Sequence(CountRows(CitationsTable)), | |
| Value | |
| ), | |
| With( | |
| { | |
| currentRecord: Index(CitationsTable,Value) | |
| }, | |
| "[" & Text(Value) & "](" & Text(Value) & ") " & | |
| "[" & currentRecord.Name & "](" & | |
| If( | |
| Not(IsBlank(currentRecord.Url)), | |
| // then - use the provided citation url | |
| Substitute(Lower(currentRecord.Url), " ", "%20"), | |
| // else if - citation name is a url | |
| Find(Lower(currentRecord.Name), "https://"), | |
| // then - use the citation name as the citation url | |
| Substitute(currentRecord.Name," ", "%20" ), | |
| // else if - is citation name is in lookup map | |
| Not(IsBlank(LookUp(Topic.FilesSources, Lower(DataverseFileName) = Lower(currentRecord.Name)))), | |
| // then - use the citation url in the lookup map | |
| Substitute(LookUp(Topic.FilesSources, Lower(DataverseFileName) = Lower(currentRecord.Name), SharePointFileUrl)," ", "%20"), | |
| // else - not in lookup map, use the fallback url | |
| Substitute(Lower(Topic.FallbackUrl), " ", "%20") | |
| ) & | |
| If( | |
| EndsWith(currentRecord.Name, ".pdf" ), | |
| // then - append #page=X to the url to allow direct page access for .pdf files | |
| "#page=" & Mid( | |
| currentRecord.Text, | |
| Find("<page value=", currentRecord.Text ) + Len("<page value=") + 1, | |
| Find( ">", currentRecord.Text ) - Len("<page value=")-3 | |
| ) | |
| ) | |
| & ") " | |
| ), | |
| Char(10) & Char(10) & Char(10) & Char(10) | |
| ) | |
| ) | |
| - kind: SetVariable | |
| id: setVariable_oXDRNa | |
| displayName: Remove Citation Links from Prompt Response | |
| variable: Topic.FormattedResponseNoCitations | |
| value: |- | |
| =If( | |
| IsBlank(Find("[1]: cite", System.Response.FormattedText)), | |
| // then | |
| System.Response.FormattedText, | |
| // else | |
| Left(System.Response.FormattedText, Find("[1]: cite", System.Response.FormattedText) + -1) | |
| ) | |
| - kind: SendActivity | |
| id: sendActivity_svkiBb | |
| activity: RESPONSE {Char(10) & Topic.FormattedResponseNoCitations & Char(10) & Char(10) & Topic.FormattedCitations} | |
| - kind: SetVariable | |
| id: setVariable_ssZuOq | |
| variable: System.ContinueResponse | |
| value: false | |
| inputType: {} | |
| outputType: {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment