Skip to content

Commit d7ea7a4

Browse files
committed
Fix AIAgentFunctionalContext delegations when doing copy()
1 parent 707bcba commit d7ea7a4

File tree

9 files changed

+90
-201
lines changed

9 files changed

+90
-201
lines changed

agents/agents-core/src/androidMain/kotlin/ai/koog/agents/core/agent/context/AIAgentFunctionalContext.kt

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ import ai.koog.prompt.structure.StructuredResponse
1717

1818
@Suppress("MissingKDocForPublicAPI")
1919
public actual class AIAgentFunctionalContext internal actual constructor(
20-
environment: AIAgentEnvironment,
21-
agentId: String,
22-
runId: String,
23-
agentInput: Any?,
24-
config: AIAgentConfig,
25-
llm: AIAgentLLMContext,
26-
stateManager: AIAgentStateManager,
27-
storage: AIAgentStorage,
28-
strategyName: String,
29-
pipeline: AIAgentFunctionalPipeline,
30-
executionInfo: AgentExecutionInfo,
31-
parentContext: AIAgentContext?,
3220
@PublishedApi internal actual val delegate: AIAgentFunctionalContextImpl
3321
) : AIAgentFunctionalContextAPI by delegate {
3422

@@ -46,17 +34,6 @@ public actual class AIAgentFunctionalContext internal actual constructor(
4634
executionInfo: AgentExecutionInfo,
4735
parentContext: AIAgentContext?
4836
) : this(
49-
environment = environment,
50-
agentId = agentId,
51-
runId = runId,
52-
agentInput = agentInput,
53-
config = config,
54-
llm = llm,
55-
stateManager = stateManager,
56-
storage = storage,
57-
strategyName = strategyName,
58-
pipeline = pipeline,
59-
executionInfo = executionInfo,
6037
delegate = AIAgentFunctionalContextImpl(
6138
environment = environment,
6239
agentId = agentId,
@@ -87,7 +64,7 @@ public actual class AIAgentFunctionalContext internal actual constructor(
8764
llmParams: LLMParams?,
8865
runMode: ToolCalls,
8966
assistantResponseRepeatMax: Int?,
90-
): Output = delegate.subtask(
67+
): Output = delegate.subtaskImpl(
9168
taskDescription,
9269
input,
9370
tools,
@@ -111,18 +88,20 @@ public actual class AIAgentFunctionalContext internal actual constructor(
11188
executionInfo: AgentExecutionInfo,
11289
parentRootContext: AIAgentContext?
11390
): AIAgentFunctionalContext = AIAgentFunctionalContext(
114-
environment = environment,
115-
agentId = agentId,
116-
runId = runId,
117-
agentInput = agentInput,
118-
config = config,
119-
llm = llm,
120-
stateManager = stateManager,
121-
storage = storage,
122-
strategyName = strategyName,
123-
pipeline = pipeline,
124-
executionInfo = executionInfo,
125-
parentContext = parentRootContext,
126-
delegate = delegate,
91+
delegate = AIAgentFunctionalContextImpl(
92+
environment = environment,
93+
agentId = agentId,
94+
pipeline = pipeline,
95+
runId = runId,
96+
agentInput = agentInput,
97+
config = config,
98+
llm = llm,
99+
stateManager = stateManager,
100+
storage = storage,
101+
strategyName = strategyName,
102+
parentContext = parentContext,
103+
executionInfo = executionInfo,
104+
storeMap = delegate.storeMap
105+
)
127106
)
128107
}

agents/agents-core/src/appleMain/kotlin/ai/koog/agents/core/agent/context/AIAgentFunctionalContext.kt

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ import ai.koog.prompt.structure.StructuredResponse
1717

1818
@Suppress("MissingKDocForPublicAPI")
1919
public actual class AIAgentFunctionalContext internal actual constructor(
20-
environment: AIAgentEnvironment,
21-
agentId: String,
22-
runId: String,
23-
agentInput: Any?,
24-
config: AIAgentConfig,
25-
llm: AIAgentLLMContext,
26-
stateManager: AIAgentStateManager,
27-
storage: AIAgentStorage,
28-
strategyName: String,
29-
pipeline: AIAgentFunctionalPipeline,
30-
executionInfo: AgentExecutionInfo,
31-
parentContext: AIAgentContext?,
3220
@PublishedApi internal actual val delegate: AIAgentFunctionalContextImpl
3321
) : AIAgentFunctionalContextAPI by delegate {
3422

@@ -46,17 +34,6 @@ public actual class AIAgentFunctionalContext internal actual constructor(
4634
executionInfo: AgentExecutionInfo,
4735
parentContext: AIAgentContext?
4836
) : this(
49-
environment = environment,
50-
agentId = agentId,
51-
runId = runId,
52-
agentInput = agentInput,
53-
config = config,
54-
llm = llm,
55-
stateManager = stateManager,
56-
storage = storage,
57-
strategyName = strategyName,
58-
pipeline = pipeline,
59-
executionInfo = executionInfo,
6037
delegate = AIAgentFunctionalContextImpl(
6138
environment = environment,
6239
agentId = agentId,
@@ -87,7 +64,7 @@ public actual class AIAgentFunctionalContext internal actual constructor(
8764
llmParams: LLMParams?,
8865
runMode: ToolCalls,
8966
assistantResponseRepeatMax: Int?,
90-
): Output = delegate.subtask(
67+
): Output = delegate.subtaskImpl(
9168
taskDescription,
9269
input,
9370
tools,
@@ -111,18 +88,20 @@ public actual class AIAgentFunctionalContext internal actual constructor(
11188
executionInfo: AgentExecutionInfo,
11289
parentRootContext: AIAgentContext?
11390
): AIAgentFunctionalContext = AIAgentFunctionalContext(
114-
environment = environment,
115-
agentId = agentId,
116-
runId = runId,
117-
agentInput = agentInput,
118-
config = config,
119-
llm = llm,
120-
stateManager = stateManager,
121-
storage = storage,
122-
strategyName = strategyName,
123-
pipeline = pipeline,
124-
executionInfo = executionInfo,
125-
parentContext = parentRootContext,
126-
delegate = delegate,
91+
delegate = AIAgentFunctionalContextImpl(
92+
environment = environment,
93+
agentId = agentId,
94+
pipeline = pipeline,
95+
runId = runId,
96+
agentInput = agentInput,
97+
config = config,
98+
llm = llm,
99+
stateManager = stateManager,
100+
storage = storage,
101+
strategyName = strategyName,
102+
parentContext = parentContext,
103+
executionInfo = executionInfo,
104+
storeMap = delegate.storeMap
105+
)
127106
)
128107
}

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/agent/AIAgentFunctionalStrategy.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ public fun <Input, Output> functionalStrategy(
4444
func: suspend AIAgentFunctionalContext.(input: Input) -> Output
4545
): AIAgentFunctionalStrategy<Input, Output> = object : AIAgentFunctionalStrategy<Input, Output> {
4646
override val name: String = name
47-
override suspend fun execute(context: AIAgentFunctionalContext, input: Input): Output = context.func(input)
47+
override suspend fun execute(context: AIAgentFunctionalContext, input: Input): Output {
48+
return context.func(input)
49+
}
4850
}

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/agent/context/AIAgentFunctionalContext.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,6 @@ import kotlin.reflect.KClass
5151
@OptIn(InternalAgentsApi::class)
5252
@Suppress("UNCHECKED_CAST", "MissingKDocForPublicAPI")
5353
public expect class AIAgentFunctionalContext internal constructor(
54-
environment: AIAgentEnvironment,
55-
agentId: String,
56-
runId: String,
57-
agentInput: Any?,
58-
config: AIAgentConfig,
59-
llm: AIAgentLLMContext,
60-
stateManager: AIAgentStateManager,
61-
storage: AIAgentStorage,
62-
strategyName: String,
63-
pipeline: AIAgentFunctionalPipeline,
64-
executionInfo: AgentExecutionInfo,
65-
parentContext: AIAgentContext? = null,
6654
delegate: AIAgentFunctionalContextImpl
6755
) : AIAgentFunctionalContextAPI {
6856
public constructor(

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/agent/context/AIAgentFunctionalContextImpl.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ internal class AIAgentFunctionalContextImpl(
5353
override val strategyName: String,
5454
override val pipeline: AIAgentFunctionalPipeline,
5555
override var executionInfo: AgentExecutionInfo,
56+
internal val storeMap: MutableMap<AIAgentStorageKey<*>, Any> = mutableMapOf(),
5657
override val parentContext: AIAgentContext? = null
5758
) : AIAgentFunctionalContextAPI {
5859

59-
private val storeMap: MutableMap<AIAgentStorageKey<*>, Any> = mutableMapOf()
60-
6160
override fun store(key: AIAgentStorageKey<*>, value: Any) {
6261
storeMap[key] = value
6362
}

agents/agents-core/src/jsMain/kotlin/ai/koog/agents/core/agent/context/AIAgentFunctionalContext.kt

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,9 @@ import ai.koog.prompt.structure.StructuredResponse
1717

1818
@Suppress("MissingKDocForPublicAPI")
1919
public actual class AIAgentFunctionalContext internal actual constructor(
20-
environment: AIAgentEnvironment,
21-
agentId: String,
22-
runId: String,
23-
agentInput: Any?,
24-
config: AIAgentConfig,
25-
llm: AIAgentLLMContext,
26-
stateManager: AIAgentStateManager,
27-
storage: AIAgentStorage,
28-
strategyName: String,
29-
pipeline: AIAgentFunctionalPipeline,
30-
executionInfo: AgentExecutionInfo,
31-
parentContext: AIAgentContext?,
3220
@PublishedApi internal actual val delegate: AIAgentFunctionalContextImpl
3321
) : AIAgentFunctionalContextAPI by delegate {
22+
3423
public actual constructor(
3524
environment: AIAgentEnvironment,
3625
agentId: String,
@@ -45,17 +34,6 @@ public actual class AIAgentFunctionalContext internal actual constructor(
4534
executionInfo: AgentExecutionInfo,
4635
parentContext: AIAgentContext?
4736
) : this(
48-
environment = environment,
49-
agentId = agentId,
50-
runId = runId,
51-
agentInput = agentInput,
52-
config = config,
53-
llm = llm,
54-
stateManager = stateManager,
55-
storage = storage,
56-
strategyName = strategyName,
57-
pipeline = pipeline,
58-
executionInfo = executionInfo,
5937
delegate = AIAgentFunctionalContextImpl(
6038
environment = environment,
6139
agentId = agentId,
@@ -86,7 +64,7 @@ public actual class AIAgentFunctionalContext internal actual constructor(
8664
llmParams: LLMParams?,
8765
runMode: ToolCalls,
8866
assistantResponseRepeatMax: Int?,
89-
): Output = delegate.subtask(
67+
): Output = delegate.subtaskImpl(
9068
taskDescription,
9169
input,
9270
tools,
@@ -110,18 +88,20 @@ public actual class AIAgentFunctionalContext internal actual constructor(
11088
executionInfo: AgentExecutionInfo,
11189
parentRootContext: AIAgentContext?
11290
): AIAgentFunctionalContext = AIAgentFunctionalContext(
113-
environment = environment,
114-
agentId = agentId,
115-
runId = runId,
116-
agentInput = agentInput,
117-
config = config,
118-
llm = llm,
119-
stateManager = stateManager,
120-
storage = storage,
121-
strategyName = strategyName,
122-
pipeline = pipeline,
123-
executionInfo = executionInfo,
124-
parentContext = parentRootContext,
125-
delegate = delegate,
91+
delegate = AIAgentFunctionalContextImpl(
92+
environment = environment,
93+
agentId = agentId,
94+
pipeline = pipeline,
95+
runId = runId,
96+
agentInput = agentInput,
97+
config = config,
98+
llm = llm,
99+
stateManager = stateManager,
100+
storage = storage,
101+
strategyName = strategyName,
102+
parentContext = parentContext,
103+
executionInfo = executionInfo,
104+
storeMap = delegate.storeMap
105+
)
126106
)
127107
}

agents/agents-core/src/jvmMain/kotlin/ai/koog/agents/core/agent/context/AIAgentFunctionalContext.kt

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,9 @@ import kotlin.reflect.KClass
3838

3939
@Suppress("MissingKDocForPublicAPI")
4040
public actual class AIAgentFunctionalContext internal actual constructor(
41-
environment: AIAgentEnvironment,
42-
agentId: String,
43-
runId: String,
44-
agentInput: Any?,
45-
config: AIAgentConfig,
46-
llm: AIAgentLLMContext,
47-
stateManager: AIAgentStateManager,
48-
storage: AIAgentStorage,
49-
strategyName: String,
50-
pipeline: AIAgentFunctionalPipeline,
51-
executionInfo: AgentExecutionInfo,
52-
parentContext: AIAgentContext?,
5341
@PublishedApi internal actual val delegate: AIAgentFunctionalContextImpl
5442
) : AIAgentFunctionalContextAPI by delegate {
43+
@JvmOverloads
5544
public actual constructor(
5645
environment: AIAgentEnvironment,
5746
agentId: String,
@@ -66,17 +55,6 @@ public actual class AIAgentFunctionalContext internal actual constructor(
6655
executionInfo: AgentExecutionInfo,
6756
parentContext: AIAgentContext?
6857
) : this(
69-
environment = environment,
70-
agentId = agentId,
71-
runId = runId,
72-
agentInput = agentInput,
73-
config = config,
74-
llm = llm,
75-
stateManager = stateManager,
76-
storage = storage,
77-
strategyName = strategyName,
78-
pipeline = pipeline,
79-
executionInfo = executionInfo,
8058
delegate = AIAgentFunctionalContextImpl(
8159
environment = environment,
8260
agentId = agentId,
@@ -93,12 +71,14 @@ public actual class AIAgentFunctionalContext internal actual constructor(
9371
)
9472
)
9573

74+
@JvmOverloads
9675
public actual suspend inline fun <reified T> requestLLMStructured(
9776
message: String,
9877
examples: List<T>,
9978
fixingParser: StructureFixingParser?
10079
): Result<StructuredResponse<T>> = delegate.requestLLMStructured(message, examples, fixingParser)
10180

81+
@JvmOverloads
10282
public actual suspend inline fun <Input, reified Output> subtask(
10383
taskDescription: String,
10484
input: Input,
@@ -132,19 +112,21 @@ public actual class AIAgentFunctionalContext internal actual constructor(
132112
executionInfo: AgentExecutionInfo,
133113
parentRootContext: AIAgentContext?
134114
): AIAgentFunctionalContext = AIAgentFunctionalContext(
135-
environment = environment,
136-
agentId = agentId,
137-
runId = runId,
138-
agentInput = agentInput,
139-
config = config,
140-
llm = llm,
141-
stateManager = stateManager,
142-
storage = storage,
143-
strategyName = strategyName,
144-
pipeline = pipeline,
145-
executionInfo = executionInfo,
146-
parentContext = parentRootContext,
147-
delegate = delegate,
115+
delegate = AIAgentFunctionalContextImpl(
116+
environment = environment,
117+
agentId = agentId,
118+
pipeline = pipeline,
119+
runId = runId,
120+
agentInput = agentInput,
121+
config = config,
122+
llm = llm,
123+
stateManager = stateManager,
124+
storage = storage,
125+
strategyName = strategyName,
126+
parentContext = parentContext,
127+
executionInfo = executionInfo,
128+
storeMap = delegate.storeMap
129+
)
148130
)
149131

150132
/**

0 commit comments

Comments
 (0)