Skip to content

Commit 954283a

Browse files
ugur-vaadinvaadin-bot
authored andcommitted
refactor: update session context tool description (#9595)
## Description There is an issue with relative date phrases like *"tomorrow"*, *"yesterday"*, *"two weeks from now"*, or *"next Friday"* in user prompts. The LLM either left date fields empty or wrote the phrase verbatim rather than resolving it into an ISO date. This PR updates the `SessionContextTool` description in `AIOrchestrator` to lead with explicit guidance for resolving relative phrases against the date/time included in the session context, into ISO date / date-time / time strings. The orchestrator stays controller-agnostic. What to do with the resolved value is left to whichever controller is wired in. Based on Form Filler DX test session findings. No related issue. ## Type of change - [ ] Bugfix - [ ] Feature - [x] Refactor ## Checklist - [x] I have read the contribution guide: https://vaadin.com/docs/latest/contributing/overview - [x] I have added a description following the guideline. - [ ] The issue is created in the corresponding repository and I have referenced it. - [x] I have added tests to ensure my change is effective and works as intended. - [x] New and existing tests are passing locally with my change. - [x] I have performed self-review and corrected misspellings.
1 parent c0389c2 commit 954283a

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

vaadin-ai-components-flow-parent/vaadin-ai-components-flow/src/main/java/com/vaadin/flow/component/ai/orchestrator/AIOrchestrator.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,13 @@ private static final class SessionContextTool
649649
SessionContextTool(String content) {
650650
this.content = content;
651651
this.description = """
652-
Read for current session context (e.g. date and time, user \
653-
locale). The content below is captured at the start of \
654-
this turn:
652+
Read for current session context. If a date/time is \
653+
included below, use it to resolve relative phrases in \
654+
the user's prompt — "today", "tomorrow", "yesterday", \
655+
"next Friday", "in two weeks", "end of next month", \
656+
etc. — into ISO date / date-time / time strings.
657+
658+
Captured at the start of this turn:
655659
656660
""" + content;
657661
}

vaadin-ai-components-flow-parent/vaadin-ai-components-flow/src/test/java/com/vaadin/flow/component/ai/orchestrator/AIOrchestratorTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,34 @@ void prompt_byDefault_includesSessionContextToolWithCurrentDateTime() {
25082508
+ contextTool.getDescription());
25092509
}
25102510

2511+
@Test
2512+
void sessionContextToolDescription_carriesRelativeDateGuidance() {
2513+
// Real LLMs often leave date fields empty on the first turn when the
2514+
// user writes "tomorrow" or "next Friday" because nothing in the
2515+
// tool surface tells them to anchor relative phrases against the
2516+
// date that the session-context tool carries. Pin the load-bearing
2517+
// phrases that close that gap; a regression here re-opens it.
2518+
stubAddMessage();
2519+
Mockito.when(
2520+
mockProvider.stream(Mockito.any(LLMProvider.LLMRequest.class)))
2521+
.thenReturn(Flux.just("Response"));
2522+
2523+
var orchestrator = AIOrchestrator.builder(mockProvider, null)
2524+
.withMessageList(mockMessageList).build();
2525+
orchestrator.prompt("Hello");
2526+
2527+
var captor = ArgumentCaptor.forClass(LLMProvider.LLMRequest.class);
2528+
Mockito.verify(mockProvider).stream(captor.capture());
2529+
var description = captor.getValue().explicitTools().getFirst()
2530+
.getDescription();
2531+
2532+
for (var anchor : List.of("relative", "tomorrow", "ISO", "phrase")) {
2533+
Assertions.assertTrue(description.contains(anchor),
2534+
"Description must mention '" + anchor + "', got: "
2535+
+ description);
2536+
}
2537+
}
2538+
25112539
@Test
25122540
void prompt_withCustomContextSupplier_replacesDefaultAndExposesContent() {
25132541
stubAddMessage();

0 commit comments

Comments
 (0)