Skip to content

Commit fb3d1d3

Browse files
committed
improving RouterAgent instructions, better logging, upgrade to gpt4-o-2024-11-20
1 parent 4308d9b commit fb3d1d3

File tree

16 files changed

+85
-133
lines changed

16 files changed

+85
-133
lines changed

app/business-api/account/src/main/java/com/microsoft/openai/samples/assistant/business/service/AccountService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public AccountService() {
2828
"Alice User",
2929
"USD",
3030
"2022-01-01",
31-
"1000.00",
31+
"5000",
3232
Arrays.asList(new PaymentMethodSummary("12345", "Visa", "2022-01-01", "2025-01-01"),
3333
new PaymentMethodSummary("23456", "BankTransfer", "2022-01-01", "9999-01-01"))));
3434
this.accounts.put("1010", new Account(
@@ -37,16 +37,16 @@ public AccountService() {
3737
"Bob User",
3838
"EUR",
3939
"2022-01-01",
40-
"2000,40",
40+
"10000",
4141
Arrays.asList(new PaymentMethodSummary("345678", "BankTransfer", "2022-01-01", "9999-01-01"),
42-
new PaymentMethodSummary("55555", "Visa", "2022-01-01", "2025-01-01"))));
42+
new PaymentMethodSummary("55555", "Visa", "2022-01-01", "2026-01-01"))));
4343
this.accounts.put("1020", new Account(
4444
"1020",
4545
"charlie.user@contoso.com",
4646
"Charlie User",
4747
"EUR",
4848
"2022-01-01",
49-
"3000,20",
49+
"3000",
5050
Arrays.asList(new PaymentMethodSummary("46748576", "DirectDebit", "2022-02-01", "9999-02-01"))));
5151

5252
this.paymentMethods.put("12345", new PaymentMethod("12345", "Visa", "2022-01-01", "2025-01-01", "500.00", "1234567812345678"));

app/business-api/account/src/main/java/com/microsoft/openai/samples/assistant/business/service/UserService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public UserService() {
2121
"Alice User",
2222
"USD",
2323
"2022-01-01",
24-
"1000.00",
24+
"5000",
2525
null
2626
)
2727
);
@@ -33,7 +33,7 @@ public UserService() {
3333
"Bob User",
3434
"EUR",
3535
"2022-01-01",
36-
"2000,40",
36+
"10000",
3737
null
3838
)
3939
);
@@ -45,7 +45,7 @@ public UserService() {
4545
"Charlie User",
4646
"EUR",
4747
"2022-01-01",
48-
"3000,20",
48+
"3000",
4949
null
5050
)
5151
);

