Files
docker-agent/pkg/runtime/tool_loop.go
T
David Gageot ad68f57e89 feat: add random toolset for agent-chosen integer draws
Adds a random toolset so agents can draw integers within inclusive
int64 bounds, with input validation, catalog/toolset registrations,
docs and examples. Successful draws are exempt from the duplicate-call
loop detector so repeated legitimate draws aren't flagged. Includes
regression tests and WASM toolset coverage.

Signed-off-by: David Gageot <david.gageot@docker.com>
2026-10-08 08:46:40 +02:00

33 lines
757 B
Go

package runtime
import (
"sync"
"github.com/docker/docker-agent/pkg/tools"
)
// toolCallLoopSink observes dispatch results without retaining their payloads.
type toolCallLoopSink struct {
EventSink
results sync.Map
}
func (s *toolCallLoopSink) Emit(event Event) {
if response, ok := event.(*ToolCallResponseEvent); ok {
exempt := response.ToolDefinition.AllowRepeatedCalls && response.Result != nil && !response.Result.IsError
s.results.Store(response.ToolCallID, exempt)
}
s.EventSink.Emit(event)
}
func (s *toolCallLoopSink) exemptCalls(calls []tools.ToolCall) []string {
var ids []string
for _, call := range calls {
if exempt, ok := s.results.Load(call.ID); ok && exempt == true {
ids = append(ids, call.ID)
}
}
return ids
}