mirror of
https://github.com/docker/docker-agent.git
synced 2026-11-04 10:02:15 +00:00
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>
33 lines
757 B
Go
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
|
|
}
|