app/business-api/transactions-history/src/main/java/com/microsoft/openai/samples/assistant/business/TransactionService.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ public class TransactionService {
1515
public TransactionService(){
1616

1717
lastTransactions.put("1010",new ArrayList<> (Arrays.asList(
18-
new Transaction("11", "Payment of the bill 334398", "outcome","Mike ThePlumber", "0001", "1010", "BankTransfer", "100.00", "2024-4-01T12:00:00Z"),
19-
new Transaction("22", "Payment of the bill 4613","outcome", "Jane TheElectrician", "0002", "1010", "CreditCard", "200.00", "2024-3-02T12:00:00Z"),
20-
new Transaction("33", "Payment of the bill 724563","outcome", "Bob TheCarpenter", "0003", "1010", "BankTransfer", "300.00", "2023-10-03T12:00:00Z"),
21-
new Transaction("43", "Payment of the bill 8898943","outcome", "Alice ThePainter", "0004", "1010", "DirectDebit", "400.00", "2023-8-04T12:00:00Z"),
22-
new Transaction("53", "Payment of the bill 19dee","outcome", "Charlie TheMechanic", "0005", "1010", "BankTransfer", "500.00", "2023-4-05T12:00:00Z"))
18+
new Transaction("11", "Payment of the bill 334398", "outcome","acme", "0001", "1010", "BankTransfer", "100.00", "2024-4-01T12:00:00Z"),
19+
new Transaction("22", "Payment of the bill 4613","outcome", "contoso", "0002", "1010", "CreditCard", "200.00", "2024-3-02T12:00:00Z"),
20+
new Transaction("33", "Payment of the bill 724563","outcome", "duff", "0003", "1010", "BankTransfer", "300.00", "2023-10-03T12:00:00Z"),
21+
new Transaction("43", "Payment of the bill 8898943","outcome", "wayne enterprises", "0004", "1010", "DirectDebit", "400.00", "2023-8-04T12:00:00Z"),
22+
new Transaction("53", "Payment of the bill 19dee","outcome", "oscorp", "0005", "1010", "BankTransfer", "500.00", "2023-4-05T12:00:00Z"))
2323
));
2424

2525

2626
allTransactions.put("1010",new ArrayList<>(Arrays.asList(
27-
new Transaction("11", "payment of bill id with 0001","outcome", "Mike ThePlumber", "A012TABTYT156!", "1010", "BankTransfer", "100.00", "2024-4-01T12:00:00Z"),
28-
new Transaction("21", "Payment of the bill 4200","outcome", "Mike ThePlumber", "0002", "1010", "BankTransfer", "200.00", "2024-1-02T12:00:00Z"),
29-
new Transaction("31", "Payment of the bill 3743","outcome", "Mike ThePlumber", "0003", "1010", "DirectDebit", "300.00", "2023-10-03T12:00:00Z"),
30-
new Transaction("41", "Payment of the bill 8921","outcome", "Mike ThePlumber", "0004", "1010", "Transfer", "400.00", "2023-8-04T12:00:00Z"),
31-
new Transaction("51", "Payment of the bill 7666","outcome", "Mike ThePlumber", "0005", "1010", "CreditCard", "500.00", "2023-4-05T12:00:00Z"),
32-
33-
new Transaction("12", "Payment of the bill 5517","outcome", "Jane TheElectrician", "0001", "1010", "CreditCard", "100.00", "2024-3-01T12:00:00Z"),
34-
new Transaction("22", "Payment of the bill 682222","outcome", "Jane TheElectrician", "0002", "1010", "CreditCard", "200.00", "2023-1-02T12:00:00Z"),
35-
new Transaction("32", "Payment of the bill 94112","outcome", "Jane TheElectrician", "0003", "1010", "Transfer", "300.00", "2022-10-03T12:00:00Z"),
36-
new Transaction("42", "Payment of the bill 23122","outcome", "Jane TheElectrician", "0004", "1010", "Transfer", "400.00", "2022-8-04T12:00:00Z"),
37-
new Transaction("52", "Payment of the bill 171443","outcome", "Jane TheElectrician", "0005", "1010", "Transfer", "500.00", "2020-4-05T12:00:00Z")
27+
new Transaction("11", "payment of bill id with 0001","outcome", "acme", "A012TABTYT156!", "1010", "BankTransfer", "100.00", "2024-4-01T12:00:00Z"),
28+
new Transaction("21", "Payment of the bill 4200","outcome", "acme", "0002", "1010", "BankTransfer", "200.00", "2024-1-02T12:00:00Z"),
29+
new Transaction("31", "Payment of the bill 3743","outcome", "acme", "0003", "1010", "DirectDebit", "300.00", "2023-10-03T12:00:00Z"),
30+
new Transaction("41", "Payment of the bill 8921","outcome", "acme", "0004", "1010", "Transfer", "400.00", "2023-8-04T12:00:00Z"),
31+
new Transaction("51", "Payment of the bill 7666","outcome", "acme", "0005", "1010", "CreditCard", "500.00", "2023-4-05T12:00:00Z"),
32+
33+
new Transaction("12", "Payment of the bill 5517","outcome", "contoso", "0001", "1010", "CreditCard", "100.00", "2024-3-01T12:00:00Z"),
34+
new Transaction("22", "Payment of the bill 682222","outcome", "contoso", "0002", "1010", "CreditCard", "200.00", "2023-1-02T12:00:00Z"),
35+
new Transaction("32", "Payment of the bill 94112","outcome", "contoso", "0003", "1010", "Transfer", "300.00", "2022-10-03T12:00:00Z"),
36+
new Transaction("42", "Payment of the bill 23122","outcome", "contoso", "0004", "1010", "Transfer", "400.00", "2022-8-04T12:00:00Z"),
37+
new Transaction("52", "Payment of the bill 171443","outcome", "contoso", "0005", "1010", "Transfer", "500.00", "2020-4-05T12:00:00Z")
3838
)));
3939

4040

app/copilot/copilot-backend/src/main/java/com/microsoft/openai/samples/assistant/agent/AccountAgent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import com.azure.ai.openai.OpenAIAsyncClient;
55
import com.microsoft.openai.samples.assistant.agent.cache.ToolExecutionCacheKey;
6-
import com.microsoft.openai.samples.assistant.agent.cache.InMemoryToolsExecutionCache;
76
import com.microsoft.openai.samples.assistant.agent.cache.ToolExecutionCacheUtils;
87
import com.microsoft.openai.samples.assistant.agent.cache.ToolsExecutionCache;
98
import com.microsoft.openai.samples.assistant.plugin.LoggedUserPlugin;
@@ -65,7 +64,7 @@ public AccountAgent(OpenAIAsyncClient client, LoggedUserService loggedUserServic
6564
String accountsAPIYaml = null;
6665
try {
6766
accountsAPIYaml = EmbeddedResourceLoader.readFile("account.yaml",
68-
HistoryReportingAgent.class,
67+
TransactionsReportingAgent.class,
6968
EmbeddedResourceLoader.ResourceLocation.CLASSPATH_ROOT);
7069
} catch (FileNotFoundException e) {
7170
throw new RuntimeException("Cannot find account-history.yaml file in the classpath", e);
@@ -86,7 +85,7 @@ public AccountAgent(OpenAIAsyncClient client, LoggedUserService loggedUserServic
8685
.build();
8786

8887
FunctionInvokedHook postExecutionHandler = event -> {
89-
LOGGER.info("Adding {} result to the cache:{}", event.getFunction().getName(),event.getResult().getResult());
88+
LOGGER.debug("Adding {} result to the cache:{}", event.getFunction().getName(),event.getResult().getResult());
9089
var tollsExecutionKey = new ToolExecutionCacheKey(loggedUserService.getLoggedUser().username(),null,event.getFunction().getName(),ToolExecutionCacheUtils.convert(event.getArguments()));
9190
this.toolsExecutionCache.put(tollsExecutionKey , event.getResult().getResult());
9291
return event;
@@ -135,6 +134,7 @@ public void run (ChatHistory userChatHistory, AgentContext agentContext){
135134
//get last message
136135
var message = messages.get(messages.size()-1);
137136

137+
LOGGER.info("======== Account Agent Response: {}",message.getContent());
138138
agentContext.setResult(message.getContent());
139139

140140
}
Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import com.azure.ai.openai.OpenAIAsyncClient;
55
import com.azure.ai.openai.OpenAIClientBuilder;
6-
import com.azure.ai.openai.models.ChatRequestUserMessage;
76
import com.azure.core.credential.AzureKeyCredential;
87
import com.azure.core.http.policy.HttpLogDetailLevel;
98
import com.azure.core.http.policy.HttpLogOptions;
@@ -12,14 +11,10 @@
1211
import com.microsoft.semantickernel.orchestration.*;
1312
import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService;
1413
import com.microsoft.semantickernel.services.chatcompletion.ChatHistory;
15-
import com.microsoft.semantickernel.services.chatcompletion.ChatMessageContent;
1614
import org.json.JSONException;
1715
import org.json.JSONObject;
1816

19-
import java.util.ArrayList;
20-
import java.util.List;
21-
22-
public class IntentAgent {
17+
public class IntentExtractor {
2318

2419
private OpenAIAsyncClient client;
2520

@@ -46,7 +41,7 @@ public class IntentAgent {
4641
4742
""";
4843

49-
public IntentAgent(OpenAIAsyncClient client, String modelId){
44+
public IntentExtractor(OpenAIAsyncClient client, String modelId){
5045
this.client = client;
5146
this.chat = OpenAIChatCompletion.builder()
5247
.withModelId(modelId)
@@ -57,24 +52,8 @@ public IntentAgent(OpenAIAsyncClient client, String modelId){
5752
.withAIService(ChatCompletionService.class, chat)
5853
.build();
5954
}
60-
public IntentAgent(String azureClientKey, String clientEndpoint, String modelId){
61-
this.client = new OpenAIClientBuilder()
62-
.credential(new AzureKeyCredential(azureClientKey))
63-
.endpoint(clientEndpoint)
64-
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
65-
.buildAsyncClient();
66-
67-
this.chat = OpenAIChatCompletion.builder()
68-
.withModelId(modelId)
69-
.withOpenAIAsyncClient(client)
70-
.build();
71-
72-
kernel = Kernel.builder()
73-
.withAIService(ChatCompletionService.class, chat)
74-
.build();
75-
}
7655

77-
public IntentResponse run(ChatHistory userChatHistory,AgentContext agentContext){
56+
public IntentResponse run(ChatHistory userChatHistory){
7857
var agentChatHistory = new ChatHistory(INTENT_SYSTEM_MESSAGE);
7958
agentChatHistory.addAll(fewShotExamples());
8059
agentChatHistory.addAll(userChatHistory);
@@ -121,7 +100,9 @@ ChatHistory fewShotExamples(){
121100
.addUserMessage("can you buy stocks for me?")
122101
.addAssistantMessage("{\"intent\": \"None\", \"clarify_sentence\":\"I'm sorry can't help with that.I can review your account details, transactions and help you with your payments\"")
123102
.addUserMessage("can you pay this bill for me?")
124-
.addAssistantMessage("{\"intent\": \"BillPayment\" }");
103+
.addAssistantMessage("{\"intent\": \"BillPayment\" }")
104+
.addUserMessage("when was last time I paid acme")
105+
.addAssistantMessage("{\"intent\": \"TransactionHistory\" }");
125106
}
126107

127108
}

app/copilot/copilot-backend/src/main/java/com/microsoft/openai/samples/assistant/agent/PaymentAgent.java

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,16 @@
33

44
import com.azure.ai.documentintelligence.DocumentIntelligenceClient;
55
import com.azure.ai.openai.OpenAIAsyncClient;
6-
import com.azure.ai.openai.OpenAIClientBuilder;
7-
import com.azure.core.credential.AzureKeyCredential;
8-
import com.azure.core.http.policy.HttpLogDetailLevel;
9-
import com.azure.core.http.policy.HttpLogOptions;
106
import com.microsoft.openai.samples.assistant.agent.cache.ToolExecutionCacheKey;
117
import com.microsoft.openai.samples.assistant.agent.cache.ToolExecutionCacheUtils;
128
import com.microsoft.openai.samples.assistant.agent.cache.ToolsExecutionCache;
13-
import com.microsoft.openai.samples.assistant.controller.ChatController;
149
import com.microsoft.openai.samples.assistant.invoice.DocumentIntelligenceInvoiceScanHelper;
1510
import com.microsoft.openai.samples.assistant.plugin.InvoiceScanPlugin;
1611
import com.microsoft.openai.samples.assistant.plugin.LoggedUserPlugin;
17-
import com.microsoft.openai.samples.assistant.plugin.PaymentPlugin;
18-
import com.microsoft.openai.samples.assistant.plugin.TransactionHistoryPlugin;
1912
import com.microsoft.openai.samples.assistant.proxy.BlobStorageProxy;
2013
import com.microsoft.openai.samples.assistant.security.LoggedUserService;
2114
import com.microsoft.semantickernel.Kernel;
2215
import com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIChatCompletion;
23-
import com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIChatMessageContent;
24-
import com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIFunctionToolCall;
25-
import com.microsoft.semantickernel.contextvariables.CaseInsensitiveMap;
26-
import com.microsoft.semantickernel.contextvariables.ContextVariable;
2716
import com.microsoft.semantickernel.hooks.KernelHook;
2817
import com.microsoft.semantickernel.implementation.EmbeddedResourceLoader;
2918
import com.microsoft.semantickernel.orchestration.*;
@@ -37,11 +26,8 @@
3726
import org.slf4j.LoggerFactory;
3827

3928
import java.io.FileNotFoundException;
40-
import java.nio.charset.StandardCharsets;
4129
import java.time.ZoneId;
4230
import java.time.ZonedDateTime;
43-
import java.util.List;
44-
import java.util.stream.Collectors;
4531

4632
public class PaymentAgent {
4733
private static final Logger LOGGER = LoggerFactory.getLogger(PaymentAgent.class);
@@ -91,14 +77,14 @@ public PaymentAgent(OpenAIAsyncClient client, LoggedUserService loggedUserServic
9177
.withAIService(ChatCompletionService.class, chat)
9278
.build();
9379

94-
//var paymentPlugin = KernelPluginFactory.createFromObject(new PaymentPlugin(), "PaymentPlugin");
95-
//var historyPlugin = KernelPluginFactory.createFromObject(new TransactionHistoryPlugin(), "TransactionHistoryPlugin");
80+
//var paymentPlugin = KernelPluginFactory.createFromObject(new PaymentMockPlugin(), "PaymentMockPlugin");
81+
//var historyPlugin = KernelPluginFactory.createFromObject(new TransactionHistoryMockPlugin(), "TransactionHistoryMockPlugin");
9682
var invoiceScanPlugin = KernelPluginFactory.createFromObject(new InvoiceScanPlugin(new DocumentIntelligenceInvoiceScanHelper(documentIntelligenceClient,blobStorageProxy)), "InvoiceScanPlugin");
9783

9884
String transactionsAPIYaml = null;
9985
try {
10086
transactionsAPIYaml = EmbeddedResourceLoader.readFile("transaction-history.yaml",
101-
HistoryReportingAgent.class,
87+
TransactionsReportingAgent.class,
10288
EmbeddedResourceLoader.ResourceLocation.CLASSPATH_ROOT);
10389
} catch (FileNotFoundException e) {
10490
throw new RuntimeException("Cannot find transaction-history.yaml file in the classpath",e);
@@ -107,7 +93,7 @@ public PaymentAgent(OpenAIAsyncClient client, LoggedUserService loggedUserServic
10793
//Used to retrieve transactions.
10894
KernelPlugin openAPIImporterTransactionPlugin = SemanticKernelOpenAPIImporter
10995
.builder()
110-
.withPluginName("TransactionHistoryPlugin")
96+
.withPluginName("TransactionHistoryMockPlugin")
11197
.withSchema(transactionsAPIYaml)
11298
.withServer(transactionAPIUrl)
11399
.build();
@@ -116,7 +102,7 @@ public PaymentAgent(OpenAIAsyncClient client, LoggedUserService loggedUserServic
116102
String accountsAPIYaml = null;
117103
try {
118104
accountsAPIYaml = EmbeddedResourceLoader.readFile("account.yaml",
119-
HistoryReportingAgent.class,
105+
TransactionsReportingAgent.class,
120106
EmbeddedResourceLoader.ResourceLocation.CLASSPATH_ROOT);
121107
} catch (FileNotFoundException e) {
122108
throw new RuntimeException("Cannot find account-history.yaml file in the classpath",e);
@@ -132,7 +118,7 @@ public PaymentAgent(OpenAIAsyncClient client, LoggedUserService loggedUserServic
132118
String paymentsAPIYaml = null;
133119
try {
134120
paymentsAPIYaml = EmbeddedResourceLoader.readFile("payments.yaml",
135-
HistoryReportingAgent.class,
121+
TransactionsReportingAgent.class,
136122
EmbeddedResourceLoader.ResourceLocation.CLASSPATH_ROOT);
137123
} catch (FileNotFoundException e) {
138124
throw new RuntimeException("Cannot find account-history.yaml file in the classpath",e);
@@ -161,7 +147,7 @@ public PaymentAgent(OpenAIAsyncClient client, LoggedUserService loggedUserServic
161147
)
162148
return event;
163149

164-
LOGGER.info("Adding {} result to the cache:{}", event.getFunction().getName(),event.getResult().getResult());
150+
LOGGER.debug("Adding {} result to the cache:{}", event.getFunction().getName(),event.getResult().getResult());
165151
var toolsExecutionKey = new ToolExecutionCacheKey(loggedUserService.getLoggedUser().username(),null,event.getFunction().getName(), ToolExecutionCacheUtils.convert(event.getArguments()));
166152
this.toolsExecutionCache.put(toolsExecutionKey , event.getResult().getResult());
167153
return event;
@@ -215,6 +201,7 @@ public void run (ChatHistory userChatHistory, AgentContext agentContext){
215201
//get last message
216202
var message = messages.get(messages.size()-1);
217203

204+
LOGGER.info("======== Payment Agent Response: {}",message.getContent());
218205
agentContext.setResult(message.getContent());
219206

220207
}

0 commit comments

Comments
 (0)