answer/pkg/agent/counter.go
Steve Dudenhoeffer 090b28d956 Update LLM integration and add new agent tools and utilities
Refactored LLM handling to use updated langchaingo models and tools, replacing gollm dependencies. Introduced agent-related utilities, tools, and counters for better modular functionality. Added a parser for LLM model configuration and revamped the answering mechanism with enhanced support for tool-based interaction.
2025-02-25 22:56:32 -05:00

26 lines
434 B
Go

package agent
import "sync/atomic"
type Counter struct {
atomic.Int32
}
// Take will attempt to take an item from the counter. If the counter is zero, it will return false.
func (c *Counter) Take() bool {
for {
current := c.Load()
if current <= 0 {
return false
}
if c.CompareAndSwap(current, current-1) {
return true
}
}
}
// Return will return an item to the counter.
func (c *Counter) Return() {
c.Add(1)
}