@@ -6,10 +6,33 @@ import ai.koog.agents.core.agent.context.AIAgentLLMContext
6
6
import ai.koog.agents.core.agent.entity.AIAgentStateManager
7
7
import ai.koog.agents.core.agent.entity.AIAgentStorage
8
8
import ai.koog.agents.core.agent.entity.AIAgentStorageKey
9
+ import ai.koog.agents.core.annotation.InternalAgentsApi
9
10
import ai.koog.agents.core.environment.AIAgentEnvironment
10
11
import ai.koog.agents.core.feature.AIAgentFeature
12
+ import ai.koog.agents.core.feature.AIAgentNonGraphPipeline
11
13
import ai.koog.prompt.message.Message
12
14
15
+ /* *
16
+ * AIAgentLoopContext represents the execution context for an AI agent operating in a loop.
17
+ * It provides access to critical components such as the environment, configuration, large language model (LLM) context,
18
+ * state management, and storage. Additionally, it enables the agent to store, retrieve, and manage context-specific data
19
+ * during its execution lifecycle.
20
+ *
21
+ * @property environment The environment interface allowing the agent to interact with the external world,
22
+ * including executing tools and reporting problems.
23
+ * @property agentId A unique identifier for the agent, differentiating it from other agents in the system.
24
+ * @property runId A unique identifier for the current run or instance of the agent's operation.
25
+ * @property agentInput The input data passed to the agent, which can be of any type, depending on the agent's context.
26
+ * @property config The configuration settings for the agent, including its prompt and model details,
27
+ * as well as operational constraints like iteration limits.
28
+ * @property llm The context for interacting with the large language model used by the agent, enabling message history
29
+ * retrieval and processing.
30
+ * @property stateManager The state management component responsible for tracking and updating the agent's state during its execution.
31
+ * @property storage A storage interface providing persistent storage capabilities for the agent's data.
32
+ * @property strategyName The name of the agent's strategic approach or operational method, determining its behavior
33
+ * during execution.
34
+ */
35
+ @Suppress(" UNCHECKED_CAST" )
13
36
public class AIAgentLoopContext (
14
37
override val environment : AIAgentEnvironment ,
15
38
override val agentId : String ,
@@ -19,30 +42,32 @@ public class AIAgentLoopContext(
19
42
override val llm : AIAgentLLMContext ,
20
43
override val stateManager : AIAgentStateManager ,
21
44
override val storage : AIAgentStorage ,
22
- override val strategyName : String
45
+ override val strategyName : String ,
46
+ public val pipeline : AIAgentNonGraphPipeline
23
47
) : AIAgentContext {
48
+
49
+ private val storeMap: MutableMap <AIAgentStorageKey <* >, Any > = mutableMapOf ()
50
+
24
51
override fun store (key : AIAgentStorageKey <* >, value : Any ) {
25
- TODO ( " Not yet implemented " )
52
+ storeMap[key] = value
26
53
}
27
54
28
- override fun <T > get (key : AIAgentStorageKey <* >): T ? {
29
- TODO (" Not yet implemented" )
30
- }
55
+ override fun <T > get (key : AIAgentStorageKey <* >): T ? = storeMap[key] as T ?
31
56
32
- override fun remove (key : AIAgentStorageKey <* >): Boolean {
33
- TODO (" Not yet implemented" )
34
- }
57
+ override fun remove (key : AIAgentStorageKey <* >): Boolean = storeMap.remove(key) != null
58
+
59
+ @OptIn(InternalAgentsApi ::class )
60
+ private val features: Map <AIAgentStorageKey <* >, Any > =
61
+ pipeline.getAgentFeatures(this )
35
62
36
63
override fun <Feature : Any > feature (key : AIAgentStorageKey <Feature >): Feature ? {
37
- TODO (" Not yet implemented" )
64
+ @Suppress(" UNCHECKED_CAST" )
65
+ return features[key] as Feature ?
38
66
}
39
67
40
- override fun <Feature : Any > feature (feature : AIAgentFeature <* , Feature >): Feature ? {
41
- TODO (" Not yet implemented" )
42
- }
68
+ override fun <Feature : Any > feature (feature : AIAgentFeature <* , Feature >): Feature ? = feature(feature.key)
43
69
44
70
override suspend fun getHistory (): List <Message > {
45
- TODO ( " Not yet implemented " )
71
+ return llm.readSession { prompt.messages }
46
72
}
47
-
48
- }
73
+ }
0 commit comments