-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow interceptor to stop tool execution
- Loading branch information
Showing
3 changed files
with
36 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/core/src/commonMain/kotlin/community/flock/aigentic/core/agent/ToolInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import community.flock.aigentic.core.agent.Agent | ||
import community.flock.aigentic.core.agent.AgentExecutor | ||
import community.flock.aigentic.core.message.Message | ||
import community.flock.aigentic.core.message.ToolCall | ||
import community.flock.aigentic.core.message.ToolResultContent | ||
import community.flock.aigentic.core.tool.Tool | ||
|
||
data class ToolInterceptorResult(val cancelExecution: Boolean, val reason: String?) | ||
|
||
interface ToolInterceptor { | ||
suspend fun intercept(agent: Agent, tool: Tool, toolCall: ToolCall): ToolInterceptorResult | ||
} | ||
|
||
suspend fun AgentExecutor.runInterceptors( | ||
agent: Agent, | ||
tool: Tool, | ||
toolCall: ToolCall | ||
): Message.ToolResult? = toolInterceptors | ||
.map { it.intercept(agent, tool, toolCall) } | ||
.firstOrNull { it.cancelExecution }?.let { | ||
Message.ToolResult( | ||
toolCall.id, | ||
toolCall.name, | ||
ToolResultContent(it.reason ?: "Tool execution blocked by interceptor") | ||
) | ||
} |
2 changes: 1 addition & 1 deletion
2
src/core/src/commonMain/kotlin/community/flock/aigentic/core/dsl/AgentExecutorConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters