Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2024-2026 Embabel Pty Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.embabel.example.common

import com.embabel.common.ai.model.Thinking

/**
* Reasoning effort for the examples' calls.
*
* Claude 4.7 and later models think adaptively, and Embabel maps a thinking token budget to their
* effort level: under 1024 is low, under 4096 is medium. On those models the budget is not a token cap.
* Older Claude models receive it as a literal thinking budget instead.
*
* Effort is set per call because the configured default model carries no effort of its own.
*/
object Effort {

@JvmField
val LOW: Thinking = Thinking.withTokenBudget(512)

@JvmField
val MEDIUM: Thinking = Thinking.withTokenBudget(1024)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.embabel.agent.domain.library.InternetResource;
import com.embabel.common.ai.model.LlmOptions;
import com.embabel.common.ai.prompt.PromptContributor;
import com.embabel.example.common.Effort;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.google.common.base.Supplier;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -75,12 +76,13 @@ record FactCheckerProperties(
List<String> trustedSources,
List<String> untrustedSources,
List<String> models,
List<String> extractionModels,
String deduplicationModel,
int maxConcurrency
) {

LlmOptions deduplicationLlm() {
return LlmOptions.withModel(deduplicationModel);
return LlmOptions.withModel(deduplicationModel).withThinking(Effort.LOW);
}

/**
Expand Down Expand Up @@ -172,7 +174,7 @@ private Stream<Supplier<FactCheck>> factCheckWithSingleLlm(
}

private Stream<Supplier<DistinctFactualAssertions>> factualAssertionExtractors(UserInput userInput, ActionContext actionContext) {
return properties.models().stream()
return properties.extractionModels().stream()
.map(model -> () -> extractFactualAssertionsWithModel(userInput, actionContext, model));
}

Expand All @@ -181,7 +183,7 @@ private Stream<Supplier<DistinctFactualAssertions>> factualAssertionExtractors(U
*/
private DistinctFactualAssertions extractFactualAssertionsWithModel(UserInput userInput, ActionContext context, String model) {
return context.ai()
.withLlm(model)
.withLlm(LlmOptions.withModel(model).withThinking(Effort.LOW))
.createObject(
"""
Extract distinct factual assertions from the following text.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.embabel.agent.api.tool.ToolCallContext;
import com.embabel.agent.spi.ToolGroupResolver;
import com.embabel.common.ai.model.LlmOptions;
import com.embabel.example.common.Effort;
import tools.jackson.databind.json.JsonMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -99,7 +100,7 @@ public Result call(String input, ToolCallContext context) {
return result;
}
};
ai.withLlm(LlmOptions.withModel(defaultLlm).withTimeout(Duration.ofMinutes(3)))
ai.withLlm(LlmOptions.withModel(defaultLlm).withThinking(Effort.LOW).withTimeout(Duration.ofMinutes(3)))
.withId("fetch_news_feed")
.withTool(directFetch)
.generateText("Call %s once with url=%s%s. Do not summarize or search."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.embabel.agent.domain.library.PersonImpl;
import com.embabel.agent.domain.library.RelevantNewsStories;
import com.embabel.common.ai.model.LlmOptions;
import com.embabel.example.common.Effort;
import org.springframework.beans.factory.annotation.Value;

import java.time.Duration;
Expand Down Expand Up @@ -112,7 +113,7 @@ public RelevantNewsStories findNewsStories(
.mapToObj(i -> i + ": " + stories.get(i).getTitle() + " — " + stories.get(i).getSummary())
.collect(Collectors.joining("\n"));
var selection = ai
.withLlm(LlmOptions.withModel(defaultLlm).withTimeout(Duration.ofMinutes(3)))
.withLlm(LlmOptions.withModel(defaultLlm).withThinking(Effort.LOW).withTimeout(Duration.ofMinutes(3)))
.withId("select_news_stories")
.createObject("""
Select between 1 and %d news stories relevant to %s's horoscope.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.embabel.agent.api.common.Ai;
import com.embabel.common.ai.model.LlmOptions;
import com.embabel.example.common.Effort;
import org.springframework.stereotype.Component;


Expand Down Expand Up @@ -47,7 +48,7 @@ public record Joke(String leadup, String punchline) {

public String tellJokeAbout(String topic) {
return ai
.withDefaultLlm()
.withLlm(LlmOptions.withDefaultLlm().withThinking(Effort.LOW))
.generateText("""
Tell me a short joke. Reply with the joke only.
%s
Expand All @@ -57,7 +58,7 @@ public String tellJokeAbout(String topic) {

public Joke createJokeObjectAbout(String topic1, String topic2, String voice) {
return ai
.withLlm(LlmOptions.withDefaultLlm().withTemperature(.8))
.withLlm(LlmOptions.withDefaultLlm().withThinking(Effort.LOW))
.createObject("""
Tell me a joke about the two topics below, in the voice below.
The joke should have a leadup and a punchline.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package com.embabel.example.injection.travel;

import com.embabel.agent.api.common.Ai;
import com.embabel.common.ai.model.LlmOptions;
import com.embabel.example.common.Effort;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -64,7 +66,7 @@ public TravelerActivityReport summarizeActivity(Long customerId) {
// We can rely on the record's generated toString in this
// case to expose the right data, as it will include all fields
var report = ai
.withDefaultLlm()
.withLlm(LlmOptions.withDefaultLlm().withThinking(Effort.LOW))
.withToolObject(activity)
.generateText("""
Your job is to help staff of Antechinus Travel understand their customers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.embabel.agent.api.common.workflow.loop.TextFeedback;
import com.embabel.agent.api.models.OpenAiModels;
import com.embabel.agent.core.Agent;
import com.embabel.common.ai.model.LlmOptions;
import com.embabel.example.common.Effort;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand Down Expand Up @@ -50,7 +52,7 @@ public Agent goatWriter() {
Goat.class);
})
.withEvaluator(context ->
context.ai().withDefaultLlm().createObject(
context.ai().withLlm(LlmOptions.withDefaultLlm().withThinking(Effort.LOW)).createObject(
"""
Evaluate the goat description for creativity and detail.
The goat must have a name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.embabel.agent.core.CoreToolGroups;
import com.embabel.agent.domain.io.UserInput;
import com.embabel.agent.mcpserver.security.SecureAgentTool;
import com.embabel.common.ai.model.LlmOptions;
import com.embabel.example.common.Effort;

import java.util.stream.Collectors;

Expand Down Expand Up @@ -66,7 +68,7 @@ public class MarketIntelligenceAgent {
@Action
public AnalysisSubject parseSubject(UserInput userInput, OperationContext context) {
return context.ai()
.withDefaultLlm()
.withLlm(LlmOptions.withDefaultLlm().withThinking(Effort.LOW))
.createObject(
"""
Extract the subject of market analysis from the following user input.
Expand All @@ -93,7 +95,7 @@ public AnalysisSubject parseSubject(UserInput userInput, OperationContext contex
@Action
public String gatherIntelligence(AnalysisSubject subject, OperationContext context) {
return context.ai()
.withDefaultLlm()
.withLlm(LlmOptions.withDefaultLlm().withThinking(Effort.LOW))
.withToolGroup(CoreToolGroups.WEB)
.createObject(
"""
Expand Down Expand Up @@ -147,7 +149,7 @@ public MarketIntelligenceReport synthesiseReport(
OperationContext context
) {
SwotEntryList swotList = context.ai()
.withDefaultLlm()
.withLlm(LlmOptions.withDefaultLlm().withThinking(Effort.LOW))
.createObject(
"""
Based on the following market intelligence, produce a SWOT analysis for %s.
Expand All @@ -161,7 +163,7 @@ Each entry must have a category (Strength, Weakness, Opportunity, or Threat)
);

CompetitorInsightList competitorList = context.ai()
.withDefaultLlm()
.withLlm(LlmOptions.withDefaultLlm().withThinking(Effort.LOW))
.createObject(
"""
Based on the following market intelligence, identify the top 4 competitors
Expand All @@ -175,7 +177,7 @@ Each entry must have a category (Strength, Weakness, Opportunity, or Threat)
);

KeyTrendList trendList = context.ai()
.withDefaultLlm()
.withLlm(LlmOptions.withDefaultLlm().withThinking(Effort.LOW))
.createObject(
"""
Based on the following market intelligence, extract the 5 most significant
Expand All @@ -189,7 +191,7 @@ Each entry must have a category (Strength, Weakness, Opportunity, or Threat)
);

String summary = context.ai()
.withDefaultLlm()
.withLlm(LlmOptions.withDefaultLlm().withThinking(Effort.LOW))
.createObject(
"""
Write a 4-sentence executive summary for a market intelligence report on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.embabel.agent.core.CoreToolGroups;
import com.embabel.agent.domain.io.UserInput;
import com.embabel.agent.mcpserver.security.SecureAgentTool;
import com.embabel.common.ai.model.LlmOptions;
import com.embabel.example.common.Effort;

import java.util.stream.Collectors;

Expand Down Expand Up @@ -61,7 +63,7 @@ public class NewsDigestAgent {
@Action
public NewsTopic extractTopic(UserInput userInput, OperationContext context) {
return context.ai()
.withDefaultLlm()
.withLlm(LlmOptions.withDefaultLlm().withThinking(Effort.LOW))
.createObject(
"""
Extract a research topic from the following user input.
Expand Down Expand Up @@ -106,7 +108,7 @@ public NewsDigest produceDigest(NewsTopic topic, OperationContext context) {
: "";

DigestItemList digestItemList = context.ai()
.withDefaultLlm()
.withLlm(LlmOptions.withDefaultLlm().withThinking(Effort.LOW))
.withToolGroup(CoreToolGroups.WEB)
.createObject(
"""
Expand All @@ -118,7 +120,7 @@ public NewsDigest produceDigest(NewsTopic topic, OperationContext context) {
);

String narrative = context.ai()
.withDefaultLlm()
.withLlm(LlmOptions.withDefaultLlm().withThinking(Effort.LOW))
.createObject(
"""
Write a 3-sentence editorial summary of these news items about %s.
Expand Down
11 changes: 7 additions & 4 deletions examples-java/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
embabel.agent.application.name=embabel-examples

embabel.models.default-llm=gpt-4.1-mini
embabel.models.llms.cheapest=gpt-6-luna
# Calls on the default model and the cheapest role ask for low effort in code (see Effort)
embabel.models.default-llm=claude-haiku-5-5
embabel.models.llms.cheapest=claude-haiku-5-5

embabel.models.llms.best=gpt-6-astra

Expand All @@ -20,10 +21,12 @@ embabel.agent-platform.ranking.llm=gpt-4.1-mini


embabel.fact-checker.models=gpt-4.1-mini,gpt-6-luna,gpt-6.1-sol
# Smaller models extract opinions as facts
embabel.fact-checker.extraction-models=claude-sonnet-5-5
embabel.fact-checker.max-concurrency=8

# Use a good LLM for this
embabel.fact-checker.deduplication-model=gpt-4.1
# Use a good LLM for this: smaller models merge an assertion with its negation
embabel.fact-checker.deduplication-model=claude-sonnet-5-5
embabel.fact-checker.reasoning-word-count=50
embabel.fact-checker.trusted-sources=Wikipedia,Wikidata,Britannica,BBC,Reuters,NY Times,ABC Australia
embabel.fact-checker.untrusted-sources=reddit,4chan,twitter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
package com.embabel.example.injection;

import com.embabel.agent.test.unit.FakeOperationContext;
import com.embabel.example.common.Effort;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
Expand All @@ -40,6 +42,7 @@ void tellJokeAboutReturnsTheJoke() {

assertEquals(terribleJoke, joke);
assertTrue(promptOf(context).contains("Topic: frogs"));
assertSame(Effort.LOW, context.getLlmInvocations().getFirst().getInteraction().getLlm().getThinking());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
import com.embabel.agent.api.common.Ai;
import com.embabel.agent.api.common.PromptRunner;
import com.embabel.agent.test.unit.FakeOperationContext;
import com.embabel.common.ai.model.LlmOptions;
import com.embabel.example.common.Effort;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.time.Instant;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.when;

class ActivitySummarizerTest {
Expand Down Expand Up @@ -55,7 +59,7 @@ void testSummarizeActivityLlmThrowsException() {

var travellerActivity = createSampleTravellerActivity();
when(mockReportingService.report(1L)).thenReturn(travellerActivity);
when(mockAi.withDefaultLlm()).thenReturn(mockPromptRunner);
when(mockAi.withLlm(any(LlmOptions.class))).thenReturn(mockPromptRunner);
when(mockPromptRunner.withToolObject(travellerActivity)).thenReturn(mockPromptRunner);
when(mockPromptRunner.generateText(anyString())).thenThrow(new RuntimeException("LLM service unavailable"));

Expand All @@ -64,7 +68,7 @@ void testSummarizeActivityLlmThrowsException() {
assertThrows(RuntimeException.class, () -> activitySummarizer.summarizeActivity(1L));

Mockito.verify(mockReportingService).report(1L);
Mockito.verify(mockAi).withDefaultLlm();
Mockito.verify(mockAi).withLlm(argThat((LlmOptions llm) -> llm.getThinking() == Effort.LOW));
Mockito.verify(mockPromptRunner).withToolObject(travellerActivity);
}

Expand All @@ -79,7 +83,7 @@ void testSummarizeActivityValidReturn() {
var expectedSummary = "John Doe is a frequent traveler who has taken 2 trips to Paris and Tokyo, spending $3000 total. As a high spender, he enjoys premium destinations.";

when(mockReportingService.report(1L)).thenReturn(travellerActivity);
when(mockAi.withDefaultLlm()).thenReturn(mockPromptRunner);
when(mockAi.withLlm(any(LlmOptions.class))).thenReturn(mockPromptRunner);
when(mockPromptRunner.withToolObject(travellerActivity)).thenReturn(mockPromptRunner);
when(mockPromptRunner.generateText(anyString())).thenReturn(expectedSummary);

Expand All @@ -90,7 +94,7 @@ void testSummarizeActivityValidReturn() {
assertEquals(travellerActivity, result.activity());

Mockito.verify(mockReportingService).report(1L);
Mockito.verify(mockAi).withDefaultLlm();
Mockito.verify(mockAi).withLlm(argThat((LlmOptions llm) -> llm.getThinking() == Effort.LOW));
Mockito.verify(mockPromptRunner).withToolObject(travellerActivity);
Mockito.verify(mockPromptRunner).generateText(anyString());
}
Expand Down
Loading
Loading