Skip to content

Commit ce8b814

Browse files
authored
Add @Retry annotation (#230)
1 parent f5aed67 commit ce8b814

File tree

9 files changed

+291
-314
lines changed

9 files changed

+291
-314
lines changed

integration-tests/src/jvmTest/kotlin/ai/koog/integration/tests/MultipleLLMPromptExecutorIntegrationTest.kt

Lines changed: 118 additions & 113 deletions
Large diffs are not rendered by default.

integration-tests/src/jvmTest/kotlin/ai/koog/integration/tests/MultipleSystemMessagesPromptIntegrationTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package ai.koog.integration.tests
22

3-
import ai.koog.integration.tests.utils.TestUtils.executeWithRetry
43
import ai.koog.integration.tests.utils.TestUtils.readTestAnthropicKeyFromEnv
54
import ai.koog.integration.tests.utils.TestUtils.readTestGoogleAIKeyFromEnv
65
import ai.koog.integration.tests.utils.TestUtils.readTestOpenAIKeyFromEnv
6+
import ai.koog.integration.tests.utils.annotations.Retry
77
import ai.koog.prompt.dsl.prompt
88
import ai.koog.prompt.executor.model.PromptExecutorExt.execute
99
import ai.koog.prompt.executor.clients.anthropic.AnthropicLLMClient
@@ -23,6 +23,7 @@ class MultipleSystemMessagesPromptIntegrationTest {
2323
private val anthropicApiKey = readTestAnthropicKeyFromEnv()
2424
private val googleApiKey = readTestGoogleAIKeyFromEnv()
2525

26+
@Retry(3)
2627
@Test
2728
fun integration_testMultipleSystemMessages() = runBlocking {
2829
val openAIClient = OpenAILLMClient(openAIApiKey)
@@ -46,9 +47,9 @@ class MultipleSystemMessagesPromptIntegrationTest {
4647
val modelAnthropic = AnthropicModels.Haiku_3_5
4748
val modelGemini = GoogleModels.Gemini2_0Flash
4849

49-
val responseOpenAI = executeWithRetry { executor.execute(prompt, modelOpenAI) }
50-
val responseAnthropic = executeWithRetry { executor.execute(prompt, modelAnthropic) }
51-
val responseGemini = executeWithRetry { executor.execute(prompt, modelGemini) }
50+
val responseOpenAI = executor.execute(prompt, modelOpenAI)
51+
val responseAnthropic = executor.execute(prompt, modelAnthropic)
52+
val responseGemini = executor.execute(prompt, modelGemini)
5253

5354
assertTrue(responseOpenAI.content.isNotEmpty(), "OpenAI response should not be empty")
5455
assertTrue(responseAnthropic.content.isNotEmpty(), "Anthropic response should not be empty")

integration-tests/src/jvmTest/kotlin/ai/koog/integration/tests/OllamaAgentIntegrationTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import ai.koog.agents.core.dsl.builder.strategy
1313
import ai.koog.agents.core.dsl.extension.*
1414
import ai.koog.agents.core.tools.ToolRegistry
1515
import ai.koog.agents.features.eventHandler.feature.EventHandler
16-
import ai.koog.integration.tests.utils.TestUtils.runWithRetry
16+
import ai.koog.integration.tests.utils.annotations.Retry
1717
import ai.koog.prompt.dsl.prompt
1818
import ai.koog.prompt.executor.model.PromptExecutor
1919
import ai.koog.prompt.llm.OllamaModels
@@ -174,13 +174,14 @@ class OllamaAgentIntegrationTest {
174174
}
175175
}
176176

177+
@Retry(3)
177178
@Test
178179
fun ollama_testAgentClearContext() = runTest(timeout = 600.seconds) {
179180
val strategy = createTestStrategy()
180181
val toolRegistry = createToolRegistry()
181182
val agent = createAgent(executor, strategy, toolRegistry)
182183

183-
val result = runWithRetry { agent.runAndGetResult("What is the capital of France?") }
184+
val result = agent.runAndGetResult("What is the capital of France?")
184185

185186
assertNotNull(result, "Result should not be empty")
186187
assertTrue(result.isNotEmpty(), "Result should not be empty")

integration-tests/src/jvmTest/kotlin/ai/koog/integration/tests/OllamaSimpleAgentIntegrationTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ai.koog.agents.core.tools.ToolRegistry
55
import ai.koog.agents.ext.tool.SayToUser
66
import ai.koog.agents.features.eventHandler.feature.EventHandler
77
import ai.koog.agents.features.eventHandler.feature.EventHandlerConfig
8-
import ai.koog.integration.tests.utils.TestUtils.runWithRetry
8+
import ai.koog.integration.tests.utils.annotations.Retry
99
import kotlinx.coroutines.test.runTest
1010
import org.junit.jupiter.api.extension.ExtendWith
1111
import kotlin.test.AfterTest
@@ -87,6 +87,7 @@ class OllamaSimpleAgentIntegrationTest {
8787
actualToolCalls.clear()
8888
}
8989

90+
@Retry(3)
9091
@Test
9192
fun ollama_simpleTest() = runTest(timeout = 600.seconds) {
9293
val toolRegistry = ToolRegistry.Companion {
@@ -119,9 +120,8 @@ class OllamaSimpleAgentIntegrationTest {
119120
installFeatures = { install(EventHandler.Feature, eventHandlerConfig) }
120121
)
121122

122-
runWithRetry {
123-
agent.run("Give me top 10 books of the all time.")
124-
}
123+
124+
agent.run("Give me top 10 books of the all time.")
125125

126126
assertTrue(actualToolCalls.isNotEmpty(), "No tools were called for model")
127127
assertTrue(

integration-tests/src/jvmTest/kotlin/ai/koog/integration/tests/SimpleAgentIntegrationTest.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import ai.koog.integration.tests.utils.TestUtils.CalculatorTool
99
import ai.koog.integration.tests.utils.TestUtils.readTestAnthropicKeyFromEnv
1010
import ai.koog.integration.tests.utils.TestUtils.readTestGoogleAIKeyFromEnv
1111
import ai.koog.integration.tests.utils.TestUtils.readTestOpenAIKeyFromEnv
12-
import ai.koog.integration.tests.utils.TestUtils.runWithRetry
12+
import ai.koog.integration.tests.utils.annotations.Retry
1313
import ai.koog.prompt.executor.clients.google.GoogleModels
1414
import ai.koog.prompt.executor.clients.openai.OpenAIModels
1515
import ai.koog.prompt.executor.llms.all.simpleAnthropicExecutor
@@ -116,6 +116,7 @@ class SimpleAgentIntegrationTest {
116116
results.clear()
117117
}
118118

119+
@Retry(3)
119120
@ParameterizedTest
120121
@MethodSource("openAIModels", "anthropicModels", "googleModels")
121122
fun integration_AIAgentShouldNotCallToolsByDefault(model: LLModel) = runBlocking {
@@ -134,14 +135,13 @@ class SimpleAgentIntegrationTest {
134135
installFeatures = { install(EventHandler.Feature, eventHandlerConfig) }
135136
)
136137

137-
runWithRetry {
138-
agent.run("Repeat what I say: hello, I'm good.")
139-
}
138+
agent.run("Repeat what I say: hello, I'm good.")
140139

141140
// by default, AIAgent has no tools underneath
142141
assertTrue(actualToolCalls.isEmpty(), "No tools should be called for model $model")
143142
}
144143

144+
@Retry(3)
145145
@ParameterizedTest
146146
@MethodSource("openAIModels", "anthropicModels", "googleModels")
147147
fun integration_AIAgentShouldCallCustomTool(model: LLModel) = runBlocking {
@@ -172,9 +172,8 @@ class SimpleAgentIntegrationTest {
172172
installFeatures = { install(EventHandler.Feature, eventHandlerConfig) }
173173
)
174174

175-
runWithRetry {
176-
agent.run("How much is 3 times 5?")
177-
}
175+
176+
agent.run("How much is 3 times 5?")
178177

179178
assertTrue(actualToolCalls.isNotEmpty(), "No tools were called for model $model")
180179
assertTrue(

0 commit comments

Comments
 (0)