Skip to content

Commit 9fea02f

Browse files
Introduce initial ACP integration (#1253)
ACP feature to create ACP-compatible agents in Koog - [x] Raw access to the protocol from the feature in order not to complicate it until ACP becomes stable - [x] Example - [x] README (Model.md) - [x] Documentation Co-authored-by: Andrey Bragin <[email protected]>
1 parent c8cdc17 commit 9fea02f

File tree

24 files changed

+1783
-22
lines changed

24 files changed

+1783
-22
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Key features of Koog include:
3636
- **LLM switching and seamless history adaptation**: Switch to a different LLM at any point without losing the existing conversation history, or reroute between multiple LLM providers.
3737
- **Integration with JVM and Kotlin applications**: Build AI agents with an idiomatic, type-safe Kotlin DSL designed specifically for JVM and Kotlin developers.
3838
- **Model Context Protocol integration**: Use Model Context Protocol (MCP) tools in AI agents.
39+
- **Agent Client Protocol integration**: Build ACP-compliant agents that can communicate with standardized client applications using the Agent Client Protocol (ACP).
3940
- **Knowledge retrieval and memory**: Retain and retrieve knowledge across conversations using vector embeddings, ranked document storage, and shared agent memory.
4041
- **Powerful Streaming API**: Process responses in real-time with streaming support and parallel tool calls.
4142
- **Modular feature system**: Customize agent capabilities through a composable architecture.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal class AIAgentStuckInTheNodeException(node: AIAgentNodeBase<*, *>, outpu
4444
* @constructor Creates an instance of this exception with the specified maximum number of iterations.
4545
* @param maxNumberOfIterations The maximum number of iterations allowed for the agent before the exception is triggered.
4646
*/
47-
internal class AIAgentMaxNumberOfIterationsReachedException(maxNumberOfIterations: Int) :
47+
public class AIAgentMaxNumberOfIterationsReachedException(maxNumberOfIterations: Int) :
4848
AIAgentException(
4949
"Agent couldn't finish in given number of steps ($maxNumberOfIterations). " +
5050
"Please, consider increasing `maxAgentIterations` value in agent's configuration"

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/environment/ContextualAgentEnvironment.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ internal class ContextualAgentEnvironment(
2828
runId = context.runId,
2929
toolCallId = toolCall.id,
3030
toolName = toolCall.tool,
31+
toolDescription = context.llm.toolRegistry.getToolOrNull(toolCall.tool)?.descriptor?.description,
3132
toolArgs = toolCall.contentJson
3233
)
3334

@@ -39,6 +40,7 @@ internal class ContextualAgentEnvironment(
3940
"run id: ${context.runId}, " +
4041
"tool call id: ${toolCall.id}, " +
4142
"tool: ${toolCall.tool}, " +
43+
"tool description: ${toolResult.toolDescription}, " +
4244
"args: ${toolCall.contentJson}) " +
4345
"with result: $toolResult"
4446
}
@@ -63,8 +65,8 @@ internal class ContextualAgentEnvironment(
6365
runId = context.runId,
6466
toolCallId = toolResult.id,
6567
toolName = toolResult.tool,
66-
toolArgs = toolResult.toolArgs,
6768
toolDescription = toolResult.toolDescription,
69+
toolArgs = toolResult.toolArgs,
6870
toolResult = toolResult.result
6971
)
7072
}
@@ -75,8 +77,8 @@ internal class ContextualAgentEnvironment(
7577
runId = context.runId,
7678
toolCallId = toolResult.id,
7779
toolName = toolResult.tool,
78-
toolArgs = toolResult.toolArgs,
7980
toolDescription = toolResult.toolDescription,
81+
toolArgs = toolResult.toolArgs,
8082
message = toolResult.content,
8183
error = toolResultKind.error
8284
)
@@ -88,8 +90,8 @@ internal class ContextualAgentEnvironment(
8890
runId = context.runId,
8991
toolCallId = toolResult.id,
9092
toolName = toolResult.tool,
91-
toolArgs = toolResult.toolArgs,
9293
toolDescription = toolResult.toolDescription,
94+
toolArgs = toolResult.toolArgs,
9395
message = toolResult.content,
9496
error = toolResultKind.error
9597
)

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/feature/handler/llm/LLMCallEventContext.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public data class LLMCallStartingContext(
3939
*
4040
* @property executionInfo The execution information containing parentId and current execution path;
4141
* @property runId The unique identifier for this LLM call session.
42+
* @property callId Identifier for the current LLM call.
4243
* @property prompt The prompt that was sent to the language model.
4344
* @property model The language model instance that was used.
4445
* @property tools The list of tool descriptors that were available for the LLM call.

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/feature/handler/tool/ToolCallEventContext.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public data class ToolCallStartingContext(
2626
val runId: String,
2727
val toolCallId: String?,
2828
val toolName: String,
29+
val toolDescription: String?,
2930
val toolArgs: JsonObject,
3031
) : ToolCallEventContext {
3132
override val eventType: AgentLifecycleEventType = AgentLifecycleEventType.ToolCallStarting
@@ -38,8 +39,8 @@ public data class ToolCallStartingContext(
3839
* @property runId The unique identifier for this tool call session;
3940
* @property toolCallId The unique identifier for this tool call;
4041
* @property toolName The name of the tool associated with the validation error;
41-
* @property toolArgs The arguments passed to the tool when the error occurred;
4242
* @property toolDescription A description of the tool being executed;
43+
* @property toolArgs The arguments passed to the tool when the error occurred;
4344
* @property message A message describing the validation error.
4445
* @property error The [AIAgentError] error describing the validation issue.
4546
*/
@@ -48,8 +49,8 @@ public data class ToolValidationFailedContext(
4849
val runId: String,
4950
val toolCallId: String?,
5051
val toolName: String,
51-
val toolArgs: JsonObject,
5252
val toolDescription: String?,
53+
val toolArgs: JsonObject,
5354
val message: String,
5455
val error: AIAgentError
5556
) : ToolCallEventContext {
@@ -63,8 +64,8 @@ public data class ToolValidationFailedContext(
6364
* @property runId The unique identifier for this tool call session;
6465
* @property toolCallId The unique identifier for this tool call;
6566
* @property toolName The name of the tool being executed when the failure occurred;
66-
* @property toolArgs The arguments that were passed to the tool during execution;
6767
* @property toolDescription A description of the tool being executed;
68+
* @property toolArgs The arguments that were passed to the tool during execution;
6869
* @property message A message describing the failure that occurred.
6970
* @property error The [AIAgentError] instance describing the tool call failure.
7071
*/
@@ -73,8 +74,8 @@ public data class ToolCallFailedContext(
7374
val runId: String,
7475
val toolCallId: String?,
7576
val toolName: String,
76-
val toolArgs: JsonObject,
7777
val toolDescription: String?,
78+
val toolArgs: JsonObject,
7879
val message: String,
7980
val error: AIAgentError?
8081
) : ToolCallEventContext {
@@ -88,17 +89,17 @@ public data class ToolCallFailedContext(
8889
* @property runId The unique identifier for this tool call session;
8990
* @property toolCallId The unique identifier for this tool call;
9091
* @property toolName The name of the tool being executed;
91-
* @property toolArgs The arguments required by the tool for execution;
9292
* @property toolDescription A description of the tool being executed;
93+
* @property toolArgs The arguments required by the tool for execution;
9394
* @property toolResult An optional result produced by the tool after execution can be null if not applicable.
9495
*/
9596
public data class ToolCallCompletedContext(
9697
override val executionInfo: AgentExecutionInfo,
9798
val runId: String,
9899
val toolCallId: String?,
99100
val toolName: String,
100-
val toolArgs: JsonObject,
101101
val toolDescription: String?,
102+
val toolArgs: JsonObject,
102103
val toolResult: JsonElement?
103104
) : ToolCallEventContext {
104105
override val eventType: AgentLifecycleEventType = AgentLifecycleEventType.ToolCallCompleted

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/feature/pipeline/AIAgentPipeline.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -451,16 +451,19 @@ public abstract class AIAgentPipeline(public val clock: Clock) {
451451
* @param runId The unique identifier for the current run.
452452
* @param toolCallId The unique identifier for the current tool call.
453453
* @param toolName The tool name that is being called
454+
* @param toolDescription The description of the tool that is being called.
454455
* @param toolArgs The arguments provided to the tool
455456
*/
456457
public suspend fun onToolCallStarting(
457458
executionInfo: AgentExecutionInfo,
458459
runId: String,
459460
toolCallId: String?,
460461
toolName: String,
462+
toolDescription: String?,
461463
toolArgs: JsonObject,
462464
) {
463-
val eventContext = ToolCallStartingContext(executionInfo, runId, toolCallId, toolName, toolArgs)
465+
val eventContext =
466+
ToolCallStartingContext(executionInfo, runId, toolCallId, toolName, toolDescription, toolArgs)
464467
toolCallEventHandlers.values.forEach { handler -> handler.toolCallHandler.handle(eventContext) }
465468
}
466469

@@ -471,8 +474,8 @@ public abstract class AIAgentPipeline(public val clock: Clock) {
471474
* @param runId The unique identifier for the current run;
472475
* @param toolCallId The unique identifier for the current tool call;
473476
* @param toolName The name of the tool for which validation failed;
474-
* @param toolArgs The arguments that failed validation;
475477
* @param toolDescription The description of the tool that was called;
478+
* @param toolArgs The arguments that failed validation;
476479
* @param message The validation error message;
477480
* @param error The [AIAgentError] validation error.
478481
*/
@@ -481,12 +484,12 @@ public abstract class AIAgentPipeline(public val clock: Clock) {
481484
runId: String,
482485
toolCallId: String?,
483486
toolName: String,
484-
toolArgs: JsonObject,
485487
toolDescription: String?,
488+
toolArgs: JsonObject,
486489
message: String,
487490
error: AIAgentError,
488491
) {
489-
val eventContext = ToolValidationFailedContext(executionInfo, runId, toolCallId, toolName, toolArgs, toolDescription, message, error)
492+
val eventContext = ToolValidationFailedContext(executionInfo, runId, toolCallId, toolName, toolDescription, toolArgs, message, error)
490493
toolCallEventHandlers.values.forEach { handler -> handler.toolValidationErrorHandler.handle(eventContext) }
491494
}
492495

@@ -497,8 +500,8 @@ public abstract class AIAgentPipeline(public val clock: Clock) {
497500
* @param runId The unique identifier for the current run;
498501
* @param toolCallId The unique identifier for the current tool call;
499502
* @param toolName The tool name that was called;
500-
* @param toolArgs The arguments provided to the tool;
501503
* @param toolDescription The description of the tool that was called;
504+
* @param toolArgs The arguments provided to the tool;
502505
* @param message A message describing the failure.
503506
* @param error The [AIAgentError] that caused the failure.
504507
*/
@@ -507,12 +510,12 @@ public abstract class AIAgentPipeline(public val clock: Clock) {
507510
runId: String,
508511
toolCallId: String?,
509512
toolName: String,
510-
toolArgs: JsonObject,
511513
toolDescription: String?,
514+
toolArgs: JsonObject,
512515
message: String,
513516
error: AIAgentError?
514517
) {
515-
val eventContext = ToolCallFailedContext(executionInfo, runId, toolCallId, toolName, toolArgs, toolDescription, message, error)
518+
val eventContext = ToolCallFailedContext(executionInfo, runId, toolCallId, toolName, toolDescription, toolArgs, message, error)
516519
toolCallEventHandlers.values.forEach { handler -> handler.toolCallFailureHandler.handle(eventContext) }
517520
}
518521

@@ -523,20 +526,20 @@ public abstract class AIAgentPipeline(public val clock: Clock) {
523526
* @param runId The unique identifier for the current run;
524527
* @param toolCallId The unique identifier for the current tool call;
525528
* @param toolName The tool name that was called;
526-
* @param toolArgs The arguments that were provided to the tool;
527529
* @param toolDescription The description of the tool that was called;
530+
* @param toolArgs The arguments that were provided to the tool;
528531
* @param toolResult The result produced by the tool, or null if no result was produced.
529532
*/
530533
public suspend fun onToolCallCompleted(
531534
executionInfo: AgentExecutionInfo,
532535
runId: String,
533536
toolCallId: String?,
534537
toolName: String,
535-
toolArgs: JsonObject,
536538
toolDescription: String?,
539+
toolArgs: JsonObject,
537540
toolResult: JsonElement?
538541
) {
539-
val eventContext = ToolCallCompletedContext(executionInfo, runId, toolCallId, toolName, toolArgs, toolDescription, toolResult)
542+
val eventContext = ToolCallCompletedContext(executionInfo, runId, toolCallId, toolName, toolDescription, toolArgs, toolResult)
540543
toolCallEventHandlers.values.forEach { handler -> handler.toolCallResultHandler.handle(eventContext) }
541544
}
542545

@@ -1375,13 +1378,15 @@ public abstract class AIAgentPipeline(public val clock: Clock) {
13751378
// Use default configuration
13761379
}
13771380
}
1381+
13781382
is AIAgentFunctionalPipeline -> {
13791383
this.install(Debugger) {
13801384
// Use default configuration
13811385
}
13821386
}
13831387
}
13841388
}
1389+
13851390
else -> {
13861391
error(
13871392
"Unsupported system feature key: ${featureKey.name}. " +

agents/agents-ext/src/commonMain/kotlin/ai/koog/agents/ext/agent/AIAgentSubgraphExt.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ internal inline fun <reified Output> identityTool(): Tool<Output, Output> = obje
140140
@OptIn(InternalAgentToolsApi::class, InternalAgentsApi::class)
141141
@AIAgentBuilderDslMarker
142142
public inline fun <reified Input, reified Output> AIAgentSubgraphBuilderBase<*, *>.subgraphWithTask(
143-
toolSelectionStrategy: ToolSelectionStrategy,
144143
name: String? = null,
144+
toolSelectionStrategy: ToolSelectionStrategy = ToolSelectionStrategy.ALL,
145145
llmModel: LLModel? = null,
146146
llmParams: LLMParams? = null,
147147
runMode: ToolCalls = ToolCalls.SEQUENTIAL,

0 commit comments

Comments
 (0)